@intellectual-frontiers/libraries 0.1.1 → 0.4.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/affected.d.ts +15 -2
- package/dist/affected.js +51 -20
- package/dist/dev.d.ts +81 -0
- package/dist/dev.js +347 -0
- package/dist/family.d.ts +58 -0
- package/dist/family.js +124 -0
- package/dist/generate-ontology.d.ts +2 -0
- package/dist/generate-ontology.js +33 -1
- package/dist/generate-workflows.js +2 -10
- package/dist/libraries.d.ts +8 -0
- package/dist/libraries.js +30 -4
- package/dist/link.d.ts +12 -0
- package/dist/link.js +98 -0
- package/dist/oscal-register.d.ts +2 -1
- package/dist/oscal-register.js +112 -88
- package/dist/pack-library.js +6 -1
- package/dist/plan.d.ts +28 -0
- package/dist/plan.js +135 -0
- package/dist/releasing.d.ts +176 -0
- package/dist/releasing.js +680 -0
- package/dist/versions.js +4 -7
- package/dist/workflows/definitions.d.ts +33 -30
- package/dist/workflows/definitions.js +200 -272
- package/dist/workflows/model.d.ts +15 -3
- package/dist/workflows/render.js +10 -2
- package/package.json +24 -4
- package/src/affected.ts +56 -17
- package/src/dev.ts +368 -0
- package/src/family.ts +143 -0
- package/src/generate-ontology.ts +34 -1
- package/src/generate-workflows.ts +3 -11
- package/src/libraries.ts +35 -3
- package/src/link.ts +97 -0
- package/src/oscal-register.ts +139 -117
- package/src/pack-library.ts +6 -1
- package/src/plan.ts +143 -0
- package/src/releasing.ts +735 -0
- package/src/versions.ts +3 -7
- package/src/workflows/definitions.ts +260 -387
- package/src/workflows/model.ts +11 -3
- package/src/workflows/render.ts +10 -2
package/dist/family.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The families of the libraries of commons and the names held for them (commons 0027-commons-libraries FR-023, FR-024; commons 0033-kanon FR-021, FR-024): what the `family` field of a manifest
|
|
3
|
+
* says, the reservations (names no library may take unless it is of the family they are held for), and the findings of the two sides of a family held together, the host's table and each member's
|
|
4
|
+
* manifest.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Pure: it takes the libraries as data and returns one sentence for each finding. A library names its host and its role (`host`, `dialect` or `plugin`); the host's `kanon` table says what its
|
|
8
|
+
* dialects and plugins are and how their packages are named (`@intellectual-frontiers/kanon`: `family`, `instances`, `plugins`), so the name of a member is checked against the host's rule and
|
|
9
|
+
* never against a rule written here. A reservation is data: an exact name or a prefix, and the host that may hold it. It reserves a name without a folder, so that no empty library is created to hold one.
|
|
10
|
+
*
|
|
11
|
+
* Spec: 0001-libraries FR-016
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import { absurd, err, ok } from "@intellectual-frontiers/core";
|
|
16
|
+
import { classify, parsePackageName } from "@intellectual-frontiers/kanon";
|
|
17
|
+
/** The roles a library has in a family: a closed union. */
|
|
18
|
+
export const ROLES = ["host", "dialect", "plugin"];
|
|
19
|
+
/** The scope of the packages of commons. */
|
|
20
|
+
const SCOPE = "@intellectual-frontiers/";
|
|
21
|
+
/** The reason the names of the retired fleet engine are held (intellectual-frontiers/.github#11). */
|
|
22
|
+
const ARCHON = "held for the fleet library and its dialects and plugins, which replace the retired fleet engine (intellectual-frontiers/.github#11)";
|
|
23
|
+
/** The names held, as data: the check reads them and no folder holds them. */
|
|
24
|
+
export const RESERVED = [
|
|
25
|
+
{ match: { kind: "exact", name: "archon" }, host: "archon", reason: ARCHON },
|
|
26
|
+
{ match: { kind: "prefix", prefix: "archon-" }, host: "archon", reason: ARCHON },
|
|
27
|
+
{ match: { kind: "exact", name: "signing" }, host: "signing", reason: "held for the signing library of the fleet libraries (intellectual-frontiers/.github#11)" },
|
|
28
|
+
{ match: { kind: "exact", name: "gitops" }, host: "gitops", reason: "held for the gitops library of the fleet libraries (intellectual-frontiers/.github#11)" },
|
|
29
|
+
{ match: { kind: "exact", name: "estate" }, host: "estate", reason: "held for the estate library of the fleet libraries (intellectual-frontiers/.github#11)" },
|
|
30
|
+
];
|
|
31
|
+
/** Whether a library name is one a match holds. */
|
|
32
|
+
export function matches(match, name) {
|
|
33
|
+
switch (match.kind) {
|
|
34
|
+
case "exact":
|
|
35
|
+
return name === match.name;
|
|
36
|
+
case "prefix":
|
|
37
|
+
return name.startsWith(match.prefix);
|
|
38
|
+
default:
|
|
39
|
+
return absurd(match);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The family field of a manifest, from what it says: the host's name and the role, or why it is not one. */
|
|
43
|
+
export function decodeFamily(input) {
|
|
44
|
+
return /^[a-z][a-z0-9-]*$/.test(input.host)
|
|
45
|
+
? ok({ host: input.host, role: input.role })
|
|
46
|
+
: err(`library.family.host ${JSON.stringify(input.host)} is not a library name`);
|
|
47
|
+
}
|
|
48
|
+
/** The findings of the names held: a library whose name a reservation holds and that is not of the family the name is held for. */
|
|
49
|
+
export function reservationFindings(libraries, reserved = RESERVED) {
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const l of libraries)
|
|
52
|
+
for (const r of reserved) {
|
|
53
|
+
if (!matches(r.match, l.name))
|
|
54
|
+
continue;
|
|
55
|
+
if (l.family?.host !== r.host)
|
|
56
|
+
out.push(`commons/${l.name}: the name is ${r.reason}, so the manifest declares family: { host: "${r.host}", role } (0033-kanon FR-024)`);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/** The findings of a family held together: each member's name against the host's rule, each declared member registered, and each registered member declared (0033-kanon FR-021). */
|
|
62
|
+
export function familyFindings(libraries) {
|
|
63
|
+
const out = [];
|
|
64
|
+
const by = new Map(libraries.map((l) => [l.name, l]));
|
|
65
|
+
for (const l of libraries) {
|
|
66
|
+
const f = l.family;
|
|
67
|
+
if (f === undefined) {
|
|
68
|
+
for (const h of libraries) {
|
|
69
|
+
const rule = h.kanon?.family;
|
|
70
|
+
const pkg = parsePackageName(`${SCOPE}${l.name}`);
|
|
71
|
+
if (rule !== undefined && h.kanon !== undefined && pkg.kind === "ok" && h.name !== l.name) {
|
|
72
|
+
const member = classify(rule, h.kanon.package, pkg.value);
|
|
73
|
+
if (member !== undefined && member.kind !== "host")
|
|
74
|
+
out.push(`commons/${l.name}: the name is a ${member.kind} of ${h.name} by its family rule, and the manifest declares no family (0033-kanon FR-021)`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
switch (f.role) {
|
|
80
|
+
case "host":
|
|
81
|
+
if (l.name !== f.host)
|
|
82
|
+
out.push(`commons/${l.name}: it declares itself the host of the family ${f.host}, and a host is named as its family (0033-kanon FR-021)`);
|
|
83
|
+
break;
|
|
84
|
+
case "dialect":
|
|
85
|
+
case "plugin": {
|
|
86
|
+
const host = by.get(f.host);
|
|
87
|
+
if (host === undefined || host.family?.role !== "host" || host.kanon === undefined) {
|
|
88
|
+
out.push(`commons/${l.name}: its family host ${f.host} is not a library that declares family role host and a kanon table (0033-kanon FR-021)`);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
const rule = host.kanon.family;
|
|
92
|
+
const pkg = parsePackageName(`${SCOPE}${l.name}`);
|
|
93
|
+
const member = rule === undefined || pkg.kind === "err" ? undefined : classify(rule, host.kanon.package, pkg.value);
|
|
94
|
+
if (member === undefined || member.kind !== f.role)
|
|
95
|
+
out.push(`commons/${l.name}: the family rule of ${f.host} does not read the name as a ${f.role} (0033-kanon FR-021)`);
|
|
96
|
+
const declared = f.role === "dialect"
|
|
97
|
+
? host.kanon.instances.some((i) => i.kind === "package" && i.package === `${SCOPE}${l.name}`)
|
|
98
|
+
: host.kanon.plugins.some((p) => p.package === `${SCOPE}${l.name}`);
|
|
99
|
+
if (!declared)
|
|
100
|
+
out.push(`commons/${l.name}: the kanon table of ${f.host} does not declare it as a ${f.role} (0033-kanon FR-020)`);
|
|
101
|
+
if (l.kanon === undefined || l.kanon.extends !== host.kanon.package)
|
|
102
|
+
out.push(`commons/${l.name}: a ${f.role} of ${f.host} declares a kanon table with extends: "${host.kanon.package}" (0033-kanon FR-020)`);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
return absurd(f.role);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const h of libraries) {
|
|
110
|
+
if (h.kanon === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
const members = [
|
|
113
|
+
...h.kanon.instances.flatMap((i) => (i.kind === "package" ? [{ role: "dialect", pkg: i.package }] : [])),
|
|
114
|
+
...h.kanon.plugins.map((p) => ({ role: "plugin", pkg: p.package })),
|
|
115
|
+
];
|
|
116
|
+
for (const m of members) {
|
|
117
|
+
const name = m.pkg.slice(SCOPE.length);
|
|
118
|
+
const l = by.get(name);
|
|
119
|
+
if (l === undefined || l.family?.host !== h.name || l.family.role !== m.role)
|
|
120
|
+
out.push(`commons/${h.name}: its kanon table declares ${m.pkg} as a ${m.role}, and no library of that name declares family: { host: "${h.name}", role: "${m.role}" } (0033-kanon FR-021)`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
@@ -13,6 +13,8 @@ export declare const IFCCM: OntologyPublication;
|
|
|
13
13
|
export declare const IFQS: OntologyPublication;
|
|
14
14
|
/** The ontology of Intellectual Frontiers Releases (commons 0026-works-versioning), as it is published. */
|
|
15
15
|
export declare const IFR: OntologyPublication;
|
|
16
|
+
/** The ontology of Kanon (commons 0033-kanon), as it is published. */
|
|
17
|
+
export declare const KANON: OntologyPublication;
|
|
16
18
|
/** The ontologies of commons that are published, each from its own typed modules: Mizan's, then the ones its specifications define. */
|
|
17
19
|
export declare const publications: readonly OntologyPublication[];
|
|
18
20
|
/** The exports of the ontology (0019-mizan-integrations FR-010): everything but its Turtle, by its path from commons' folder. */
|
|
@@ -19,6 +19,7 @@ import { Authority, bases, classes, Decision, files, integrationDirections, rung
|
|
|
19
19
|
import * as ifccmOntology from "@intellectual-frontiers/ontology/ifccm";
|
|
20
20
|
import * as ifrOntology from "@intellectual-frontiers/ontology/ifr";
|
|
21
21
|
import * as ifqsOntology from "@intellectual-frontiers/ontology/ifqs";
|
|
22
|
+
import * as kanonOntology from "@intellectual-frontiers/ontology/kanon";
|
|
22
23
|
import { formatRdfFinding, validate } from "@intellectual-frontiers/rdf";
|
|
23
24
|
import { stdio } from "@intellectual-frontiers/system";
|
|
24
25
|
import { exportDcat } from "@intellectual-frontiers/mizan/integrations/pure/export-dcat";
|
|
@@ -204,8 +205,39 @@ export const IFR = {
|
|
|
204
205
|
viewTitle: "Intellectual Frontiers Releases: the ontology",
|
|
205
206
|
license: CC0,
|
|
206
207
|
};
|
|
208
|
+
/** The ontology of Kanon (commons 0033-kanon), as it is published. */
|
|
209
|
+
export const KANON = {
|
|
210
|
+
name: "kanon",
|
|
211
|
+
ns: { prefix: "kanon", iri: kanonOntology.KANON.iri },
|
|
212
|
+
idNs: { prefix: "mzid", iri: MZID.iri },
|
|
213
|
+
curies: [
|
|
214
|
+
["kanon", kanonOntology.KANON.iri],
|
|
215
|
+
["mz", MZ.iri],
|
|
216
|
+
["xsd", "http://www.w3.org/2001/XMLSchema#"],
|
|
217
|
+
["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
|
|
218
|
+
["skos", "http://www.w3.org/2004/02/skos/core#"],
|
|
219
|
+
["dcterms", "http://purl.org/dc/terms/"],
|
|
220
|
+
["prov", "http://www.w3.org/ns/prov#"],
|
|
221
|
+
["sh", "http://www.w3.org/ns/shacl#"],
|
|
222
|
+
],
|
|
223
|
+
files: kanonOntology.files,
|
|
224
|
+
ontology: kanonOntology.kanonOntology,
|
|
225
|
+
classes: kanonOntology.classes,
|
|
226
|
+
properties: kanonOntology.properties,
|
|
227
|
+
terms: kanonOntology.terms,
|
|
228
|
+
schemas: [kanonOntology.Layer],
|
|
229
|
+
lists: listsOf("kanon", [["Layer", kanonOntology.layers]]),
|
|
230
|
+
source: "commons/ontology/src/kanon/*.ts",
|
|
231
|
+
run: RUN,
|
|
232
|
+
shapes: { prefix: "kanonsh", iri: "https://www.intellectualfrontiers.com/ontology/kanon-shapes#" },
|
|
233
|
+
schemasIri: "https://www.intellectualfrontiers.com/ontology/kanon-schemas",
|
|
234
|
+
sssomSetId: "https://www.intellectualfrontiers.com/ontology/kanon-mappings",
|
|
235
|
+
sssomCuries: { dcterms: "http://purl.org/dc/terms/", prov: "http://www.w3.org/ns/prov#", sh: "http://www.w3.org/ns/shacl#" },
|
|
236
|
+
viewTitle: "Kanon: the ontology",
|
|
237
|
+
license: CC0,
|
|
238
|
+
};
|
|
207
239
|
/** The ontologies of commons that are published, each from its own typed modules: Mizan's, then the ones its specifications define. */
|
|
208
|
-
export const publications = [MIZAN, IFCCM, IFQS, IFR];
|
|
240
|
+
export const publications = [MIZAN, IFCCM, IFQS, IFR, KANON];
|
|
209
241
|
/** Where the generated files are downloaded from: this repository's `commons/` folder on its default branch. */
|
|
210
242
|
const DOWNLOAD_BASE = "https://raw.githubusercontent.com/intellectual-frontiers/.github/main/commons/";
|
|
211
243
|
/** The exports of the ontology (0019-mizan-integrations FR-010): everything but its Turtle, by its path from commons' folder. */
|
|
@@ -22,7 +22,6 @@ import process from "node:process";
|
|
|
22
22
|
import { ACTIONS, workflows } from "./workflows/definitions.js";
|
|
23
23
|
import { validateAction, validateWorkflow } from "./workflows/model.js";
|
|
24
24
|
import { renderAction, renderWorkflow } from "./workflows/render.js";
|
|
25
|
-
import { inputsOf } from "./affected.js";
|
|
26
25
|
import { readLibraries } from "./libraries.js";
|
|
27
26
|
import { existsSync, readDirSync, readTextFileSync, writeTextFileSync, mkdirSync } from "@intellectual-frontiers/system/fs";
|
|
28
27
|
import { stdio } from "@intellectual-frontiers/system";
|
|
@@ -32,23 +31,16 @@ const FOLDER = ".github/workflows";
|
|
|
32
31
|
export function outputs(repo) {
|
|
33
32
|
const root = repo.replace(/[\\/]$/, "");
|
|
34
33
|
const problems = [];
|
|
35
|
-
const libraries = [];
|
|
36
34
|
for (const f of readLibraries(root)) {
|
|
37
35
|
if ("problem" in f)
|
|
38
36
|
problems.push(`commons/${f.dir}/library.ts: ${f.problem}`);
|
|
39
37
|
else {
|
|
40
38
|
if (f.library.distribution.includes("npm") && !existsSync(`${root}/commons/${f.library.name}/tools/pack.ts`))
|
|
41
|
-
problems.push(`commons/${f.library.name} is published to npm and has no tools/pack.ts, which
|
|
42
|
-
libraries.push({
|
|
43
|
-
name: f.library.name,
|
|
44
|
-
verify: f.library.verify,
|
|
45
|
-
paths: inputsOf(root, f.library.name).paths,
|
|
46
|
-
distribution: f.library.distribution,
|
|
47
|
-
});
|
|
39
|
+
problems.push(`commons/${f.library.name} is published to npm and has no tools/pack.ts, which the release workflow runs (0030-generated-workflows FR-009)`);
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
42
|
const files = new Map();
|
|
51
|
-
for (const w of workflows(
|
|
43
|
+
for (const w of workflows()) {
|
|
52
44
|
problems.push(...validateWorkflow(w));
|
|
53
45
|
files.set(`${FOLDER}/${w.file}.auto.yml`, renderWorkflow(w));
|
|
54
46
|
}
|
package/dist/libraries.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type Result } from "@intellectual-frontiers/core";
|
|
2
|
+
import { type Table } from "@intellectual-frontiers/kanon";
|
|
2
3
|
import { type LevelKey } from "@intellectual-frontiers/mizan/levels";
|
|
4
|
+
import { type LibraryFamily } from "./family.js";
|
|
3
5
|
/** The name of a library's manifest in its folder. */
|
|
4
6
|
export declare const LIBRARY_FILE = "library.ts";
|
|
5
7
|
/** The specification that holds the requirements of the libraries, and the first number of the requirements it generates. */
|
|
@@ -27,7 +29,13 @@ export type Library = {
|
|
|
27
29
|
readonly summary?: string;
|
|
28
30
|
/** Where it is published: always `github` (the GitHub package registry of the organization), and `npm` as well where a decision about that package has made it so (FR-015 and FR-016). */
|
|
29
31
|
readonly distribution: readonly Registry[];
|
|
32
|
+
/** The table of its layers where it is built to Kanon (commons 0033-kanon FR-010); none where it is not. */
|
|
33
|
+
readonly kanon?: Table;
|
|
34
|
+
/** Its host and its role where it is of a family (a host, a dialect of it or a plugin of it; 0033-kanon FR-021, 0027-commons-libraries FR-023). */
|
|
35
|
+
readonly family?: LibraryFamily;
|
|
30
36
|
};
|
|
37
|
+
/** The lowest conformance level that requires a library to declare `kanon`; none yet (0033-kanon FR-014, OQ-1): a level asks for it by naming itself here. */
|
|
38
|
+
export declare const KANON_REQUIRED_FROM: LevelKey | undefined;
|
|
31
39
|
/** The registries a library may be published to: the kinds only, never a host or a credential (0027-commons-libraries FR-018). */
|
|
32
40
|
export declare const REGISTRIES: readonly ["github", "npm"];
|
|
33
41
|
export type Registry = (typeof REGISTRIES)[number];
|
package/dist/libraries.js
CHANGED
|
@@ -61,7 +61,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
61
61
|
*
|
|
62
62
|
* @remarks
|
|
63
63
|
* A manifest declares the library's `name` (its folder), its conformance `level` (`L1` where it declares none, 0028-conformance-levels), the path of its spec kit, its `verify` command, its
|
|
64
|
-
* `version`, its `exports` (the keys of the package's `exports`) and its `distribution` (the registries it is published to: `github`, the default, and `npm` as well where a decision about that package has made it so; FR-015 to FR-018). The section "The libraries" of the specification is between the markers `<!-- libraries:begin -->` and `<!-- libraries:end -->`,
|
|
64
|
+
* `version`, its `exports` (the keys of the package's `exports`) its `family` (a host and a role in a family of libraries, FR-023) and its `distribution` (the registries it is published to: `github`, the default, and `npm` as well where a decision about that package has made it so; FR-015 to FR-018). The section "The libraries" of the specification is between the markers `<!-- libraries:begin -->` and `<!-- libraries:end -->`,
|
|
65
65
|
* one requirement for each library numbered from FR-101, an id kept for the life of the library; the rows of those requirements are in `enforcement.tsv`. Adding a library is adding a folder with a manifest and
|
|
66
66
|
* running this command.
|
|
67
67
|
*
|
|
@@ -80,12 +80,14 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
80
80
|
* @module
|
|
81
81
|
*/
|
|
82
82
|
import process from "node:process";
|
|
83
|
-
import { array, describe, formatDecodeError, literal, object, string, err, ok, } from "@intellectual-frontiers/core";
|
|
83
|
+
import { array, describe, formatDecodeError, literal, object, unknownValue, string, err, ok, } from "@intellectual-frontiers/core";
|
|
84
84
|
import { exportedLiteral } from "@intellectual-frontiers/formats/ts-literal";
|
|
85
|
+
import { decodeTable } from "@intellectual-frontiers/kanon";
|
|
85
86
|
import { existsSync, readDirSync, readTextFileSync, writeTextFileSync } from "@intellectual-frontiers/system/fs";
|
|
86
87
|
import { stdio } from "@intellectual-frontiers/system";
|
|
87
88
|
import { spawn } from "@intellectual-frontiers/system/proc";
|
|
88
89
|
import { DEFAULT_LIBRARY_LEVEL, LEVELS, rankOf } from "@intellectual-frontiers/mizan/levels";
|
|
90
|
+
import { decodeFamily, familyFindings, reservationFindings, ROLES } from "./family.js";
|
|
89
91
|
/** The name of a library's manifest in its folder. */
|
|
90
92
|
export const LIBRARY_FILE = "library.ts";
|
|
91
93
|
/** The specification that holds the requirements of the libraries, and the first number of the requirements it generates. */
|
|
@@ -101,6 +103,8 @@ function bounds(spec) {
|
|
|
101
103
|
const to = spec.indexOf(`\n${END}\n`, from);
|
|
102
104
|
return from < 0 || to < 0 ? undefined : { from: from + 1, to: to + 1 };
|
|
103
105
|
}
|
|
106
|
+
/** The lowest conformance level that requires a library to declare `kanon`; none yet (0033-kanon FR-014, OQ-1): a level asks for it by naming itself here. */
|
|
107
|
+
export const KANON_REQUIRED_FROM = undefined;
|
|
104
108
|
/** The registries a library may be published to: the kinds only, never a host or a credential (0027-commons-libraries FR-018). */
|
|
105
109
|
export const REGISTRIES = ["github", "npm"];
|
|
106
110
|
/** Where a manifest that declares no distribution is published. */
|
|
@@ -119,8 +123,8 @@ const nameDecoder = (input, path = "$") => {
|
|
|
119
123
|
? r
|
|
120
124
|
: err({ kind: "decode", path, expected: "a name of lower-case letters, digits and hyphens", found: describe(input) });
|
|
121
125
|
};
|
|
122
|
-
const body = object({ name: nameDecoder, verify: nonEmpty, version: nonEmpty, exports: array(nonEmpty) }, { level: literal(...LEVELS), specKit: nonEmpty, summary: nonEmpty, distribution: array(literal(...REGISTRIES)) });
|
|
123
|
-
const FIELDS = ["name", "level", "specKit", "verify", "version", "exports", "summary", "distribution"];
|
|
126
|
+
const body = object({ name: nameDecoder, verify: nonEmpty, version: nonEmpty, exports: array(nonEmpty) }, { level: literal(...LEVELS), specKit: nonEmpty, summary: nonEmpty, distribution: array(literal(...REGISTRIES)), kanon: unknownValue, family: object({ host: nonEmpty, role: literal(...ROLES) }) });
|
|
127
|
+
const FIELDS = ["name", "level", "specKit", "verify", "version", "exports", "summary", "distribution", "kanon", "family"];
|
|
124
128
|
/** The manifest read from the text of its file: `export const library = { ... }` and no other export, read as data and never run (0027-commons-libraries FR-012). */
|
|
125
129
|
export function decodeLibrarySource(source) {
|
|
126
130
|
const exports = source.split("\n").filter((l) => /^export\s/.test(l));
|
|
@@ -145,6 +149,20 @@ export function decodeLibrarySource(source) {
|
|
|
145
149
|
return err("library.distribution lists each registry once and at least one (FR-015)");
|
|
146
150
|
if (!distribution.includes("github"))
|
|
147
151
|
return err("library.distribution includes github: a library is published to the GitHub package registry whatever else it is published to (FR-015, FR-016)");
|
|
152
|
+
let kanon;
|
|
153
|
+
if (v.kanon !== undefined) {
|
|
154
|
+
const t = decodeTable(v.kanon);
|
|
155
|
+
if (t.kind === "err")
|
|
156
|
+
return err(`library.${t.error} (0033-kanon FR-010)`);
|
|
157
|
+
kanon = t.value;
|
|
158
|
+
}
|
|
159
|
+
let family;
|
|
160
|
+
if (v.family !== undefined) {
|
|
161
|
+
const f = decodeFamily(v.family);
|
|
162
|
+
if (f.kind === "err")
|
|
163
|
+
return f;
|
|
164
|
+
family = f.value;
|
|
165
|
+
}
|
|
148
166
|
return ok({
|
|
149
167
|
name: v.name,
|
|
150
168
|
level: v.level ?? DEFAULT_LIBRARY_LEVEL,
|
|
@@ -154,6 +172,8 @@ export function decodeLibrarySource(source) {
|
|
|
154
172
|
exports: v.exports,
|
|
155
173
|
...(v.summary === undefined ? {} : { summary: v.summary }),
|
|
156
174
|
distribution,
|
|
175
|
+
...(kanon === undefined ? {} : { kanon }),
|
|
176
|
+
...(family === undefined ? {} : { family }),
|
|
157
177
|
});
|
|
158
178
|
}
|
|
159
179
|
/** The manifests of `commons/*`, in the order of the folders' names: every folder that holds a `library.ts`. */
|
|
@@ -232,7 +252,13 @@ export function manifestFindings(repo) {
|
|
|
232
252
|
const verifyText = script === undefined ? "" : scriptText(`${dir}/package.json`, script);
|
|
233
253
|
if (rankOf(l.level) >= 1 && rankOf(l.level) < rankOf("L3") && !verifyText.includes(`--level ${l.level}`))
|
|
234
254
|
found.push(`commons/${f.dir}: the manifest declares ${l.level} and the verify script does not run the Mizan check with --level ${l.level} (0028-conformance-levels FR-013)`);
|
|
255
|
+
if (l.kanon !== undefined && !verifyText.includes("kanon/src/check.ts"))
|
|
256
|
+
found.push(`commons/${f.dir}: the manifest declares kanon and the verify script does not run the check of the table (bun ../kanon/src/check.ts) (0033-kanon FR-014)`);
|
|
257
|
+
if (KANON_REQUIRED_FROM !== undefined && rankOf(l.level) >= rankOf(KANON_REQUIRED_FROM) && l.kanon === undefined)
|
|
258
|
+
found.push(`commons/${f.dir}: the manifest declares ${l.level}, which requires kanon, and declares none (0033-kanon FR-014)`);
|
|
235
259
|
}
|
|
260
|
+
const known = have.flatMap((f) => ("library" in f ? [f.library] : []));
|
|
261
|
+
found.push(...reservationFindings(known), ...familyFindings(known));
|
|
236
262
|
return found;
|
|
237
263
|
}
|
|
238
264
|
/** A field of a value read from JSON, `undefined` where the value is not an object or has no such field. */
|
package/dist/link.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The packages of commons by name and the folder of each; `commons/ts` comes first, so that it is the one that bears `@intellectual-frontiers/commons`. */
|
|
2
|
+
export declare function linksOf(repo: string): ReadonlyMap<string, string>;
|
|
3
|
+
/** Links each package that is not linked yet, and gives how many it linked, or why it could not. */
|
|
4
|
+
export declare function linkAll(repo: string): {
|
|
5
|
+
readonly made: number;
|
|
6
|
+
} | {
|
|
7
|
+
readonly problem: string;
|
|
8
|
+
};
|
|
9
|
+
/** The repository above a folder: the nearest one that has `commons/libraries/library.ts`. */
|
|
10
|
+
export declare function rootAbove(from: string): string | undefined;
|
|
11
|
+
/** The command line: 0, or 1 where it could not link. */
|
|
12
|
+
export declare function main(argv: readonly string[]): number;
|
package/dist/link.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The links of the libraries (commons 0001-libraries FR-011): every package of commons linked under `commons/node_modules/@intellectual-frontiers`, so that a library imports another by its package name and reads the checkout's
|
|
3
|
+
* source. It is the first command of every script that imports a library of commons (`dev:check`, `release`, the plan of CI), and it imports none: a fresh checkout has no link yet, and the command that makes them cannot
|
|
4
|
+
* itself need one.
|
|
5
|
+
*
|
|
6
|
+
* bun commons/libraries/src/link.ts link what is not linked, from the repository above this folder (or --repo DIR)
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* A folder of `commons/` whose `package.json` is named `@intellectual-frontiers/<name>` is linked as that name, and `commons/ts` as `@intellectual-frontiers/commons` (`commons/docs` bears the same name and is not linked). A link
|
|
10
|
+
* that is there is left as it is. Only the built-ins of Node are used, so it runs on Bun and on Node 26 before anything is installed.
|
|
11
|
+
*
|
|
12
|
+
* @limits
|
|
13
|
+
* It links and nothing else: the packages the root and a library install are `bun install`'s.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { linksOf } from "./link.ts";
|
|
18
|
+
* linksOf(".").get("@intellectual-frontiers/commons"); // the path of commons/ts
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Spec: 0001-libraries FR-011
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, symlinkSync } from "node:fs";
|
|
26
|
+
import { dirname, join, resolve } from "node:path";
|
|
27
|
+
import process from "node:process";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
const SCOPE = "@intellectual-frontiers/";
|
|
30
|
+
const nameOf = (file) => {
|
|
31
|
+
try {
|
|
32
|
+
const x = JSON.parse(readFileSync(file, "utf8"));
|
|
33
|
+
return typeof x === "object" && x !== null && "name" in x && typeof x.name === "string" ? x.name : undefined;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** The packages of commons by name and the folder of each; `commons/ts` comes first, so that it is the one that bears `@intellectual-frontiers/commons`. */
|
|
40
|
+
export function linksOf(repo) {
|
|
41
|
+
const links = new Map();
|
|
42
|
+
const dirs = readdirSync(join(repo, "commons"), { withFileTypes: true })
|
|
43
|
+
.filter((e) => e.isDirectory() && e.name !== "node_modules")
|
|
44
|
+
.map((e) => e.name)
|
|
45
|
+
.sort((a, b) => (a === "ts" ? -1 : b === "ts" ? 1 : a < b ? -1 : 1));
|
|
46
|
+
for (const d of dirs) {
|
|
47
|
+
const name = nameOf(join(repo, "commons", d, "package.json"));
|
|
48
|
+
if (name !== undefined && name.startsWith(SCOPE) && !links.has(name))
|
|
49
|
+
links.set(name, join(repo, "commons", d));
|
|
50
|
+
}
|
|
51
|
+
return links;
|
|
52
|
+
}
|
|
53
|
+
/** Links each package that is not linked yet, and gives how many it linked, or why it could not. */
|
|
54
|
+
export function linkAll(repo) {
|
|
55
|
+
try {
|
|
56
|
+
const scope = join(repo, "commons", "node_modules", "@intellectual-frontiers");
|
|
57
|
+
let made = 0;
|
|
58
|
+
for (const [name, dir] of linksOf(repo)) {
|
|
59
|
+
const at = join(scope, name.slice(SCOPE.length));
|
|
60
|
+
if (existsSync(at))
|
|
61
|
+
continue;
|
|
62
|
+
if (made === 0)
|
|
63
|
+
mkdirSync(scope, { recursive: true });
|
|
64
|
+
symlinkSync(dir, at, "junction");
|
|
65
|
+
made += 1;
|
|
66
|
+
}
|
|
67
|
+
return { made };
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
return { problem: `the libraries could not be linked under commons/node_modules: ${e instanceof Error ? e.message : String(e)}` };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** The repository above a folder: the nearest one that has `commons/libraries/library.ts`. */
|
|
74
|
+
export function rootAbove(from) {
|
|
75
|
+
for (let d = resolve(from);; d = dirname(d)) {
|
|
76
|
+
if (existsSync(join(d, "commons", "libraries", "library.ts")))
|
|
77
|
+
return d;
|
|
78
|
+
if (dirname(d) === d)
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** The command line: 0, or 1 where it could not link. */
|
|
83
|
+
export function main(argv) {
|
|
84
|
+
const at = argv.indexOf("--repo");
|
|
85
|
+
const repo = at >= 0 ? resolve(argv[at + 1] ?? ".") : rootAbove(dirname(fileURLToPath(import.meta.url)));
|
|
86
|
+
if (repo === undefined) {
|
|
87
|
+
process.stderr.write("link: no repository with commons/libraries here; give --repo DIR\n");
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
const r = linkAll(repo);
|
|
91
|
+
if ("problem" in r) {
|
|
92
|
+
process.stderr.write(`link: ${r.problem}\n`);
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
if (import.meta.main)
|
|
98
|
+
process.exitCode = main(process.argv.slice(2));
|
package/dist/oscal-register.d.ts
CHANGED
|
@@ -48,7 +48,8 @@ export type RegisterDocuments = {
|
|
|
48
48
|
};
|
|
49
49
|
/**
|
|
50
50
|
* The register as OSCAL 1.2.3: the component definition and the assessment results, rendered (0003-mizan FR-021, FR-022). Where `register.enforcement` names a file, its text is the register
|
|
51
|
-
* and `input.enforcement` is not read (FR-043); the same bytes come for the same register wherever its file is.
|
|
51
|
+
* and `input.enforcement` is not read (FR-043); the same bytes come for the same register wherever its file is. Both are written here, from the rows, and not by a library of exchange formats:
|
|
52
|
+
* the register's own vocabulary (a mechanism, a proof, a waiver) is Mizan's.
|
|
52
53
|
*/
|
|
53
54
|
export declare function registerDocuments(input: RegisterInput, register?: RegisterOptions): Promise<RegisterDocuments>;
|
|
54
55
|
/** What the register may be told besides its folder (0003-mizan FR-043): where its `enforcement.tsv` is, where it is not `enforcement.tsv` of the folder. */
|