@intentius/chant 0.124.103 → 0.124.105
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/audit/secrets.d.ts +6 -0
- package/dist/audit/secrets.js +9 -2
- package/dist/capabilities/templates.d.ts +66 -3
- package/dist/capabilities/templates.js +220 -81
- package/dist/cli/commands/import-index.d.ts +15 -0
- package/dist/cli/commands/import-index.js +37 -3
- package/dist/cli/handlers/lifecycle.js +6 -0
- package/dist/cli/handlers/release-config.d.ts +15 -0
- package/dist/cli/handlers/release-config.js +58 -0
- package/dist/cli/handlers/release-doctor.js +8 -3
- package/dist/cli/handlers/release-init.js +7 -4
- package/dist/cli/handlers/release.js +36 -3
- package/dist/cli/handlers/search.d.ts +1 -1
- package/dist/cli/handlers/search.js +24 -2
- package/dist/cli/main.js +12 -2
- package/dist/cli/parse-args.js +9 -2
- package/dist/cli/registry.d.ts +2 -0
- package/dist/cli/release-commands/cut.js +3 -0
- package/dist/cli/release-commands/doctor.js +5 -2
- package/dist/cloud-lister/aws.d.ts +9 -0
- package/dist/cloud-lister/aws.js +20 -0
- package/dist/config-import.js +26 -4
- package/dist/config.d.ts +24 -0
- package/dist/config.js +6 -0
- package/dist/floor-table.data.js +8 -6
- package/dist/floor-table.js +3 -1
- package/dist/graph-refs.d.ts +22 -0
- package/dist/graph-refs.js +20 -11
- package/dist/lifecycle/cloud-index.d.ts +6 -0
- package/dist/lifecycle/cloud-index.js +32 -5
- package/dist/lifecycle/derive-edges.d.ts +1 -1
- package/dist/lifecycle/derive-edges.js +5 -3
- package/dist/lifecycle/identity-match.d.ts +18 -2
- package/dist/lifecycle/identity-match.js +10 -5
- package/dist/lifecycle/index-drift.d.ts +13 -0
- package/dist/lifecycle/index-drift.js +21 -3
- package/dist/lifecycle/index-import.d.ts +24 -2
- package/dist/lifecycle/index-import.js +61 -9
- package/dist/lifecycle/index-join.d.ts +1 -1
- package/dist/lifecycle/index-join.js +1 -1
- package/dist/lifecycle/publish-declaration.d.ts +6 -0
- package/dist/lifecycle/publish-declaration.js +18 -1
- package/dist/lifecycle/publish-forge.d.ts +2 -0
- package/dist/lifecycle/publish-forge.js +3 -1
- package/dist/lifecycle/publish-oci.d.ts +27 -0
- package/dist/lifecycle/publish-oci.js +63 -8
- package/dist/lifecycle/release-artifacts.js +3 -1
- package/dist/lifecycle/release-at.d.ts +5 -1
- package/dist/lifecycle/release-at.js +69 -4
- package/dist/lifecycle/release-changelog.d.ts +18 -5
- package/dist/lifecycle/release-changelog.js +22 -10
- package/dist/lifecycle/release-cut.d.ts +13 -1
- package/dist/lifecycle/release-cut.js +3 -0
- package/dist/lifecycle/release-doctor.d.ts +10 -0
- package/dist/lifecycle/release-doctor.js +84 -14
- package/dist/lifecycle/release-green.d.ts +5 -2
- package/dist/lifecycle/release-green.js +40 -8
- package/dist/lifecycle/release-images.d.ts +39 -3
- package/dist/lifecycle/release-images.js +84 -7
- package/dist/lifecycle/release-init-goreleaser-images.d.ts +21 -0
- package/dist/lifecycle/release-init-goreleaser-images.js +160 -0
- package/dist/lifecycle/release-init.d.ts +38 -7
- package/dist/lifecycle/release-init.js +298 -52
- package/dist/lifecycle/release-next.d.ts +1 -1
- package/dist/lifecycle/release-next.js +9 -4
- package/dist/local-chant.d.ts +3 -0
- package/dist/local-chant.js +28 -2
- package/dist/release-floors.d.ts +10 -6
- package/dist/release-floors.js +10 -6
- package/dist/ts-loader.d.ts +12 -3
- package/dist/ts-loader.js +27 -11
- package/dist/wave-runtime.mjs +292 -291
- package/dist/workspace/capabilities-contract.d.ts +15 -5
- package/dist/workspace/capabilities-contract.js +7 -4
- package/dist/workspace/capabilities.schema.json +45 -1
- package/dist/workspace/catalog-edges.d.ts +22 -0
- package/dist/workspace/catalog-edges.js +23 -0
- package/dist/workspace/release-changed.d.ts +2 -0
- package/dist/workspace/release-changed.js +7 -2
- package/dist/workspace/release-steps/doctor.js +2 -1
- package/dist/workspace/release-steps/goreleaser.d.ts +6 -3
- package/dist/workspace/release-steps/goreleaser.js +12 -6
- package/dist/workspace/release-toolchains.d.ts +6 -0
- package/dist/workspace/release-toolchains.js +8 -0
- package/dist/workspace/release-train-workflow.d.ts +18 -0
- package/dist/workspace/release-train-workflow.js +135 -7
- package/dist/workspace/release-train.js +1 -1
- package/dist/workspace/release-workflow.d.ts +26 -0
- package/dist/workspace/release-workflow.js +60 -12
- package/dist/workspace/train-artifacts.js +3 -4
- package/dist/workspace/train-cut.d.ts +22 -1
- package/dist/workspace/train-cut.js +80 -16
- package/package.json +2 -2
package/dist/audit/secrets.d.ts
CHANGED
|
@@ -99,6 +99,12 @@ export declare const ENTROPY_RULE_ID = "SEC010";
|
|
|
99
99
|
* line up with dictionary-shaped alphabetic chunks. Requires at least two
|
|
100
100
|
* separators so a single hyphen (common inside genuine tokens) doesn't
|
|
101
101
|
* trigger it.
|
|
102
|
+
*
|
|
103
|
+
* All-digit chunks (a version's numbers, the `64` of `x86_64`) count for
|
|
104
|
+
* neither side, so a release asset's name in a download URL
|
|
105
|
+
* (`0/goreleaser_Linux_x86_64`, the tail of `.../v2.19.0/goreleaser_Linux_x86_64.tar.gz`)
|
|
106
|
+
* reads as the identifier it is (#5268); at least two wordy chunks are still
|
|
107
|
+
* required.
|
|
102
108
|
*/
|
|
103
109
|
export declare function looksLikeIdentifierSlug(value: string): boolean;
|
|
104
110
|
/** Is this a dependency lockfile the secrets scan should skip? */
|
package/dist/audit/secrets.js
CHANGED
|
@@ -247,13 +247,20 @@ const HEX_ONLY_RE = /^[0-9a-f]+$/i;
|
|
|
247
247
|
* line up with dictionary-shaped alphabetic chunks. Requires at least two
|
|
248
248
|
* separators so a single hyphen (common inside genuine tokens) doesn't
|
|
249
249
|
* trigger it.
|
|
250
|
+
*
|
|
251
|
+
* All-digit chunks (a version's numbers, the `64` of `x86_64`) count for
|
|
252
|
+
* neither side, so a release asset's name in a download URL
|
|
253
|
+
* (`0/goreleaser_Linux_x86_64`, the tail of `.../v2.19.0/goreleaser_Linux_x86_64.tar.gz`)
|
|
254
|
+
* reads as the identifier it is (#5268); at least two wordy chunks are still
|
|
255
|
+
* required.
|
|
250
256
|
*/
|
|
251
257
|
export function looksLikeIdentifierSlug(value) {
|
|
252
258
|
const parts = value.split(/[-_/]/).filter(Boolean);
|
|
253
259
|
if (parts.length < 3)
|
|
254
260
|
return false;
|
|
255
|
-
const
|
|
256
|
-
|
|
261
|
+
const counted = parts.filter((p) => !/^[0-9]+$/.test(p));
|
|
262
|
+
const wordy = counted.filter((p) => /^[a-zA-Z]+$/.test(p) && p.length >= 3).length;
|
|
263
|
+
return wordy >= 2 && wordy / counted.length >= 0.5;
|
|
257
264
|
}
|
|
258
265
|
/** At least 3 of {lower, upper, digit, symbol} present — cuts plain-word / all-hex false positives. */
|
|
259
266
|
function hasClassDiversity(value) {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
/** The first chant whose capabilities document carries `templates` (#4531). */
|
|
2
2
|
export declare const CAPABILITY_TEMPLATES_FLOOR = "0.124.54";
|
|
3
|
+
/**
|
|
4
|
+
* The first chant whose capabilities document lists a project's own templates
|
|
5
|
+
* from `.chant/templates.json`, marks each entry's `origin`, may carry `kinds`,
|
|
6
|
+
* and lists refused project entries under `refused` (behold issue 1142).
|
|
7
|
+
*/
|
|
8
|
+
export declare const PROJECT_TEMPLATES_FLOOR = "0.124.105";
|
|
9
|
+
/** Where a project declares its own templates, relative to the workspace or project root. */
|
|
10
|
+
export declare const PROJECT_TEMPLATES_FILE = ".chant/templates.json";
|
|
11
|
+
/** chant's own templates file, as a refusal names it. */
|
|
12
|
+
export declare const CHANT_TEMPLATES_FILE = "@intentius/chant/capabilities/templates.json";
|
|
3
13
|
/** The version of templates.json's shape. */
|
|
4
14
|
export declare const TEMPLATES_DATA_VERSION = 1;
|
|
5
15
|
export type TemplateQueryKind = "path" | "cypher";
|
|
@@ -24,6 +34,8 @@ export interface TemplateEntry {
|
|
|
24
34
|
question: string;
|
|
25
35
|
/** The sources whose nodes it applies to (behold's source kinds); absent means every source. */
|
|
26
36
|
sources?: string[];
|
|
37
|
+
/** The node kinds it applies to, as the graph holds them (`aws_s3_bucket`, `AWS::S3::Bucket`); absent means every kind. */
|
|
38
|
+
kinds?: string[];
|
|
27
39
|
inputs: TemplateInput[];
|
|
28
40
|
reads: TemplateReads;
|
|
29
41
|
query: {
|
|
@@ -33,18 +45,69 @@ export interface TemplateEntry {
|
|
|
33
45
|
/** What it does not answer, said where it is offered. */
|
|
34
46
|
note?: string;
|
|
35
47
|
}
|
|
36
|
-
/**
|
|
48
|
+
/** Where a catalog entry came from: chant's own file, or the project's `.chant/templates.json`. */
|
|
49
|
+
export type TemplateOrigin = "chant" | "project";
|
|
50
|
+
/** An entry of the catalog the capabilities document lists. */
|
|
51
|
+
export interface CatalogTemplate extends TemplateEntry {
|
|
52
|
+
origin: TemplateOrigin;
|
|
53
|
+
}
|
|
54
|
+
/** A project entry left out of the catalog, and why. */
|
|
55
|
+
export interface RefusedTemplate {
|
|
56
|
+
/** The entry's id, when it has a usable one. */
|
|
57
|
+
id?: string;
|
|
58
|
+
/** The file it was read from, relative to the workspace or project root. */
|
|
59
|
+
file: string;
|
|
60
|
+
/** The field at fault, such as `templates[2].query.text`; absent when the file is not JSON. */
|
|
61
|
+
field?: string;
|
|
62
|
+
/** What is wrong, naming the file and the field. */
|
|
63
|
+
message: string;
|
|
64
|
+
}
|
|
65
|
+
/** What {@link templateCatalog} found: chant's templates, then the project's, and the project entries it refused. */
|
|
66
|
+
export interface TemplateCatalog {
|
|
67
|
+
templates: CatalogTemplate[];
|
|
68
|
+
refused: RefusedTemplate[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A templates file or entry that does not hold to the entry kind, naming the
|
|
72
|
+
* template. `field` is the path to the field at fault and `file` the file it
|
|
73
|
+
* was read from, when known.
|
|
74
|
+
*/
|
|
37
75
|
export declare class TemplateCatalogError extends Error {
|
|
76
|
+
readonly field?: string | undefined;
|
|
77
|
+
readonly file?: string | undefined;
|
|
78
|
+
constructor(message: string, field?: string | undefined, file?: string | undefined);
|
|
38
79
|
}
|
|
39
80
|
/**
|
|
40
81
|
* Read a templates file, checking each entry against the entry kind: a
|
|
41
82
|
* unique id, exactly one resource input first, a query of a known kind
|
|
42
83
|
* whose placeholders (path) or parameters (Cypher) are its inputs, and every
|
|
43
|
-
* input used.
|
|
84
|
+
* input used. The first entry that does not hold is thrown.
|
|
85
|
+
*/
|
|
86
|
+
export declare function parseTemplates(raw: unknown, file?: string): TemplateEntry[];
|
|
87
|
+
/**
|
|
88
|
+
* Check a templates file entry by entry: the entries that hold, and a
|
|
89
|
+
* {@link TemplateCatalogError} for each that does not. A file whose shape is
|
|
90
|
+
* wrong (not an object, another version, no list) is thrown whole. An id
|
|
91
|
+
* defined twice keeps its first entry.
|
|
44
92
|
*/
|
|
45
|
-
export declare function
|
|
93
|
+
export declare function checkTemplates(raw: unknown, file?: string): {
|
|
94
|
+
templates: TemplateEntry[];
|
|
95
|
+
refused: TemplateCatalogError[];
|
|
96
|
+
};
|
|
46
97
|
/** The templates chant ships, checked. */
|
|
47
98
|
export declare function investigationTemplates(): TemplateEntry[];
|
|
99
|
+
/** The directory a project's templates file is read in: the workspace root, or the project root when `dir` is in no workspace. */
|
|
100
|
+
export declare function templatesRoot(dir: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* The template catalog for the project at `dir` (behold#1142): chant's
|
|
103
|
+
* templates, then the project's own from {@link PROJECT_TEMPLATES_FILE} at
|
|
104
|
+
* {@link templatesRoot}, each marked with its origin. A workspace member's
|
|
105
|
+
* own file is not read. A project entry that does not hold to the entry kind,
|
|
106
|
+
* or whose id is one of chant's, is left out and listed under `refused`, and
|
|
107
|
+
* the others load. A file that cannot be read as a templates file is refused
|
|
108
|
+
* whole, as one entry. No file means chant's templates alone.
|
|
109
|
+
*/
|
|
110
|
+
export declare function templateCatalog(dir: string): TemplateCatalog;
|
|
48
111
|
export interface ExpandedTemplate {
|
|
49
112
|
template: string;
|
|
50
113
|
kind: TemplateQueryKind;
|
|
@@ -17,18 +17,48 @@
|
|
|
17
17
|
* behold and choudoufu read it as data. The initial set is the one behold#1027
|
|
18
18
|
* stubbed in behold's src/graph-db/templates.ts.
|
|
19
19
|
*
|
|
20
|
+
* A project adds its own templates in `.chant/templates.json`, in the same
|
|
21
|
+
* shape (behold#1142). {@link templateCatalog} reads it from the workspace
|
|
22
|
+
* root, or from the project root when there is no workspace, and lists its
|
|
23
|
+
* entries after chant's with `origin: "project"`. An entry that does not hold
|
|
24
|
+
* to the entry kind, or that reuses one of chant's ids, is refused alone and
|
|
25
|
+
* listed under `refused`, so one bad entry never takes the rest with it: a
|
|
26
|
+
* reader such as choudoufu refuses a whole list on one bad entry.
|
|
27
|
+
*
|
|
20
28
|
* Filling in: a path template's `{{<input>}}` is replaced by the input's
|
|
21
29
|
* value, the resource's id for `{{node}}`. A Cypher template takes its inputs
|
|
22
30
|
* as query parameters, never spliced into the text: the resource's key is
|
|
23
31
|
* `$key` and every other input is `$<name>`.
|
|
24
32
|
*/
|
|
33
|
+
import { readFileSync } from "node:fs";
|
|
34
|
+
import { join } from "node:path";
|
|
35
|
+
import { findProjectRoot, findWorkspaceRoot } from "../project-root.js";
|
|
25
36
|
import data from "./templates.json" with { type: "json" };
|
|
26
37
|
/** The first chant whose capabilities document carries `templates` (#4531). */
|
|
27
38
|
export const CAPABILITY_TEMPLATES_FLOOR = "0.124.54";
|
|
39
|
+
/**
|
|
40
|
+
* The first chant whose capabilities document lists a project's own templates
|
|
41
|
+
* from `.chant/templates.json`, marks each entry's `origin`, may carry `kinds`,
|
|
42
|
+
* and lists refused project entries under `refused` (behold issue 1142).
|
|
43
|
+
*/
|
|
44
|
+
export const PROJECT_TEMPLATES_FLOOR = "0.124.105";
|
|
45
|
+
/** Where a project declares its own templates, relative to the workspace or project root. */
|
|
46
|
+
export const PROJECT_TEMPLATES_FILE = ".chant/templates.json";
|
|
47
|
+
/** chant's own templates file, as a refusal names it. */
|
|
48
|
+
export const CHANT_TEMPLATES_FILE = "@intentius/chant/capabilities/templates.json";
|
|
28
49
|
/** The version of templates.json's shape. */
|
|
29
50
|
export const TEMPLATES_DATA_VERSION = 1;
|
|
30
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* A templates file or entry that does not hold to the entry kind, naming the
|
|
53
|
+
* template. `field` is the path to the field at fault and `file` the file it
|
|
54
|
+
* was read from, when known.
|
|
55
|
+
*/
|
|
31
56
|
export class TemplateCatalogError extends Error {
|
|
57
|
+
constructor(message, field, file) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.field = field;
|
|
60
|
+
this.file = file;
|
|
61
|
+
}
|
|
32
62
|
}
|
|
33
63
|
const ID = /^[a-z][a-z0-9-]*$/;
|
|
34
64
|
const INPUT_NAME = /^[a-z][A-Za-z0-9_]*$/;
|
|
@@ -42,94 +72,133 @@ const str = (v) => typeof v === "string" && v.trim() !== "";
|
|
|
42
72
|
* Read a templates file, checking each entry against the entry kind: a
|
|
43
73
|
* unique id, exactly one resource input first, a query of a known kind
|
|
44
74
|
* whose placeholders (path) or parameters (Cypher) are its inputs, and every
|
|
45
|
-
* input used.
|
|
75
|
+
* input used. The first entry that does not hold is thrown.
|
|
76
|
+
*/
|
|
77
|
+
export function parseTemplates(raw, file) {
|
|
78
|
+
const { templates, refused } = checkTemplates(raw, file);
|
|
79
|
+
if (refused.length > 0)
|
|
80
|
+
throw refused[0];
|
|
81
|
+
return templates;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check a templates file entry by entry: the entries that hold, and a
|
|
85
|
+
* {@link TemplateCatalogError} for each that does not. A file whose shape is
|
|
86
|
+
* wrong (not an object, another version, no list) is thrown whole. An id
|
|
87
|
+
* defined twice keeps its first entry.
|
|
46
88
|
*/
|
|
47
|
-
export function
|
|
89
|
+
export function checkTemplates(raw, file) {
|
|
48
90
|
const doc = raw;
|
|
49
|
-
|
|
50
|
-
throw new TemplateCatalogError(
|
|
91
|
+
const whole = (m, field) => {
|
|
92
|
+
throw new TemplateCatalogError(file ? `${file}${field ? ` ${field}` : ""}: ${m}` : m, field, file);
|
|
93
|
+
};
|
|
94
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc))
|
|
95
|
+
whole("a templates file is an object");
|
|
51
96
|
if (doc.version !== TEMPLATES_DATA_VERSION)
|
|
52
|
-
|
|
97
|
+
whole(`templates file version ${String(doc.version)} is not ${TEMPLATES_DATA_VERSION}`, "version");
|
|
53
98
|
if (!Array.isArray(doc.templates))
|
|
54
|
-
|
|
99
|
+
whole("templates is a list", "templates");
|
|
55
100
|
const seen = new Set();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
if (!e || typeof e !== "object")
|
|
63
|
-
fail("is not an object");
|
|
64
|
-
if (!str(e.id) || !ID.test(e.id))
|
|
65
|
-
fail("needs an id of lowercase letters, digits and -");
|
|
66
|
-
if (seen.has(e.id))
|
|
67
|
-
fail("is defined twice");
|
|
68
|
-
seen.add(e.id);
|
|
69
|
-
if (!str(e.title))
|
|
70
|
-
fail("needs a title");
|
|
71
|
-
if (!str(e.question))
|
|
72
|
-
fail("needs the question it answers");
|
|
73
|
-
if (!READS.includes(e.reads))
|
|
74
|
-
fail(`reads is one of ${READS.join(", ")}`);
|
|
75
|
-
if (e.sources !== undefined && (!Array.isArray(e.sources) || !e.sources.every(str)))
|
|
76
|
-
fail("sources is a list of source kinds");
|
|
77
|
-
if (e.note !== undefined && !str(e.note))
|
|
78
|
-
fail("a note is text");
|
|
79
|
-
if (!Array.isArray(e.inputs))
|
|
80
|
-
fail("needs its inputs");
|
|
81
|
-
const names = new Set();
|
|
82
|
-
for (const input of e.inputs) {
|
|
83
|
-
if (!input || !str(input.name) || !INPUT_NAME.test(input.name))
|
|
84
|
-
fail("an input needs a name");
|
|
85
|
-
if (names.has(input.name))
|
|
86
|
-
fail(`input ${input.name} is listed twice`);
|
|
87
|
-
names.add(input.name);
|
|
88
|
-
if (!INPUT_KINDS.includes(input.kind))
|
|
89
|
-
fail(`input ${input.name}'s kind is one of ${INPUT_KINDS.join(", ")}`);
|
|
90
|
-
if (!str(input.description))
|
|
91
|
-
fail(`input ${input.name} needs a description`);
|
|
101
|
+
const templates = [];
|
|
102
|
+
const refused = [];
|
|
103
|
+
doc.templates.forEach((t, i) => {
|
|
104
|
+
try {
|
|
105
|
+
templates.push(checkEntry(t, i, seen, file));
|
|
92
106
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!q || !KINDS.includes(q.kind) || !str(q.text))
|
|
98
|
-
fail(`query is { kind: ${KINDS.join(" | ")}, text }`);
|
|
99
|
-
const resource = resources[0].name;
|
|
100
|
-
if (q.kind === "path") {
|
|
101
|
-
if (/\$[A-Za-z_]/.test(q.text))
|
|
102
|
-
fail("a path pattern takes {{input}} placeholders, not $parameters");
|
|
103
|
-
const used = new Set([...q.text.matchAll(PLACEHOLDER)].map((m) => m[1]));
|
|
104
|
-
for (const u of used)
|
|
105
|
-
if (!names.has(u))
|
|
106
|
-
fail(`{{${u}}} names no input`);
|
|
107
|
-
// A scope is where the query is read, not part of its text.
|
|
108
|
-
for (const input of e.inputs)
|
|
109
|
-
if (input.kind !== "scope" && !used.has(input.name))
|
|
110
|
-
fail(`the path pattern never uses ${input.name}`);
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (!(e instanceof TemplateCatalogError))
|
|
109
|
+
throw e;
|
|
110
|
+
refused.push(e);
|
|
111
111
|
}
|
|
112
|
-
else {
|
|
113
|
-
if (/\{\{/.test(q.text))
|
|
114
|
-
fail("a Cypher query takes $parameters, never spliced {{input}} text");
|
|
115
|
-
if (!/^\s*(MATCH|OPTIONAL MATCH|WITH|CALL|UNWIND)\b/i.test(q.text))
|
|
116
|
-
fail("a Cypher query starts with a reading clause");
|
|
117
|
-
if (/\b(CREATE|MERGE|DELETE|DETACH|SET|REMOVE|DROP)\b/i.test(q.text))
|
|
118
|
-
fail("a Cypher query only reads");
|
|
119
|
-
if (!balanced(q.text))
|
|
120
|
-
fail("its brackets do not balance");
|
|
121
|
-
const params = new Set([...q.text.matchAll(PARAM)].map((m) => m[1]));
|
|
122
|
-
if (!params.has("key"))
|
|
123
|
-
fail("a Cypher query binds the resource as $key");
|
|
124
|
-
for (const p of params)
|
|
125
|
-
if (p !== "key" && !names.has(p))
|
|
126
|
-
fail(`$${p} names no input`);
|
|
127
|
-
for (const input of e.inputs)
|
|
128
|
-
if (input.name !== resource && input.kind !== "scope" && !params.has(input.name))
|
|
129
|
-
fail(`the query never uses $${input.name}`);
|
|
130
|
-
}
|
|
131
|
-
return e;
|
|
132
112
|
});
|
|
113
|
+
return { templates, refused };
|
|
114
|
+
}
|
|
115
|
+
/** One entry, checked; `seen` holds the ids before it. */
|
|
116
|
+
function checkEntry(t, i, seen, file) {
|
|
117
|
+
const e = t;
|
|
118
|
+
const at = `templates[${i}]`;
|
|
119
|
+
const where = str(e?.id) ? `template ${e.id}` : `template ${i}`;
|
|
120
|
+
const fail = (m, field = "") => {
|
|
121
|
+
const path = `${at}${field}`;
|
|
122
|
+
throw new TemplateCatalogError(file ? `${file} ${path}: ${where}: ${m}` : `${where}: ${m}`, path, file);
|
|
123
|
+
};
|
|
124
|
+
if (!e || typeof e !== "object" || Array.isArray(e))
|
|
125
|
+
fail("is not an object");
|
|
126
|
+
if (!str(e.id) || !ID.test(e.id))
|
|
127
|
+
fail("needs an id of lowercase letters, digits and -", ".id");
|
|
128
|
+
if (seen.has(e.id))
|
|
129
|
+
fail("is defined twice", ".id");
|
|
130
|
+
seen.add(e.id);
|
|
131
|
+
if (!str(e.title))
|
|
132
|
+
fail("needs a title", ".title");
|
|
133
|
+
if (!str(e.question))
|
|
134
|
+
fail("needs the question it answers", ".question");
|
|
135
|
+
if (!READS.includes(e.reads))
|
|
136
|
+
fail(`reads is one of ${READS.join(", ")}`, ".reads");
|
|
137
|
+
if (e.sources !== undefined && (!Array.isArray(e.sources) || !e.sources.every(str)))
|
|
138
|
+
fail("sources is a list of source kinds", ".sources");
|
|
139
|
+
if (e.kinds !== undefined && (!Array.isArray(e.kinds) || e.kinds.length === 0 || !e.kinds.every(str)))
|
|
140
|
+
fail("kinds is a list of node kinds, or absent for every kind", ".kinds");
|
|
141
|
+
if (e.note !== undefined && !str(e.note))
|
|
142
|
+
fail("a note is text", ".note");
|
|
143
|
+
if (!Array.isArray(e.inputs))
|
|
144
|
+
fail("needs its inputs", ".inputs");
|
|
145
|
+
const names = new Set();
|
|
146
|
+
e.inputs.forEach((input, j) => {
|
|
147
|
+
const f = `.inputs[${j}]`;
|
|
148
|
+
if (!input || !str(input.name) || !INPUT_NAME.test(input.name))
|
|
149
|
+
fail("an input needs a name", `${f}.name`);
|
|
150
|
+
if (names.has(input.name))
|
|
151
|
+
fail(`input ${input.name} is listed twice`, `${f}.name`);
|
|
152
|
+
names.add(input.name);
|
|
153
|
+
if (!INPUT_KINDS.includes(input.kind))
|
|
154
|
+
fail(`input ${input.name}'s kind is one of ${INPUT_KINDS.join(", ")}`, `${f}.kind`);
|
|
155
|
+
if (!str(input.description))
|
|
156
|
+
fail(`input ${input.name} needs a description`, `${f}.description`);
|
|
157
|
+
});
|
|
158
|
+
const resources = e.inputs.filter((x) => x.kind === "resource");
|
|
159
|
+
if (resources.length !== 1 || e.inputs[0] !== resources[0])
|
|
160
|
+
fail("takes one resource input, first", ".inputs");
|
|
161
|
+
const q = e.query;
|
|
162
|
+
if (!q || typeof q !== "object")
|
|
163
|
+
fail(`query is { kind: ${KINDS.join(" | ")}, text }`, ".query");
|
|
164
|
+
if (!KINDS.includes(q.kind))
|
|
165
|
+
fail(`query is { kind: ${KINDS.join(" | ")}, text }`, ".query.kind");
|
|
166
|
+
if (!str(q.text))
|
|
167
|
+
fail(`query is { kind: ${KINDS.join(" | ")}, text }`, ".query.text");
|
|
168
|
+
const text = ".query.text";
|
|
169
|
+
const resource = resources[0].name;
|
|
170
|
+
if (q.kind === "path") {
|
|
171
|
+
if (/\$[A-Za-z_]/.test(q.text))
|
|
172
|
+
fail("a path pattern takes {{input}} placeholders, not $parameters", text);
|
|
173
|
+
const used = new Set([...q.text.matchAll(PLACEHOLDER)].map((m) => m[1]));
|
|
174
|
+
for (const u of used)
|
|
175
|
+
if (!names.has(u))
|
|
176
|
+
fail(`{{${u}}} names no input`, text);
|
|
177
|
+
// A scope is where the query is read, not part of its text.
|
|
178
|
+
for (const input of e.inputs)
|
|
179
|
+
if (input.kind !== "scope" && !used.has(input.name))
|
|
180
|
+
fail(`the path pattern never uses ${input.name}`, text);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
if (/\{\{/.test(q.text))
|
|
184
|
+
fail("a Cypher query takes $parameters, never spliced {{input}} text", text);
|
|
185
|
+
if (!/^\s*(MATCH|OPTIONAL MATCH|WITH|CALL|UNWIND)\b/i.test(q.text))
|
|
186
|
+
fail("a Cypher query starts with a reading clause", text);
|
|
187
|
+
if (/\b(CREATE|MERGE|DELETE|DETACH|SET|REMOVE|DROP)\b/i.test(q.text))
|
|
188
|
+
fail("a Cypher query only reads", text);
|
|
189
|
+
if (!balanced(q.text))
|
|
190
|
+
fail("its brackets do not balance", text);
|
|
191
|
+
const params = new Set([...q.text.matchAll(PARAM)].map((m) => m[1]));
|
|
192
|
+
if (!params.has("key"))
|
|
193
|
+
fail("a Cypher query binds the resource as $key", text);
|
|
194
|
+
for (const p of params)
|
|
195
|
+
if (p !== "key" && !names.has(p))
|
|
196
|
+
fail(`$${p} names no input`, text);
|
|
197
|
+
for (const input of e.inputs)
|
|
198
|
+
if (input.name !== resource && input.kind !== "scope" && !params.has(input.name))
|
|
199
|
+
fail(`the query never uses $${input.name}`, text);
|
|
200
|
+
}
|
|
201
|
+
return e;
|
|
133
202
|
}
|
|
134
203
|
/** Whether (), [] and {} nest, outside quoted strings. */
|
|
135
204
|
function balanced(text) {
|
|
@@ -157,6 +226,76 @@ export function investigationTemplates() {
|
|
|
157
226
|
cache ?? (cache = parseTemplates(data));
|
|
158
227
|
return cache;
|
|
159
228
|
}
|
|
229
|
+
/** The directory a project's templates file is read in: the workspace root, or the project root when `dir` is in no workspace. */
|
|
230
|
+
export function templatesRoot(dir) {
|
|
231
|
+
return findWorkspaceRoot(dir)?.dir ?? findProjectRoot(dir);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The template catalog for the project at `dir` (behold#1142): chant's
|
|
235
|
+
* templates, then the project's own from {@link PROJECT_TEMPLATES_FILE} at
|
|
236
|
+
* {@link templatesRoot}, each marked with its origin. A workspace member's
|
|
237
|
+
* own file is not read. A project entry that does not hold to the entry kind,
|
|
238
|
+
* or whose id is one of chant's, is left out and listed under `refused`, and
|
|
239
|
+
* the others load. A file that cannot be read as a templates file is refused
|
|
240
|
+
* whole, as one entry. No file means chant's templates alone.
|
|
241
|
+
*/
|
|
242
|
+
export function templateCatalog(dir) {
|
|
243
|
+
const chant = investigationTemplates().map((t) => ({ ...t, origin: "chant" }));
|
|
244
|
+
const file = PROJECT_TEMPLATES_FILE;
|
|
245
|
+
let text;
|
|
246
|
+
try {
|
|
247
|
+
text = readFileSync(join(templatesRoot(dir), file), "utf-8");
|
|
248
|
+
}
|
|
249
|
+
catch (e) {
|
|
250
|
+
if (e.code === "ENOENT")
|
|
251
|
+
return { templates: chant, refused: [] };
|
|
252
|
+
return { templates: chant, refused: [{ file, message: `${file}: cannot be read: ${e.message}` }] };
|
|
253
|
+
}
|
|
254
|
+
let raw;
|
|
255
|
+
try {
|
|
256
|
+
raw = JSON.parse(text);
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
return { templates: chant, refused: [{ file, message: `${file}: is not JSON: ${e.message}` }] };
|
|
260
|
+
}
|
|
261
|
+
let checked;
|
|
262
|
+
try {
|
|
263
|
+
checked = checkTemplates(raw, file);
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
if (!(e instanceof TemplateCatalogError))
|
|
267
|
+
throw e;
|
|
268
|
+
return { templates: chant, refused: [refusal(e, file)] };
|
|
269
|
+
}
|
|
270
|
+
const refused = checked.refused.map((e) => refusal(e, file, raw.templates));
|
|
271
|
+
const chantIds = new Set(chant.map((t) => t.id));
|
|
272
|
+
const own = [];
|
|
273
|
+
for (const t of checked.templates) {
|
|
274
|
+
if (chantIds.has(t.id)) {
|
|
275
|
+
const i = raw.templates.indexOf(t);
|
|
276
|
+
const field = `templates[${i}].id`;
|
|
277
|
+
refused.push({
|
|
278
|
+
id: t.id,
|
|
279
|
+
file,
|
|
280
|
+
field,
|
|
281
|
+
message: `${file} ${field}: template ${t.id}: ${CHANT_TEMPLATES_FILE} already defines ${t.id}, and an id keeps chant's meaning; rename this one`,
|
|
282
|
+
});
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
own.push({ ...t, origin: "project" });
|
|
286
|
+
}
|
|
287
|
+
return { templates: [...chant, ...own], refused };
|
|
288
|
+
}
|
|
289
|
+
function refusal(e, file, entries) {
|
|
290
|
+
const index = e.field?.match(/^templates\[(\d+)\]/)?.[1];
|
|
291
|
+
const id = index !== undefined ? entries?.[Number(index)]?.id : undefined;
|
|
292
|
+
return {
|
|
293
|
+
...(typeof id === "string" && ID.test(id) ? { id } : {}),
|
|
294
|
+
file,
|
|
295
|
+
...(e.field ? { field: e.field } : {}),
|
|
296
|
+
message: e.message,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
160
299
|
/** A value spliced into a path pattern is one search term: letters, digits and `_ : . - / * ( ) , [ ]` only. */
|
|
161
300
|
const TERM_VALUE = /^[A-Za-z0-9_:.\-/*(),[\]]+$/;
|
|
162
301
|
/**
|
|
@@ -46,6 +46,21 @@ export declare function renderIndexImport(plan: IndexImportPlan, plugins: readon
|
|
|
46
46
|
};
|
|
47
47
|
/** The report as written: two-space JSON and a final newline. */
|
|
48
48
|
export declare function indexImportReportJson(report: IndexImportReport): string;
|
|
49
|
+
/**
|
|
50
|
+
* The project the declared check reads. It is the project the command runs
|
|
51
|
+
* in: the nearest `chant.config` at or above the working directory (or
|
|
52
|
+
* `projectDir`), wherever `--output` points. Run from outside any project,
|
|
53
|
+
* the project above the output's parent is the fallback. `dir` is where the
|
|
54
|
+
* search started when none is found, and `found` is false.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveIndexImportProject(opts: {
|
|
57
|
+
cwd: string;
|
|
58
|
+
output?: string;
|
|
59
|
+
projectDir?: string;
|
|
60
|
+
}): {
|
|
61
|
+
dir: string;
|
|
62
|
+
found: boolean;
|
|
63
|
+
};
|
|
49
64
|
export declare function importFromIndex(options: IndexImportOptions): Promise<IndexImportResult>;
|
|
50
65
|
/** One line per status: what was imported, declared and left out. */
|
|
51
66
|
export declare function summarizeIndexImport(report: IndexImportReport): string;
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
18
18
|
import { dirname, join, relative, resolve } from "path";
|
|
19
|
+
import { findProjectConfigPastFragments } from "../../config.js";
|
|
19
20
|
import { adoptionFileFromImportReport, adoptionFileJson } from "../../lifecycle/adoption-file.js";
|
|
20
21
|
import { declaredNodes, indexImportHeader, planIndexImport, selectionIsEmpty, } from "../../lifecycle/index-import.js";
|
|
21
|
-
import { generateOrganizedFiles } from "./import.js";
|
|
22
|
+
import { buildErrorWarnings, generateOrganizedFiles } from "./import.js";
|
|
22
23
|
export const INDEX_IMPORT_REPORT_FILE = "chant-index-import.json";
|
|
23
24
|
function asDocuments(parsed, from) {
|
|
24
25
|
const list = Array.isArray(parsed)
|
|
@@ -139,9 +140,28 @@ async function pluginsFor(docs, projectDir) {
|
|
|
139
140
|
}
|
|
140
141
|
return plugins;
|
|
141
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* The project the declared check reads. It is the project the command runs
|
|
145
|
+
* in: the nearest `chant.config` at or above the working directory (or
|
|
146
|
+
* `projectDir`), wherever `--output` points. Run from outside any project,
|
|
147
|
+
* the project above the output's parent is the fallback. `dir` is where the
|
|
148
|
+
* search started when none is found, and `found` is false.
|
|
149
|
+
*/
|
|
150
|
+
export function resolveIndexImportProject(opts) {
|
|
151
|
+
const starts = [resolve(opts.projectDir ?? opts.cwd)];
|
|
152
|
+
if (!opts.projectDir && opts.output)
|
|
153
|
+
starts.push(dirname(resolve(opts.output)));
|
|
154
|
+
for (const start of starts) {
|
|
155
|
+
const { dir, configPath } = findProjectConfigPastFragments(start);
|
|
156
|
+
if (configPath)
|
|
157
|
+
return { dir, found: true };
|
|
158
|
+
}
|
|
159
|
+
return { dir: starts[0], found: false };
|
|
160
|
+
}
|
|
142
161
|
export async function importFromIndex(options) {
|
|
143
162
|
const outputDir = resolve(options.output ?? "./infra/");
|
|
144
|
-
const
|
|
163
|
+
const project0 = resolveIndexImportProject({ cwd: process.cwd(), output: options.output, projectDir: options.projectDir });
|
|
164
|
+
const projectDir = project0.dir;
|
|
145
165
|
const warnings = [];
|
|
146
166
|
const fail = (error) => ({ success: false, generatedFiles: [], warnings, error });
|
|
147
167
|
if (selectionIsEmpty(options.selection)) {
|
|
@@ -161,7 +181,9 @@ export async function importFromIndex(options) {
|
|
|
161
181
|
entities = options.declaredEntities;
|
|
162
182
|
}
|
|
163
183
|
else {
|
|
164
|
-
const project =
|
|
184
|
+
const project = project0.found
|
|
185
|
+
? await projectEntities(projectDir, options.src, plugins)
|
|
186
|
+
: { entities: new Map(), warning: `no chant.config found at or above ${projectDir}, so no indexed resource was checked against declarations; run the command inside the project` };
|
|
165
187
|
if (project.warning)
|
|
166
188
|
warnings.push(project.warning);
|
|
167
189
|
entities = project.entities;
|
|
@@ -210,6 +232,18 @@ export async function importFromIndex(options) {
|
|
|
210
232
|
return { success: false, generatedFiles, warnings, error: `no adoption file written: ${err instanceof Error ? err.message : String(err)}`, report: plan.report };
|
|
211
233
|
}
|
|
212
234
|
}
|
|
235
|
+
// As `chant import <template>` does: build what was written and name each
|
|
236
|
+
// error-severity post-synth finding that would stop `chant build`. Source
|
|
237
|
+
// that mirrors a resource as the cloud holds it can lack settings a check
|
|
238
|
+
// requires; the person sees the gap here rather than at the first build.
|
|
239
|
+
for (const group of plan.groups) {
|
|
240
|
+
const plugin = plugins.find((p) => p.name === group.lexicon);
|
|
241
|
+
const prefix = group.dir ? `${group.dir}/` : "";
|
|
242
|
+
const written = generatedFiles.filter((f) => f.endsWith(".ts") && f.startsWith(prefix)).map((f) => f.slice(prefix.length));
|
|
243
|
+
if (!plugin || written.length === 0)
|
|
244
|
+
continue;
|
|
245
|
+
warnings.push(...(await buildErrorWarnings(plugin, join(outputDir, group.dir), written)));
|
|
246
|
+
}
|
|
213
247
|
const lexicons = [...new Set(plan.groups.map((g) => g.lexicon))];
|
|
214
248
|
return {
|
|
215
249
|
success: true,
|
|
@@ -946,6 +946,12 @@ function runLifecycleDiffIndex(args) {
|
|
|
946
946
|
console.log(` ? ${name} ${joinCell(j) ?? ""}${detail}`);
|
|
947
947
|
}
|
|
948
948
|
}
|
|
949
|
+
const partial = Object.entries(part.unobservedProperties).sort(([a], [b]) => a.localeCompare(b));
|
|
950
|
+
if (partial.length > 0) {
|
|
951
|
+
console.log(formatBold("\nNOT OBSERVED BY THE INDEX (declared properties its listing does not carry; not compared):"));
|
|
952
|
+
for (const [name, keys] of partial)
|
|
953
|
+
console.log(` ? ${name}: ${keys.join(", ")}`);
|
|
954
|
+
}
|
|
949
955
|
renderDeepDiff(lexicon, part.deep, provenanceOf, args.projectRoot);
|
|
950
956
|
}
|
|
951
957
|
return result;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #5263: a `chant release` command refuses a `chant.config` it can't load,
|
|
3
|
+
* rather than reading it as one with no `release`. The member's own config
|
|
4
|
+
* and its workspace root's are both read: `release.legacyTags` and
|
|
5
|
+
* `release.breakingOnZero` come from the root too.
|
|
6
|
+
*/
|
|
7
|
+
/** The first chant whose `chant release` commands refuse a config they can't load with `release-config-unreadable`, and that reads `chant.config.ts` with the project's tsx when its own install has none (#5263). */
|
|
8
|
+
export declare const RELEASE_CONFIG_UNREADABLE_FLOOR = "0.124.104";
|
|
9
|
+
/** The fix for a config that can't be loaded: for a missing tsx, the ways to give chant one. */
|
|
10
|
+
export declare function unreadableConfigFix(message: string, version: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Print the refusal and return 1 when the config in `cwd`, or in the
|
|
13
|
+
* workspace root it sits in, can't be loaded; null when both load.
|
|
14
|
+
*/
|
|
15
|
+
export declare function refuseUnreadableReleaseConfig(cwd: string): Promise<number | null>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #5263: a `chant release` command refuses a `chant.config` it can't load,
|
|
3
|
+
* rather than reading it as one with no `release`. The member's own config
|
|
4
|
+
* and its workspace root's are both read: `release.legacyTags` and
|
|
5
|
+
* `release.breakingOnZero` come from the root too.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
9
|
+
import { formatError } from "../format.js";
|
|
10
|
+
/** The first chant whose `chant release` commands refuse a config they can't load with `release-config-unreadable`, and that reads `chant.config.ts` with the project's tsx when its own install has none (#5263). */
|
|
11
|
+
export const RELEASE_CONFIG_UNREADABLE_FLOOR = "0.124.104";
|
|
12
|
+
/** Why the config in `dir` can't be loaded, or null when it loads or there is none. */
|
|
13
|
+
async function loadFailure(dir) {
|
|
14
|
+
const ts = join(dir, "chant.config.ts");
|
|
15
|
+
const path = existsSync(ts) ? ts : join(dir, "chant.config.json");
|
|
16
|
+
if (!existsSync(path))
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
const { loadChantConfig } = await import("../../config.js");
|
|
20
|
+
await loadChantConfig(dir);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return { path, message: err instanceof Error ? err.message : String(err) };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The fix for a config that can't be loaded: for a missing tsx, the ways to give chant one. */
|
|
28
|
+
export function unreadableConfigFix(message, version) {
|
|
29
|
+
if (message.startsWith("chant needs tsx")) {
|
|
30
|
+
return ("chant reads chant.config.ts with tsx, from its own install or this project's node_modules. " +
|
|
31
|
+
`Install it in the project (npm i -D tsx), run chant beside it (npx -p tsx -p @intentius/chant@${version} chant release ...), ` +
|
|
32
|
+
"or write the config as chant.config.json.");
|
|
33
|
+
}
|
|
34
|
+
return "Fix the config so it loads: chant release reads its release block, and does not guess one.";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Print the refusal and return 1 when the config in `cwd`, or in the
|
|
38
|
+
* workspace root it sits in, can't be loaded; null when both load.
|
|
39
|
+
*/
|
|
40
|
+
export async function refuseUnreadableReleaseConfig(cwd) {
|
|
41
|
+
const dirs = [resolve(cwd)];
|
|
42
|
+
const { findWorkspaceRoot } = await import("../../project-root.js");
|
|
43
|
+
const root = findWorkspaceRoot(cwd);
|
|
44
|
+
if (root && resolve(root.dir) !== dirs[0])
|
|
45
|
+
dirs.push(resolve(root.dir));
|
|
46
|
+
for (const dir of dirs) {
|
|
47
|
+
const failed = await loadFailure(dir);
|
|
48
|
+
if (!failed)
|
|
49
|
+
continue;
|
|
50
|
+
const { readerVersion } = await import("../../workspace/declaration.js");
|
|
51
|
+
console.error(formatError({
|
|
52
|
+
message: `${failed.path} could not be loaded: ${failed.message.split("\n")[0]} [release-config-unreadable]`,
|
|
53
|
+
hint: unreadableConfigFix(failed.message, readerVersion()),
|
|
54
|
+
}));
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|