@turingcode/cli 0.1.0 → 0.1.1
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/cli/create-cli.js +9 -4
- package/dist/cli/index.js +1 -1
- package/dist/features/clock/command.js +26 -13
- package/dist/features/table/command.js +39 -28
- package/dist/features/table/contract_check.js +4 -4
- package/dist/features/table/describe.js +14 -11
- package/dist/features/table/diagnostics.js +4 -4
- package/dist/features/table/table_check.js +2 -2
- package/package.json +1 -1
package/dist/cli/create-cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import yargs from "yargs/yargs";
|
|
2
|
-
import clock from "../features/clock/command.js";
|
|
3
2
|
import table from "../features/table/command.js";
|
|
4
|
-
|
|
3
|
+
// The clock commands (../features/clock/command.js) are kept but not registered for now.
|
|
4
|
+
const commands = [...table];
|
|
5
5
|
/**
|
|
6
6
|
* Builds the yargs parser with every feature command registered.
|
|
7
7
|
*
|
|
@@ -9,13 +9,18 @@ const commands = [clock, ...table];
|
|
|
9
9
|
* @returns The parser; call `parseAsync()` to run it.
|
|
10
10
|
*/
|
|
11
11
|
export function createCli(args) {
|
|
12
|
-
|
|
12
|
+
const cli = yargs(args)
|
|
13
13
|
.scriptName("turingcode")
|
|
14
|
-
.usage("Usage: $0 <command> [options]")
|
|
14
|
+
.usage("Usage: $0 <command> [options]; $0 <command> --help for each command's usage")
|
|
15
15
|
.command(commands)
|
|
16
16
|
.demandCommand(1)
|
|
17
17
|
.strict()
|
|
18
18
|
.help()
|
|
19
|
+
.hide("help")
|
|
20
|
+
.hide("version")
|
|
21
|
+
.wrap(null)
|
|
19
22
|
.exitProcess(false)
|
|
20
23
|
.fail((message, error) => { throw error ?? new Error(message); });
|
|
24
|
+
// Type tags such as [string] add tokens without information; the typings lack this yargs 17.7 method.
|
|
25
|
+
return cli.usageConfiguration({ "hide-types": true });
|
|
21
26
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -12,7 +12,7 @@ export async function main(args = hideBin(process.argv)) {
|
|
|
12
12
|
await createCli(args).parseAsync();
|
|
13
13
|
}
|
|
14
14
|
catch (error) {
|
|
15
|
-
process.stderr.write(`turingcode: ${error.message}\nRun "turingcode --help" for usage.\n`);
|
|
15
|
+
process.stderr.write(`turingcode: ${error.message}\nRun "turingcode <command> --help" for usage.\n`);
|
|
16
16
|
process.exitCode = 1;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -30,20 +30,28 @@ const finite = (value) => {
|
|
|
30
30
|
return value;
|
|
31
31
|
};
|
|
32
32
|
const sharedOptions = {
|
|
33
|
-
project: { type: "string", describe: "Project folder name on the server
|
|
34
|
-
format: { choices: ["markdown", "json"], describe: "
|
|
35
|
-
"hse-ppm": { type: "number", coerce: finite, describe: "HSE
|
|
36
|
-
vdd: { type: "number", coerce: finite, describe: "Supply voltage in
|
|
33
|
+
project: { type: "string", describe: "Project folder name on the server" },
|
|
34
|
+
format: { choices: ["markdown", "json"], describe: "markdown | json (default markdown)" },
|
|
35
|
+
"hse-ppm": { type: "number", coerce: finite, describe: "HSE tolerance in ppm, for the worst case (default 0)" },
|
|
36
|
+
vdd: { type: "number", coerce: finite, describe: "Supply voltage in V, for SPI limits (default 3.3)" },
|
|
37
37
|
};
|
|
38
38
|
const solve = {
|
|
39
39
|
command: "solve",
|
|
40
|
-
describe: "Solve a clock tree for a target SYSCLK
|
|
40
|
+
describe: "Solve a clock tree for a target SYSCLK; prints a .ioc patch for stm32_cubetools_set_params",
|
|
41
41
|
builder: cli => cli.options({
|
|
42
42
|
...sharedOptions,
|
|
43
|
-
config: { type: "string", coerce: readJsonArg, describe: "Design
|
|
44
|
-
target: { type: "number", coerce: finite, describe: "Target SYSCLK in Hz" },
|
|
45
|
-
objective: {
|
|
46
|
-
|
|
43
|
+
config: { type: "string", coerce: readJsonArg, describe: "Design (before a project exists), inline JSON or .json path" },
|
|
44
|
+
target: { type: "number", coerce: finite, describe: "Target SYSCLK in Hz (with --project)" },
|
|
45
|
+
objective: {
|
|
46
|
+
choices: ["exact_target", "min_error", "max_clock"],
|
|
47
|
+
describe: "exact_target | min_error | max_clock (default exact_target; with --project)",
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
.example(`$0 clock solve --config '{"part":"STM32G474RETx","sources":{"hse":{"hz":8000000,"ppm":50}},`
|
|
51
|
+
+ `"system":{"objective":"exact_target","target_sysclk_hz":170000000}}'`, "")
|
|
52
|
+
.example("$0 clock solve --project my_board --target 170000000", "")
|
|
53
|
+
.epilogue("Give --project, --config or both. With --config, put target, objective, ppm and vdd inside it "
|
|
54
|
+
+ "(system, sources, conditions)."),
|
|
47
55
|
handler: args => runServerTool("stm32_cubetools_clock_solve", {
|
|
48
56
|
project_name: args.project, config: args.config, target_sysclk_hz: args.target, objective: args.objective,
|
|
49
57
|
output_format: args.format, hse_ppm: args["hse-ppm"], vdd: args.vdd,
|
|
@@ -51,16 +59,21 @@ const solve = {
|
|
|
51
59
|
};
|
|
52
60
|
const audit = {
|
|
53
61
|
command: "audit",
|
|
54
|
-
describe: "Audit a project's clocks and peripheral timing
|
|
55
|
-
builder: cli => cli.options(
|
|
62
|
+
describe: "Audit a project's clocks and peripheral timing against the datasheet limits",
|
|
63
|
+
builder: cli => cli.options({
|
|
64
|
+
...sharedOptions,
|
|
65
|
+
project: { ...sharedOptions.project, demandOption: true, describe: "Project folder name on the server (required)" },
|
|
66
|
+
})
|
|
67
|
+
.example("$0 clock audit --project my_board", ""),
|
|
56
68
|
handler: args => runServerTool("stm32_cubetools_clock_audit", {
|
|
57
69
|
project_name: args.project, output_format: args.format, hse_ppm: args["hse-ppm"], vdd: args.vdd,
|
|
58
70
|
}),
|
|
59
71
|
};
|
|
60
72
|
const command = {
|
|
61
73
|
command: "clock",
|
|
62
|
-
describe: "STM32 clock tree
|
|
63
|
-
builder: cli => cli.command(solve).command(audit).demandCommand(1)
|
|
74
|
+
describe: "Solve or audit an STM32 clock tree on the Turing Code server",
|
|
75
|
+
builder: cli => cli.command(solve).command(audit).demandCommand(1)
|
|
76
|
+
.epilogue("Needs TURINGCODE_TOKEN (gateway token); TURINGCODE_URL overrides the gateway."),
|
|
64
77
|
handler: () => { },
|
|
65
78
|
};
|
|
66
79
|
export default command;
|
|
@@ -15,19 +15,21 @@ const report = (result, text, json) => {
|
|
|
15
15
|
process.stdout.write(json ? JSON.stringify(result) + "\n" : text);
|
|
16
16
|
process.exitCode = EXIT_CODES[result.status] ?? 2;
|
|
17
17
|
};
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
json: { type: "boolean", describe: "Print the full spec result as one-line JSON instead of compact text" },
|
|
22
|
-
};
|
|
18
|
+
const CONTRACT = { type: "string", demandOption: true, describe: "Contract JSON (required)" };
|
|
19
|
+
const SOURCE_KINDS = { type: "string", demandOption: true, describe: "source_kinds registry JSON the contract pins (required)" };
|
|
20
|
+
const JSON_FLAG = { type: "boolean", describe: "Full result as one-line JSON" };
|
|
23
21
|
const check = {
|
|
24
22
|
command: "check",
|
|
25
|
-
describe: "Validate a
|
|
23
|
+
describe: "Validate a contract",
|
|
26
24
|
builder: cli => cli.options({
|
|
27
|
-
...
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
contract: { ...CONTRACT, demandOption: false, describe: "Contract JSON (required unless --kit-manifest)" },
|
|
26
|
+
"source-kinds": SOURCE_KINDS,
|
|
27
|
+
kit: { type: "boolean", describe: "Also validate the contracts it depends on (found next to it) and the references between them" },
|
|
28
|
+
"kit-manifest": { type: "string", describe: "With --kit: JSON {\"contracts\": {\"<id>@<version>\": \"<path>\"}} to validate" },
|
|
29
|
+
json: JSON_FLAG,
|
|
30
|
+
})
|
|
31
|
+
.example("$0 contract check --contract orders.json --source-kinds source_kinds.json --kit", "")
|
|
32
|
+
.epilogue("Exit: 0 VALID, 1 INVALID_CONTRACT, 2 bad input or missing file."),
|
|
31
33
|
handler: args => {
|
|
32
34
|
const result = contractCheck({
|
|
33
35
|
contract_path: args.contract, source_kinds_path: args["source-kinds"], kit: args.kit,
|
|
@@ -38,57 +40,66 @@ const check = {
|
|
|
38
40
|
};
|
|
39
41
|
const describe = {
|
|
40
42
|
command: "describe",
|
|
41
|
-
describe: "Print a contract
|
|
42
|
-
builder: cli => cli.options(
|
|
43
|
+
describe: "Print the tables a contract expects, their columns and rules, as Markdown",
|
|
44
|
+
builder: cli => cli.options({ contract: CONTRACT, "source-kinds": SOURCE_KINDS, json: JSON_FLAG })
|
|
45
|
+
.example("$0 contract describe --contract orders.json --source-kinds source_kinds.json", ""),
|
|
43
46
|
handler: args => {
|
|
44
47
|
const result = describeContract({ contract_path: args.contract, source_kinds_path: args["source-kinds"] });
|
|
45
48
|
report(result, result.markdown ?? formatContractCheck(result), args.json);
|
|
46
49
|
},
|
|
47
50
|
};
|
|
48
51
|
/**
|
|
49
|
-
* Parses `--
|
|
52
|
+
* Parses `--dep <contract_id@version>=<tables file>` flags.
|
|
50
53
|
*
|
|
51
54
|
* @param {string[]} values - Raw flag values.
|
|
52
|
-
* @returns {Record<string, {output_path: string}>} pin ->
|
|
55
|
+
* @returns {Record<string, {output_path: string}>} pin -> tables file.
|
|
53
56
|
* @throws {Error} When a value has no `=`.
|
|
54
57
|
*/
|
|
55
|
-
function
|
|
58
|
+
function parseDeps(values) {
|
|
56
59
|
return Object.fromEntries(values.map(v => {
|
|
57
60
|
const at = v.indexOf("=");
|
|
58
61
|
if (at < 1)
|
|
59
|
-
throw new Error(`--
|
|
62
|
+
throw new Error(`--dep expects <contract_id@version>=<tables file>, got '${v}'`);
|
|
60
63
|
return [v.slice(0, at), { output_path: v.slice(at + 1) }];
|
|
61
64
|
}));
|
|
62
65
|
}
|
|
63
66
|
const tableCheckCommand = {
|
|
64
67
|
command: "check",
|
|
65
|
-
describe: "Check
|
|
68
|
+
describe: "Check tables against a contract",
|
|
66
69
|
builder: cli => cli.options({
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
type: "string", array: true, coerce:
|
|
72
|
-
describe: "
|
|
70
|
+
contract: CONTRACT,
|
|
71
|
+
"source-kinds": SOURCE_KINDS,
|
|
72
|
+
tables: { type: "string", demandOption: true, describe: "Markdown file of tables, or folder of <Table>.csv (required)" },
|
|
73
|
+
dep: {
|
|
74
|
+
type: "string", array: true, coerce: parseDeps,
|
|
75
|
+
describe: "<pin>=<tables file> for each contract this one depends on (`contract describe` lists them)",
|
|
73
76
|
},
|
|
74
|
-
|
|
77
|
+
"contract-id": { type: "string", describe: "Expected <contract_id>@<version> of --contract" },
|
|
78
|
+
json: JSON_FLAG,
|
|
79
|
+
})
|
|
80
|
+
.example("$0 table check --contract orders.json --source-kinds source_kinds.json --tables orders.md", "")
|
|
81
|
+
.epilogue([
|
|
82
|
+
"Prints PASS or FAIL, then each failing item with how to fix it; after fixing, run it again to confirm.",
|
|
83
|
+
"Rules listed as \"not checked yet\" are not verified by this version. `contract describe` shows the tables a contract expects.",
|
|
84
|
+
"Exit: 0 PASS, 1 FAIL or invalid contract, 2 bad input or missing file.",
|
|
85
|
+
].join("\n")),
|
|
75
86
|
handler: args => {
|
|
76
87
|
const result = tableCheck({
|
|
77
|
-
contract_path: args.contract, source_kinds_path: args["source-kinds"], output_path: args.
|
|
78
|
-
contract_id: args["contract-id"], upstream_outputs: args.
|
|
88
|
+
contract_path: args.contract, source_kinds_path: args["source-kinds"], output_path: args.tables,
|
|
89
|
+
contract_id: args["contract-id"], upstream_outputs: args.dep,
|
|
79
90
|
});
|
|
80
91
|
report(result, formatTableCheck(result), args.json);
|
|
81
92
|
},
|
|
82
93
|
};
|
|
83
94
|
const contract = {
|
|
84
95
|
command: "contract",
|
|
85
|
-
describe: "
|
|
96
|
+
describe: "Validate a table contract, or print the tables it expects",
|
|
86
97
|
builder: cli => cli.command(check).command(describe).demandCommand(1),
|
|
87
98
|
handler: () => { },
|
|
88
99
|
};
|
|
89
100
|
const table = {
|
|
90
101
|
command: "table",
|
|
91
|
-
describe: "
|
|
102
|
+
describe: "Check Markdown/CSV tables against a contract",
|
|
92
103
|
builder: cli => cli.command(tableCheckCommand).demandCommand(1),
|
|
93
104
|
handler: () => { },
|
|
94
105
|
};
|
|
@@ -84,7 +84,7 @@ export function indexFolder(dir, out) {
|
|
|
84
84
|
*/
|
|
85
85
|
function statusOf(diags) {
|
|
86
86
|
const codes = new Set(diags.filter(d => d.severity === "FAIL").map(d => d.code));
|
|
87
|
-
if (codes.has("CONTRACT.MISSING_FILE") || codes.has("CONTRACT.
|
|
87
|
+
if (codes.has("CONTRACT.MISSING_FILE") || codes.has("CONTRACT.DEPENDENCY_NOT_FOUND"))
|
|
88
88
|
return "MISSING_DATA";
|
|
89
89
|
if (codes.has("CONTRACT.BOUND_EXCEEDED"))
|
|
90
90
|
return "SEARCH_BOUND_EXCEEDED";
|
|
@@ -174,7 +174,7 @@ export function contractCheck(input) {
|
|
|
174
174
|
return index ? index.get(pin) : null;
|
|
175
175
|
};
|
|
176
176
|
/** Reports an upstream pin that has no file, unless the lookup itself already failed. */
|
|
177
|
-
const notFound = (pin, from, path) => path === undefined && diags.push(contractDiag("CONTRACT.
|
|
177
|
+
const notFound = (pin, from, path) => path === undefined && diags.push(contractDiag("CONTRACT.DEPENDENCY_NOT_FOUND", `${from.pin ?? from.path}: dependency ${pin} not found`, {}, pin, manifest ? "an entry in the kit manifest" : `a contract file in ${dirname(from.path)}`));
|
|
178
178
|
const roots = [];
|
|
179
179
|
if (input.contract_path)
|
|
180
180
|
roots.push(load(input.contract_path));
|
|
@@ -198,12 +198,12 @@ export function contractCheck(input) {
|
|
|
198
198
|
return;
|
|
199
199
|
if (stack.includes(node)) {
|
|
200
200
|
const chain = [...stack.slice(stack.indexOf(node)), node].map(n => n.pin ?? n.path).join(" -> ");
|
|
201
|
-
diags.push(contractDiag("CONTRACT.CYCLE", `
|
|
201
|
+
diags.push(contractDiag("CONTRACT.CYCLE", `dependency cycle ${chain}`, {}, chain, "an acyclic graph"));
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
204
|
if (maxDepth !== undefined && stack.length >= maxDepth) {
|
|
205
205
|
const chain = [...stack, node].map(n => n.pin ?? n.path).join(" -> ");
|
|
206
|
-
diags.push(contractDiag("CONTRACT.BOUND_EXCEEDED", `
|
|
206
|
+
diags.push(contractDiag("CONTRACT.BOUND_EXCEEDED", `dependency chain deeper than max_cross_stage_depth`, {}, chain, `<= ${maxDepth} levels`));
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
209
|
stack.push(node);
|
|
@@ -28,7 +28,7 @@ function whenText(rule) {
|
|
|
28
28
|
* One plain-language sentence for a rule, for the prompt guide.
|
|
29
29
|
*
|
|
30
30
|
* @param {Rule} rule - The rule.
|
|
31
|
-
* @param {Contract} c - The contract (for
|
|
31
|
+
* @param {Contract} c - The contract (for dependency names).
|
|
32
32
|
* @returns {string} The sentence.
|
|
33
33
|
*/
|
|
34
34
|
function ruleText(rule, c) {
|
|
@@ -52,7 +52,7 @@ function ruleText(rule, c) {
|
|
|
52
52
|
+ `${list(p.value_cols)}.`;
|
|
53
53
|
case "foreign_key": {
|
|
54
54
|
const where = p.target_contracts
|
|
55
|
-
? `${p.target_table ? code(p.target_table) : "a table"} of ${list(p.target_contracts)} (
|
|
55
|
+
? `${p.target_table ? code(p.target_table) : "a table"} of ${list(p.target_contracts)} (its tables file, given with --dep)`
|
|
56
56
|
: code(`${p.target_table}.${p.target_column ?? "ID"}`);
|
|
57
57
|
return `Every ID in ${code(p.column)} must exist in ${where}` + (p.allow_dash ? "; `-` means none." : ".");
|
|
58
58
|
}
|
|
@@ -76,7 +76,7 @@ function ruleText(rule, c) {
|
|
|
76
76
|
return `Keep ${p.min_count === p.max_count ? `exactly ${p.min_count}` : `${p.min_count} to ${p.max_count}`} `
|
|
77
77
|
+ `row(s) whose ${code(p.id_col)} is ${code(p.id_value)}.`;
|
|
78
78
|
case "extension_reader_citation":
|
|
79
|
-
return `When
|
|
79
|
+
return `When ${list(p.upstream_stages)} declares an extension whose Reader matches this contract (${code(c.stage_id)}), `
|
|
80
80
|
+ "cite its column name (or one of its row IDs; a table's name or row IDs for a new table) outside the "
|
|
81
81
|
+ `${list(p.exclude_sections ?? ["Inputs", "Extensions"])} sections.`;
|
|
82
82
|
case "written_equals":
|
|
@@ -95,7 +95,7 @@ function ruleText(rule, c) {
|
|
|
95
95
|
* @returns {string[]} Markdown lines.
|
|
96
96
|
*/
|
|
97
97
|
function tableSection(t, c) {
|
|
98
|
-
const lines = [
|
|
98
|
+
const lines = [`### Table \`${t.name}\`${t.required ? "" : " (optional)"}`, ""];
|
|
99
99
|
if (t.id_column)
|
|
100
100
|
lines.push(`Row ID: ${code(t.id_column)}, matching ${code(t.id_pattern)}, unique.`);
|
|
101
101
|
for (const s of t.sentinel_rows ?? []) {
|
|
@@ -116,7 +116,7 @@ function tableSection(t, c) {
|
|
|
116
116
|
return lines;
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
|
-
* Renders a contract as the Markdown
|
|
119
|
+
* Renders a contract as the Markdown guide to the tables it expects (spec §2.3).
|
|
120
120
|
*
|
|
121
121
|
* @param {Contract} c - A valid contract.
|
|
122
122
|
* @param {SourceKinds} registry - Its pinned source_kinds registry.
|
|
@@ -124,13 +124,13 @@ function tableSection(t, c) {
|
|
|
124
124
|
*/
|
|
125
125
|
export function renderGuide(c, registry) {
|
|
126
126
|
const lines = [
|
|
127
|
-
`#
|
|
127
|
+
`# Contract ${c.contract_id}@${c.version}`, "", "## Format", "",
|
|
128
128
|
c.input_format === "csv"
|
|
129
|
-
? "Write each table as `<Table>.csv` in
|
|
130
|
-
: "Write each table under its
|
|
129
|
+
? "Write each table as `<Table>.csv` in one folder, header row first."
|
|
130
|
+
: "Write each table under a heading with its name, e.g. `## " + c.tables[0].name + "`, as a Markdown table: a header row with exactly the "
|
|
131
131
|
+ "columns below in this order, a `|---|` separator row, then one row per item. Write `\\|` for a `|` "
|
|
132
132
|
+ "inside a cell. Leave no table out, and add no table or column that is not declared.",
|
|
133
|
-
"",
|
|
133
|
+
"", "## Tables", "",
|
|
134
134
|
];
|
|
135
135
|
for (const t of c.tables)
|
|
136
136
|
lines.push(...tableSection(t, c));
|
|
@@ -140,7 +140,7 @@ export function renderGuide(c, registry) {
|
|
|
140
140
|
lines.push(...c.cross_table_rules.map(r => `- ${ruleText(r, c)}`), ...crossProse.map(r => `- ${r.section}: ${r.text}`), "");
|
|
141
141
|
}
|
|
142
142
|
const policy = c.extensions_policy;
|
|
143
|
-
lines.push("##
|
|
143
|
+
lines.push("## Extension declarations", "");
|
|
144
144
|
if (!policy.allowed) {
|
|
145
145
|
lines.push("No extra tables or columns are allowed.", "");
|
|
146
146
|
}
|
|
@@ -165,7 +165,7 @@ export function renderGuide(c, registry) {
|
|
|
165
165
|
lines.push(`Source priority, highest first: ${list(c.source_order)}.`, "");
|
|
166
166
|
const ut = c.unit_table;
|
|
167
167
|
if (ut) {
|
|
168
|
-
lines.push("##
|
|
168
|
+
lines.push("## Unit spellings", "", `Write units as one of: ${list(ut.kept_units)}.`);
|
|
169
169
|
const conv = Object.entries(ut.convert_units).map(([from, [to, f]]) => f === "1" ? `${code(from)} is ${code(to)}` : `${code(from)} is ${code(to)} × ${f}`);
|
|
170
170
|
if (conv.length)
|
|
171
171
|
lines.push(`Other spellings: ${conv.join("; ")}.`);
|
|
@@ -173,6 +173,9 @@ export function renderGuide(c, registry) {
|
|
|
173
173
|
lines.push(`Scale by these factors only, written next to \`*\` or \`/\`: ${list(ut.unit_factors)}.`);
|
|
174
174
|
lines.push("");
|
|
175
175
|
}
|
|
176
|
+
const deps = c.upstream_contracts.map(pin => ` --dep ${pin}=<its tables file>`).join("");
|
|
177
|
+
lines.push("## Checking", "", "```", `turingcode table check --contract <this contract> --source-kinds <registry> `
|
|
178
|
+
+ `--tables <your tables file>${deps}`, "```", "");
|
|
176
179
|
return lines.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
177
180
|
}
|
|
178
181
|
/**
|
|
@@ -14,7 +14,7 @@ const CONTRACT_HINTS = {
|
|
|
14
14
|
"CONTRACT.REQUIRES_FIELD": ["Add the top-level field that this rule needs.", "spec §3.1"],
|
|
15
15
|
"CONTRACT.ORPHAN_REF": ["Point the reference at a table/column that exists.", "spec §2.1"],
|
|
16
16
|
"CONTRACT.CYCLE": ["Remove the circular upstream_contracts pin.", "spec §2.1"],
|
|
17
|
-
"CONTRACT.
|
|
17
|
+
"CONTRACT.DEPENDENCY_NOT_FOUND": ["Provide the pinned dependency contract file (in the manifest or the same folder).", "spec §2.1"],
|
|
18
18
|
"CONTRACT.MANIFEST_MISMATCH": ["Make the manifest key match the file's contract_id@version.", "spec §2.1"],
|
|
19
19
|
"CONTRACT.VERSION_MISMATCH": ["Pin the version that the given file actually has.", "spec §3.5"],
|
|
20
20
|
"CONTRACT.FLOAT_LITERAL": ["Write the factor as a string, e.g. \"0.001\", so it stays exact.", "spec §3.4"],
|
|
@@ -44,11 +44,11 @@ const TABLE_HINTS = {
|
|
|
44
44
|
"C0.INVALID_EXTENSION": "Fix the Extensions row so it names a real table and a new column (or '*').",
|
|
45
45
|
"C0.INVALID_EXTENSION_TYPE": "Use one of the allowed extension types.",
|
|
46
46
|
"C0.INVALID_EXTENSION_SOURCE": "Use one of the allowed extension sources.",
|
|
47
|
-
"C0.INVALID_EXTENSION_READER": "Write the reader in the
|
|
47
|
+
"C0.INVALID_EXTENSION_READER": "Write the reader in the form shown in 'expected'.",
|
|
48
48
|
"C0.EXTENSION_TYPE": "Make the cell match the type its Extensions row declares.",
|
|
49
49
|
"C1.UNKNOWN_REF": "Cite only IDs that exist in the referenced table.",
|
|
50
|
-
"C1.EXTENSION_NOT_CITED": "Cite the extension's column name (or one of its row IDs)
|
|
51
|
-
"C1.
|
|
50
|
+
"C1.EXTENSION_NOT_CITED": "Cite the extension's column name (or one of its row IDs) in these tables.",
|
|
51
|
+
"C1.MISSING_DEP_TABLES": "Pass the dependency's tables file with --dep <pin>=<file>.",
|
|
52
52
|
...Object.fromEntries(["C0", "C1", "C2", "C3", "C4", "C5"].map(g => [`${g}.NOT_CHECKED`, "Nothing to fix: this engine version cannot check this rule yet, so check it yourself."])),
|
|
53
53
|
"TABLE.MISSING_FILE": "Check the path; the file must exist and be readable.",
|
|
54
54
|
"TABLE.INVALID_INPUT": "Fix the command arguments named in the message.",
|
|
@@ -421,7 +421,7 @@ function runRule(rule, table, stage, upstreams, out) {
|
|
|
421
421
|
: [e.column, ...(p.allow_row_id_for_column === false ? []
|
|
422
422
|
: upRows.filter(r => !isEmpty(r.cells[e.column] ?? "")).map(r => r.label))];
|
|
423
423
|
if (!candidates.some(w => cites(text, w))) {
|
|
424
|
-
fail("C1.EXTENSION_NOT_CITED", `${id} extension ${e.table}.${e.column}
|
|
424
|
+
fail("C1.EXTENSION_NOT_CITED", `${id} extension ${e.table}.${e.column} names this contract as reader but is never cited`, "-", e.column, "(not cited)", show(candidates.slice(0, 10)), e.table);
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
}
|
|
@@ -505,7 +505,7 @@ export function tableCheck(input) {
|
|
|
505
505
|
for (const upPin of contract.upstream_contracts) {
|
|
506
506
|
const given = input.upstream_outputs?.[upPin];
|
|
507
507
|
if (!given) {
|
|
508
|
-
return stop("MISSING_DATA", "C1.
|
|
508
|
+
return stop("MISSING_DATA", "C1.MISSING_DEP_TABLES", `no tables file given for dependency ${upPin}`, "(absent)", `--dep ${upPin}=<tables file>`);
|
|
509
509
|
}
|
|
510
510
|
const upContract = JSON.parse(readFileSync(index.get(upPin), "utf-8").replace(/^/, ""));
|
|
511
511
|
const upOutput = read(given.output_path, upContract);
|