@loomcli/core 0.5.0 → 0.6.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/application.d.ts +18 -2
- package/dist/application.js +266 -71
- package/dist/bindings.d.ts +15 -10
- package/dist/bindings.js +34 -15
- package/dist/chain.d.ts +15 -6
- package/dist/chain.js +40 -20
- package/dist/command-rules.d.ts +55 -0
- package/dist/command-rules.js +142 -0
- package/dist/command.d.ts +65 -23
- package/dist/command.js +695 -226
- package/dist/controls.d.ts +8 -0
- package/dist/controls.js +23 -0
- package/dist/defect.d.ts +18 -0
- package/dist/defect.js +272 -0
- package/dist/developer.d.ts +24 -0
- package/dist/developer.js +52 -0
- package/dist/diagnostic-text.d.ts +81 -0
- package/dist/diagnostic-text.js +283 -0
- package/dist/diagnostic.d.ts +11 -0
- package/dist/diagnostic.js +70 -0
- package/dist/errors.d.ts +108 -24
- package/dist/errors.js +324 -53
- package/dist/exit-codes.d.ts +45 -0
- package/dist/exit-codes.js +46 -0
- package/dist/extension.d.ts +41 -8
- package/dist/extension.js +142 -57
- package/dist/facts.d.ts +66 -11
- package/dist/facts.js +98 -22
- package/dist/globals.d.ts +29 -21
- package/dist/globals.js +115 -46
- package/dist/hints.d.ts +79 -0
- package/dist/hints.js +247 -0
- package/dist/host.d.ts +13 -0
- package/dist/host.js +43 -1
- package/dist/identity.d.ts +19 -0
- package/dist/identity.js +72 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +5 -0
- package/dist/input-rules.d.ts +64 -0
- package/dist/input-rules.js +145 -0
- package/dist/inspect.d.ts +12 -4
- package/dist/inspect.js +88 -28
- package/dist/lanes.js +1 -1
- package/dist/locate.js +4 -4
- package/dist/options.d.ts +23 -2
- package/dist/options.js +135 -44
- package/dist/output.d.ts +9 -2
- package/dist/output.js +18 -2
- package/dist/plain.d.ts +6 -0
- package/dist/plain.js +12 -0
- package/dist/plugin-rules.d.ts +62 -0
- package/dist/plugin-rules.js +155 -0
- package/dist/plugin.d.ts +22 -10
- package/dist/plugin.js +348 -116
- package/dist/prototypes.d.ts +7 -0
- package/dist/prototypes.js +29 -0
- package/dist/rendering.d.ts +6 -1
- package/dist/rendering.js +23 -5
- package/dist/rules.d.ts +51 -0
- package/dist/rules.js +115 -0
- package/dist/sequence.js +6 -1
- package/dist/sources.d.ts +6 -4
- package/dist/sources.js +22 -13
- package/dist/style-wire.js +1 -1
- package/dist/style.js +1 -1
- package/dist/theme.d.ts +4 -0
- package/dist/theme.js +25 -5
- package/dist/thenable.d.ts +15 -0
- package/dist/thenable.js +29 -0
- package/dist/translators.d.ts +69 -0
- package/dist/translators.js +253 -0
- package/dist/types.d.ts +11 -1
- package/dist/validation.d.ts +44 -3
- package/dist/validation.js +156 -57
- package/dist/view.d.ts +48 -14
- package/dist/view.js +155 -77
- package/package.json +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { registerRule } from './diagnostic-text.js';
|
|
2
|
+
/*
|
|
3
|
+
* Core's rules for the declaration faults of arguments, options, validators, defaults, global
|
|
4
|
+
* options, and environment bindings. Each is declared once here and shared by every site that
|
|
5
|
+
* raises it, as a plugin's rules are.
|
|
6
|
+
*/
|
|
7
|
+
/** An option declared with a type other than string or Boolean. */
|
|
8
|
+
const optionType = registerRule('@loomcli/core/option-type', {
|
|
9
|
+
explanation: 'The type decides how the parser reads an option: a string option consumes a value, and a Boolean option consumes none. Core reads no other kind.',
|
|
10
|
+
headline: 'Invalid option type',
|
|
11
|
+
});
|
|
12
|
+
/** A short alias that is not one ASCII letter. */
|
|
13
|
+
const shortAlias = registerRule('@loomcli/core/short-alias', {
|
|
14
|
+
explanation: 'An operator types a short alias as a hyphen and one letter, and several combine into one short group such as -tm, so each is one ASCII letter the parser can split apart.',
|
|
15
|
+
headline: 'Invalid short alias',
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* A yes-or-no declaration key, such as `required`, `hidden`, or an extension descriptor's
|
|
19
|
+
* `collect`, that holds a value other than a Boolean.
|
|
20
|
+
*/
|
|
21
|
+
const flagNotBoolean = registerRule('@loomcli/core/flag-not-boolean', {
|
|
22
|
+
explanation: 'hidden, shortOnly, multiple, required, variadic, validateOmitted, and an extension\'s collect each answer one yes-or-no question about a declaration, so each holds true or false. A value such as the string "false" would read as true.',
|
|
23
|
+
headline: 'Flag not a Boolean',
|
|
24
|
+
});
|
|
25
|
+
/** `shortOnly` on an option that declares no short alias. */
|
|
26
|
+
const shortOnlyWithoutShort = registerRule('@loomcli/core/short-only-without-short', {
|
|
27
|
+
explanation: 'shortOnly removes every long spelling of an option, so an option with no short alias would leave an operator no spelling to type.',
|
|
28
|
+
headline: 'Short only with no short alias',
|
|
29
|
+
});
|
|
30
|
+
/** `multiple` on a Boolean option. */
|
|
31
|
+
const booleanOptionMultiple = registerRule('@loomcli/core/boolean-option-multiple', {
|
|
32
|
+
explanation: 'A Boolean option reports whether its spelling was supplied, so a repeat has no second value to collect. multiple collects each occurrence of a string option into an array.',
|
|
33
|
+
headline: 'Boolean option takes one value',
|
|
34
|
+
});
|
|
35
|
+
/** `polarity` on a string option. */
|
|
36
|
+
const polarityOnString = registerRule('@loomcli/core/polarity-on-string', {
|
|
37
|
+
explanation: 'Polarity chooses which long forms a Boolean option accepts and what its absence means. A string option takes its value from the operator, so it has no polarity.',
|
|
38
|
+
headline: 'Polarity on a string option',
|
|
39
|
+
});
|
|
40
|
+
/** A polarity outside the three settings. */
|
|
41
|
+
const optionPolarity = registerRule('@loomcli/core/option-polarity', {
|
|
42
|
+
explanation: "Polarity chooses a Boolean option's long forms and its absent value from three settings: positive, both, and negative.",
|
|
43
|
+
headline: 'Invalid polarity',
|
|
44
|
+
});
|
|
45
|
+
/** `polarity: 'both'` beside `shortOnly`. */
|
|
46
|
+
const shortOnlyBothPolarities = registerRule('@loomcli/core/short-only-both-polarities', {
|
|
47
|
+
explanation: 'Polarity both gives an option one spelling that turns it on and one that turns it off. shortOnly leaves the option its short alias alone, and one spelling sets one value.',
|
|
48
|
+
headline: 'Both polarities with short only',
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* One spelling that two options in one scope claim, the application's, a plugin's, or one a
|
|
52
|
+
* plugin's hook declared.
|
|
53
|
+
*/
|
|
54
|
+
const spellingTaken = registerRule('@loomcli/core/spelling-taken', {
|
|
55
|
+
explanation: "The parser reads each spelling as one option, and a Command's own options share one invocation with the global options and every installed plugin's options. A spelling two options claim, a short alias or a generated negative form included, would reach only one of them.",
|
|
56
|
+
headline: 'Spelling used twice',
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Two options with one declared name in one scope, the application's, a plugin's, or one a
|
|
60
|
+
* plugin's hook declared.
|
|
61
|
+
*/
|
|
62
|
+
const optionDeclaredTwice = registerRule('@loomcli/core/option-declared-twice', {
|
|
63
|
+
explanation: "An action reads the global options and its Command's own options from one options object, each under its declared name, and the pre-scan reads the global options and every installed plugin's options from one table. Two options with one name in either leave one of them unreadable.",
|
|
64
|
+
headline: 'Option declared twice',
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* An input a plugin's `onCommandAttach` hook declares under a name that an input of the other kind
|
|
68
|
+
* already holds in the Command's scope: an argument under an option's name, or an option under an
|
|
69
|
+
* argument's name.
|
|
70
|
+
*/
|
|
71
|
+
const nameSharedAcrossKinds = registerRule('@loomcli/core/name-shared-across-kinds', {
|
|
72
|
+
explanation: "An onCommandAttach hook adds inputs to a Command whose other inputs the plugin did not declare, so each name a hook declares stays apart from every argument and option in the Command's scope, whichever kind holds it. An author who gives an argument and an option one name does so knowingly, but a hook cannot see the Command's inputs, so a shared name there is an accident the author did not choose.",
|
|
73
|
+
headline: 'Argument and option share a name',
|
|
74
|
+
});
|
|
75
|
+
/** `required` or `validateOmitted` on a global option. */
|
|
76
|
+
const globalPresenceRule = registerRule('@loomcli/core/global-presence-rule', {
|
|
77
|
+
explanation: 'A global option is validated on every Command, the Commands of plugins included, so a rule that its value must exist would fail a Command that never reads it. An omitted global option is absent.',
|
|
78
|
+
headline: 'Presence rule on a global option',
|
|
79
|
+
});
|
|
80
|
+
/** `globalOption()` after the application's own `command()` or `action()`. */
|
|
81
|
+
const globalOptionAfterCommand = registerRule('@loomcli/core/global-option-after-command', {
|
|
82
|
+
explanation: 'A Command attached with command() and the root action read their types from the global options declared before them, so a global option declared later would reach an action whose types never name it.',
|
|
83
|
+
headline: 'Global option after a Command',
|
|
84
|
+
});
|
|
85
|
+
/** An environment binding on a multiple option. */
|
|
86
|
+
const envOnMultiple = registerRule('@loomcli/core/env-on-multiple', {
|
|
87
|
+
explanation: 'A variable holds one string, and core never splits it, so it cannot supply the several values a multiple option collects. The configuration source supplies a list.',
|
|
88
|
+
headline: 'Environment binding on a list',
|
|
89
|
+
});
|
|
90
|
+
/** An environment binding whose name is outside the variable name grammar. */
|
|
91
|
+
const envName = registerRule('@loomcli/core/env-name', {
|
|
92
|
+
explanation: 'The input-source stage reads the variable an option binds by its name, and a shell sets a variable only under a name of letters, digits, and underscores that does not start with a digit.',
|
|
93
|
+
headline: 'Invalid variable name',
|
|
94
|
+
});
|
|
95
|
+
/** An environment binding on an argument. */
|
|
96
|
+
const envOnArgument = registerRule('@loomcli/core/env-on-argument', {
|
|
97
|
+
explanation: 'An argument is identified by its place among the bare tokens, so no variable can stand in for it. An option names itself on the command line, which lets a variable fill it.',
|
|
98
|
+
headline: 'Environment binding on an argument',
|
|
99
|
+
});
|
|
100
|
+
/** One variable that two options in one invocation's scope bind. */
|
|
101
|
+
const variableBoundTwice = registerRule('@loomcli/core/variable-bound-twice', {
|
|
102
|
+
explanation: "Within one invocation's scope a variable fills one option, so two options that bind it would both take the value an operator set for one of them.",
|
|
103
|
+
headline: 'Variable bound twice',
|
|
104
|
+
});
|
|
105
|
+
/** `validateOmitted` on a declaration whose absence another rule already decides. */
|
|
106
|
+
const omissionAlreadyDecided = registerRule('@loomcli/core/omission-already-decided', {
|
|
107
|
+
explanation: 'validateOmitted sends an omitted value to its validator, which only an input with no other absence rule needs. An omitted required input fails, a default fills an omitted value, and an omitted multiple option or variadic argument receives an empty array.',
|
|
108
|
+
headline: 'Absence already decided',
|
|
109
|
+
});
|
|
110
|
+
/** `validateOmitted` on a declaration with no validator. */
|
|
111
|
+
const omissionWithoutValidator = registerRule('@loomcli/core/omission-without-validator', {
|
|
112
|
+
explanation: "validateOmitted sends an omitted value to the input's validator, so an input with no validator has nothing to receive it.",
|
|
113
|
+
headline: 'Omission with no validator',
|
|
114
|
+
});
|
|
115
|
+
/** `validate`, `default`, `required`, or `validateOmitted` on a Boolean option. */
|
|
116
|
+
const booleanOptionValueRule = registerRule('@loomcli/core/boolean-option-value-rule', {
|
|
117
|
+
explanation: 'A Boolean option consumes no value, so there is nothing to validate, and its polarity decides the value an absent option reads. validate, default, required, and validateOmitted belong to inputs that take a value.',
|
|
118
|
+
headline: 'Value rule on a Boolean option',
|
|
119
|
+
});
|
|
120
|
+
/** A required input that also declares a default. */
|
|
121
|
+
const requiredWithDefault = registerRule('@loomcli/core/required-with-default', {
|
|
122
|
+
explanation: 'A default fills an omitted value, and a required input fails when it is omitted, so a required input never reads its default.',
|
|
123
|
+
headline: 'Default on a required input',
|
|
124
|
+
});
|
|
125
|
+
/** A `validate` value that is not a Standard Schema v1 object. */
|
|
126
|
+
const notAValidator = registerRule('@loomcli/core/not-a-validator', {
|
|
127
|
+
explanation: "Core validates every value through the Standard Schema v1 interface: the object's ~standard property, with version 1, a vendor, and a validate function. It calls nothing else.",
|
|
128
|
+
headline: 'Not a Standard Schema',
|
|
129
|
+
});
|
|
130
|
+
/** A default of the wrong raw shape for its declaration. */
|
|
131
|
+
const defaultShape = registerRule('@loomcli/core/default-shape', {
|
|
132
|
+
explanation: "A default stands in for the value an operator would supply. Without a validator it is that raw value, a string or, for an input that takes several values, an array of strings; with one, it is the validator's input, and an input that takes several values still takes an array of them.",
|
|
133
|
+
headline: 'Default of the wrong shape',
|
|
134
|
+
});
|
|
135
|
+
/** A declared default its validator rejected. */
|
|
136
|
+
const invalidDefault = registerRule('@loomcli/core/invalid-default', {
|
|
137
|
+
explanation: 'Each run passes every declared default through its validator before it reads a token, because a default reaches the action as a validated value. A default the validator rejects would reach no action, whatever the operator supplies.',
|
|
138
|
+
headline: 'Default rejected',
|
|
139
|
+
});
|
|
140
|
+
/** A validator's JSON Schema converter that threw or returned a value that is not a plain object. */
|
|
141
|
+
const schemaConverterFailed = registerRule('@loomcli/core/schema-converter-failed', {
|
|
142
|
+
explanation: "Help, the manifest, and completion read what an input accepts from the JSON Schema its validator publishes. A converter that throws or returns anything but a plain object publishes no shape, so a distributed build reads the input's schema as null.",
|
|
143
|
+
headline: 'Schema converter failed',
|
|
144
|
+
});
|
|
145
|
+
export { booleanOptionMultiple, booleanOptionValueRule, defaultShape, envName, envOnArgument, envOnMultiple, flagNotBoolean, globalOptionAfterCommand, globalPresenceRule, invalidDefault, notAValidator, omissionAlreadyDecided, nameSharedAcrossKinds, omissionWithoutValidator, optionDeclaredTwice, optionPolarity, optionType, polarityOnString, requiredWithDefault, schemaConverterFailed, shortAlias, shortOnlyBothPolarities, shortOnlyWithoutShort, spellingTaken, variableBoundTwice, };
|
package/dist/inspect.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BuiltCommand, BuiltGraph } from './command.js';
|
|
2
|
+
import { InternalError } from './errors.js';
|
|
2
3
|
import type { DeclaredResult } from './types.js';
|
|
3
4
|
/** The plain JSON Schema a validated input publishes, or `null` where the graph holds no shape. */
|
|
4
5
|
type InputSchema = Readonly<Record<string, unknown>> | null;
|
|
@@ -120,12 +121,14 @@ export declare function snapshot(value: unknown): unknown;
|
|
|
120
121
|
/** The declared result as plain data, or `null` on a Command that declares none. */
|
|
121
122
|
declare function resultNode(result: DeclaredResult | undefined): ResultNode | null;
|
|
122
123
|
/**
|
|
123
|
-
* Renders one built graph as frozen plain data. Nothing here reads a host fact
|
|
124
|
-
*
|
|
125
|
-
*
|
|
124
|
+
* Renders one built graph as frozen plain data. Nothing here reads a host fact; each validated
|
|
125
|
+
* input's converter is asked for its input schema, and in a development build a converter that
|
|
126
|
+
* fails is a declaration fault. The globals list holds the application's own options, then each
|
|
127
|
+
* installed plugin's in installation order, which is the order the globals table holds them in.
|
|
126
128
|
*/
|
|
127
129
|
declare function inspectGraph(name: string, graph: BuiltGraph, facts: {
|
|
128
130
|
description: string | undefined;
|
|
131
|
+
development: boolean;
|
|
129
132
|
version: string;
|
|
130
133
|
}): CommandGraph;
|
|
131
134
|
/**
|
|
@@ -142,6 +145,11 @@ interface GraphLink {
|
|
|
142
145
|
* programming error rather than an invocation fault.
|
|
143
146
|
*/
|
|
144
147
|
declare function linkOf(graph: CommandGraph): GraphLink;
|
|
148
|
+
/**
|
|
149
|
+
* The defect a graph reports when its nodes disagree with the build it was rendered from, so a
|
|
150
|
+
* node core looked up is missing.
|
|
151
|
+
*/
|
|
152
|
+
declare function graphMismatch(sentence: string): InternalError;
|
|
145
153
|
/**
|
|
146
154
|
* The routed node inside the inspected graph, which routing already proved reachable. A missing
|
|
147
155
|
* segment means the two readings of one graph disagree, so the run stops rather than hand a
|
|
@@ -149,4 +157,4 @@ declare function linkOf(graph: CommandGraph): GraphLink;
|
|
|
149
157
|
*/
|
|
150
158
|
declare function nodeAt(graph: CommandGraph, path: readonly string[]): CommandNode;
|
|
151
159
|
export type { ArgumentNode, CommandGraph, CommandNode, OptionNode, ResultNode };
|
|
152
|
-
export { inspectGraph, linkOf, nodeAt, resultNode };
|
|
160
|
+
export { graphMismatch, inspectGraph, linkOf, nodeAt, resultNode };
|
package/dist/inspect.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { InternalError } from './errors.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { asSentence, DeclarationError, InternalError, reasonOf } from './errors.js';
|
|
2
|
+
import { partOf, siteFinding } from './facts.js';
|
|
3
|
+
import { schemaConverterFailed } from './input-rules.js';
|
|
4
|
+
import { isPlainObject } from './plain.js';
|
|
5
|
+
import { foreignGraph, foreignGraphCorrection } from './rules.js';
|
|
6
|
+
import { declaringSite, inputPlace, validatesOmission } from './validation.js';
|
|
4
7
|
/** A declaration that carries no extension value publishes one shared, empty frozen record. */
|
|
5
8
|
const noExtensions = Object.freeze({});
|
|
6
9
|
/**
|
|
@@ -57,37 +60,68 @@ function publishesSchema(schema) {
|
|
|
57
60
|
'output' in props.jsonSchema &&
|
|
58
61
|
typeof props.jsonSchema.output === 'function');
|
|
59
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* The converter fault a development build reports for one input, with the way it failed and, when
|
|
65
|
+
* the converter threw, the thrown value as its cause.
|
|
66
|
+
*/
|
|
67
|
+
function converterFault(input, check, failed) {
|
|
68
|
+
const site = declaringSite(input, inputPlace(input, check));
|
|
69
|
+
const parts = {
|
|
70
|
+
correction: 'Fix the converter so it returns a JSON Schema object, or declare a validator that publishes none.',
|
|
71
|
+
findings: [siteFinding(site, partOf(site, 'validate'))],
|
|
72
|
+
sentence: `${site.subject} validator's JSON Schema converter ${failed.failure}`,
|
|
73
|
+
};
|
|
74
|
+
return 'cause' in failed
|
|
75
|
+
? new DeclarationError(schemaConverterFailed, parts, { cause: failed.cause })
|
|
76
|
+
: new DeclarationError(schemaConverterFailed, parts);
|
|
77
|
+
}
|
|
60
78
|
/**
|
|
61
79
|
* The input-side schema a declaration's validator publishes, snapshotted the way a declared
|
|
62
80
|
* default is, or `null` where the graph holds no published shape: no validator, a validator with
|
|
63
|
-
* no converter, or a converter that throws or returns anything but a plain
|
|
64
|
-
*
|
|
65
|
-
* held while the question of how a run tells development from a distributed application is
|
|
66
|
-
* decided, so it reads `null` on both paths.
|
|
81
|
+
* no converter, or, in a distributed build, a converter that throws or returns anything but a plain
|
|
82
|
+
* object. A development build reports that last case as a declaration fault instead.
|
|
67
83
|
*/
|
|
68
|
-
function inputSchema(
|
|
84
|
+
function inputSchema(input, check) {
|
|
85
|
+
const { config } = input;
|
|
69
86
|
const schema = 'validate' in config ? config.validate : undefined;
|
|
70
87
|
if (schema === undefined) {
|
|
71
88
|
return null;
|
|
72
89
|
}
|
|
73
|
-
|
|
74
|
-
//
|
|
90
|
+
let copied = undefined;
|
|
91
|
+
// The converter is the library's code from the first property read to the last key of its answer.
|
|
92
|
+
// A throw on reaching it, on calling it, or on reading what it answered is one failure.
|
|
75
93
|
try {
|
|
76
94
|
if (!publishesSchema(schema)) {
|
|
77
95
|
return null;
|
|
78
96
|
}
|
|
79
97
|
const published = schema['~standard'].jsonSchema.input(schemaTarget);
|
|
80
|
-
|
|
98
|
+
copied = isPlainObject(published) ? snapshotRecord(published) : undefined;
|
|
81
99
|
}
|
|
82
|
-
catch {
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (check.development) {
|
|
102
|
+
throw converterFault(input, check, {
|
|
103
|
+
cause: error,
|
|
104
|
+
failure: `failed for target "${schemaTarget.target}": ${asSentence(reasonOf(error))}`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
83
107
|
return null;
|
|
84
108
|
}
|
|
109
|
+
if (copied !== undefined) {
|
|
110
|
+
return copied;
|
|
111
|
+
}
|
|
112
|
+
if (check.development) {
|
|
113
|
+
throw converterFault(input, check, {
|
|
114
|
+
failure: `answered target "${schemaTarget.target}" with a value that is not a plain object.`,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
85
118
|
}
|
|
86
119
|
/** One declaration's extension record, which is the shared empty one when it carries no value. */
|
|
87
120
|
function extensionsOf(records, declaration) {
|
|
88
121
|
return records.get(declaration) ?? noExtensions;
|
|
89
122
|
}
|
|
90
|
-
function optionNode(input,
|
|
123
|
+
function optionNode(input, read) {
|
|
124
|
+
const { check, records, scope, table } = read;
|
|
91
125
|
const { config, name } = input;
|
|
92
126
|
const { long, negative, short } = spellingsOf(table, name);
|
|
93
127
|
const extensions = extensionsOf(records, input);
|
|
@@ -119,7 +153,7 @@ function optionNode(input, { records, scope, table }) {
|
|
|
119
153
|
multiple: config.multiple === true,
|
|
120
154
|
name,
|
|
121
155
|
required: config.required === true,
|
|
122
|
-
schema: inputSchema(
|
|
156
|
+
schema: inputSchema(input, check),
|
|
123
157
|
scope,
|
|
124
158
|
short,
|
|
125
159
|
type: 'string',
|
|
@@ -129,7 +163,8 @@ function optionNode(input, { records, scope, table }) {
|
|
|
129
163
|
return Object.freeze(node);
|
|
130
164
|
}
|
|
131
165
|
/** The built slots already answer presence and arity, so the node repeats no config reading. */
|
|
132
|
-
function argumentNode(slot,
|
|
166
|
+
function argumentNode(slot, read) {
|
|
167
|
+
const { check, records } = read;
|
|
133
168
|
const { config, name } = slot.input;
|
|
134
169
|
const node = {
|
|
135
170
|
default: declaredDefault(config),
|
|
@@ -137,7 +172,7 @@ function argumentNode(slot, records) {
|
|
|
137
172
|
extensions: extensionsOf(records, slot.input),
|
|
138
173
|
name,
|
|
139
174
|
required: slot.required,
|
|
140
|
-
schema: inputSchema(
|
|
175
|
+
schema: inputSchema(slot.input, check),
|
|
141
176
|
validateOmitted: validatesOmission(slot.input),
|
|
142
177
|
validated: config.validate !== undefined,
|
|
143
178
|
variadic: slot.variadic,
|
|
@@ -152,18 +187,24 @@ function optionNodes(inputs, read) {
|
|
|
152
187
|
* and the root reports the Application's, which is why the caller supplies that one.
|
|
153
188
|
*/
|
|
154
189
|
function commandNode(command, place) {
|
|
155
|
-
const { nodes, path, records } = place;
|
|
190
|
+
const { development, nodes, path, records } = place;
|
|
191
|
+
const check = { development, global: false, path };
|
|
156
192
|
const node = {
|
|
157
193
|
aliases: Object.freeze([...command.aliases]),
|
|
158
|
-
arguments: Object.freeze(command.arguments.map((slot) => argumentNode(slot, records))),
|
|
159
|
-
children: Object.freeze([...command.children].map(([name, child]) => commandNode(child, { nodes, path: Object.freeze([...path, name]), records }))),
|
|
194
|
+
arguments: Object.freeze(command.arguments.map((slot) => argumentNode(slot, { check, records }))),
|
|
195
|
+
children: Object.freeze([...command.children].map(([name, child]) => commandNode(child, { development, nodes, path: Object.freeze([...path, name]), records }))),
|
|
160
196
|
deprecated: command.deprecated,
|
|
161
197
|
description: 'description' in place ? place.description : command.description,
|
|
162
198
|
extensions: command.extensions,
|
|
163
199
|
hasAction: command.dispatch !== undefined,
|
|
164
200
|
hidden: command.hidden,
|
|
165
201
|
name: command.name,
|
|
166
|
-
options: Object.freeze(optionNodes(command.inputs, {
|
|
202
|
+
options: Object.freeze(optionNodes(command.inputs, {
|
|
203
|
+
check,
|
|
204
|
+
records,
|
|
205
|
+
scope: 'application',
|
|
206
|
+
table: command.options,
|
|
207
|
+
})),
|
|
167
208
|
path,
|
|
168
209
|
result: resultNode(command.result),
|
|
169
210
|
};
|
|
@@ -183,23 +224,27 @@ function resultNode(result) {
|
|
|
183
224
|
});
|
|
184
225
|
}
|
|
185
226
|
/**
|
|
186
|
-
* Renders one built graph as frozen plain data. Nothing here reads a host fact
|
|
187
|
-
*
|
|
188
|
-
*
|
|
227
|
+
* Renders one built graph as frozen plain data. Nothing here reads a host fact; each validated
|
|
228
|
+
* input's converter is asked for its input schema, and in a development build a converter that
|
|
229
|
+
* fails is a declaration fault. The globals list holds the application's own options, then each
|
|
230
|
+
* installed plugin's in installation order, which is the order the globals table holds them in.
|
|
189
231
|
*/
|
|
190
232
|
function inspectGraph(name, graph, facts) {
|
|
233
|
+
const { development } = facts;
|
|
191
234
|
const records = graph.extensions;
|
|
192
235
|
const table = graph.globals.options;
|
|
193
236
|
const nodes = new WeakMap();
|
|
237
|
+
const check = { development, global: true, path: [] };
|
|
194
238
|
const inspected = {
|
|
195
239
|
description: facts.description,
|
|
196
240
|
globals: Object.freeze([
|
|
197
|
-
...optionNodes(graph.globals.inputs, { records, scope: 'application', table }),
|
|
198
|
-
...graph.globals.plugins.flatMap((installed) => optionNodes(installed.inputs, { records, scope: 'plugin', table })),
|
|
241
|
+
...optionNodes(graph.globals.inputs, { check, records, scope: 'application', table }),
|
|
242
|
+
...graph.globals.plugins.flatMap((installed) => optionNodes(installed.inputs, { check, records, scope: 'plugin', table })),
|
|
199
243
|
]),
|
|
200
244
|
name,
|
|
201
245
|
root: commandNode(graph.root, {
|
|
202
246
|
description: facts.description,
|
|
247
|
+
development,
|
|
203
248
|
nodes,
|
|
204
249
|
path: Object.freeze([]),
|
|
205
250
|
records,
|
|
@@ -219,10 +264,25 @@ const links = new WeakMap();
|
|
|
219
264
|
function linkOf(graph) {
|
|
220
265
|
const link = links.get(graph);
|
|
221
266
|
if (!link) {
|
|
222
|
-
throw new InternalError(
|
|
267
|
+
throw new InternalError(foreignGraph, {
|
|
268
|
+
cause: undefined,
|
|
269
|
+
correction: 'Pass the graph inspect() returned.',
|
|
270
|
+
sentence: 'The graph was not produced by inspect().',
|
|
271
|
+
});
|
|
223
272
|
}
|
|
224
273
|
return link;
|
|
225
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* The defect a graph reports when its nodes disagree with the build it was rendered from, so a
|
|
277
|
+
* node core looked up is missing.
|
|
278
|
+
*/
|
|
279
|
+
function graphMismatch(sentence) {
|
|
280
|
+
return new InternalError(foreignGraph, {
|
|
281
|
+
cause: undefined,
|
|
282
|
+
correction: foreignGraphCorrection,
|
|
283
|
+
sentence,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
226
286
|
/**
|
|
227
287
|
* The routed node inside the inspected graph, which routing already proved reachable. A missing
|
|
228
288
|
* segment means the two readings of one graph disagree, so the run stops rather than hand a
|
|
@@ -233,10 +293,10 @@ function nodeAt(graph, path) {
|
|
|
233
293
|
for (const name of path) {
|
|
234
294
|
const child = node.children.find((entry) => entry.name === name);
|
|
235
295
|
if (!child) {
|
|
236
|
-
throw
|
|
296
|
+
throw graphMismatch(`The routed command "${path.join(' ')}" is not in the inspected graph.`);
|
|
237
297
|
}
|
|
238
298
|
node = child;
|
|
239
299
|
}
|
|
240
300
|
return node;
|
|
241
301
|
}
|
|
242
|
-
export { inspectGraph, linkOf, nodeAt, resultNode };
|
|
302
|
+
export { graphMismatch, inspectGraph, linkOf, nodeAt, resultNode };
|
package/dist/lanes.js
CHANGED
|
@@ -2,7 +2,7 @@ import { routedSubject } from './errors.js';
|
|
|
2
2
|
import { glyph } from './glyphs.generated.js';
|
|
3
3
|
import { view } from './view.js';
|
|
4
4
|
/**
|
|
5
|
-
* The identity prefix core's own views take, the package name by the plugin
|
|
5
|
+
* The identity prefix core's own views take, the package name by the plugin identity convention.
|
|
6
6
|
* Core compiles from `src` alone, so the name is spelled here rather than read from the manifest.
|
|
7
7
|
*/
|
|
8
8
|
const core = '@loomcli/core';
|
package/dist/locate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { argumentSlot, readsAsChild, route } from './command.js';
|
|
2
|
-
import {
|
|
3
|
-
import { linkOf } from './inspect.js';
|
|
2
|
+
import { UsageError } from './errors.js';
|
|
3
|
+
import { graphMismatch, linkOf } from './inspect.js';
|
|
4
4
|
import { isOptionToken, longStringOption, longToken, scanGlobals, scanInputs } from './options.js';
|
|
5
5
|
const none = Object.freeze({ kind: 'none' });
|
|
6
6
|
/**
|
|
@@ -57,7 +57,7 @@ function valueOf(scope, name, word) {
|
|
|
57
57
|
const option = graph.globals.find((entry) => entry.name === name) ??
|
|
58
58
|
command.options.find((entry) => entry.name === name);
|
|
59
59
|
if (!option) {
|
|
60
|
-
throw
|
|
60
|
+
throw graphMismatch(`Option "${name}" is not in the inspected graph.`);
|
|
61
61
|
}
|
|
62
62
|
return { command, kind: 'value', lead: word.lead, option, prefix: word.prefix };
|
|
63
63
|
}
|
|
@@ -114,7 +114,7 @@ function locate(graph, words) {
|
|
|
114
114
|
}
|
|
115
115
|
const command = link.nodes.get(earlier.command);
|
|
116
116
|
if (!command) {
|
|
117
|
-
throw
|
|
117
|
+
throw graphMismatch('The routed command is not in the inspected graph.');
|
|
118
118
|
}
|
|
119
119
|
return lastWord({ built: link.graph, command, earlier, graph }, words.at(-1) ?? '');
|
|
120
120
|
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InputSite } from './facts.js';
|
|
1
2
|
import type { OptionConfig } from './types.js';
|
|
2
3
|
export interface OptionDeclaration {
|
|
3
4
|
name: string;
|
|
@@ -13,7 +14,7 @@ export interface OptionValues {
|
|
|
13
14
|
/** Every parsed value lands in one of these maps; `lists` holds the repeated string options. */
|
|
14
15
|
export declare function emptyValues(): OptionValues;
|
|
15
16
|
/** Which accepted form a table entry is. The table owns the convention, so readers never re-derive it. */
|
|
16
|
-
type SpellingRole = 'long' | 'negative' | 'short';
|
|
17
|
+
export type SpellingRole = 'long' | 'negative' | 'short';
|
|
17
18
|
type OptionForm = {
|
|
18
19
|
type: 'string';
|
|
19
20
|
name: string;
|
|
@@ -26,6 +27,22 @@ type OptionForm = {
|
|
|
26
27
|
type OptionSpelling = OptionForm & {
|
|
27
28
|
role: SpellingRole;
|
|
28
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* The part of one declaration that yields a spelling of the given role, which a spelling fault
|
|
32
|
+
* marks: the declared name for the long form, `short` for the short alias, and the `polarity` that
|
|
33
|
+
* generates a negative form.
|
|
34
|
+
*/
|
|
35
|
+
export declare function spellingMark(site: InputSite, role: SpellingRole): string;
|
|
36
|
+
/** The declared name answers the declared-name rule an argument's name answers. */
|
|
37
|
+
export declare function checkOptionName(name: unknown, site: InputSite): void;
|
|
38
|
+
/**
|
|
39
|
+
* The scope one table compiles: the phrase a repeated name names it by, and where each of its
|
|
40
|
+
* options was declared, which every fault's findings rebuild.
|
|
41
|
+
*/
|
|
42
|
+
export interface CompileScope<Declaration extends OptionDeclaration> {
|
|
43
|
+
readonly subject: string;
|
|
44
|
+
readonly siteOf: (declaration: Declaration) => InputSite;
|
|
45
|
+
}
|
|
29
46
|
/**
|
|
30
47
|
* One Boolean option's value for one invocation: the value the parser consumed, or the value its
|
|
31
48
|
* declared polarity gives an absent option. A negative-only option is absent as `true`, because its
|
|
@@ -33,7 +50,11 @@ type OptionSpelling = OptionForm & {
|
|
|
33
50
|
* declaration answer the same rule.
|
|
34
51
|
*/
|
|
35
52
|
export declare function booleanValue(values: OptionValues, name: string, config: OptionConfig): boolean;
|
|
36
|
-
|
|
53
|
+
/**
|
|
54
|
+
* One scope's options compiled into the spelling table the parser reads, with every rule one
|
|
55
|
+
* declaration answers alone and every rule two of them answer together.
|
|
56
|
+
*/
|
|
57
|
+
export declare function compileOptions<Declaration extends OptionDeclaration>(declarations: readonly Declaration[], scope: CompileScope<Declaration>): Map<string, OptionSpelling>;
|
|
37
58
|
/**
|
|
38
59
|
* Whether a token reads as an option: it starts with a hyphen. Routing stops at one, and a
|
|
39
60
|
* separate value is never one. The parser and `locate` read each token through this rule.
|