@loomcli/core 0.6.0 → 0.8.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.
Files changed (52) hide show
  1. package/NOTICE +34 -0
  2. package/dist/application.d.ts +11 -6
  3. package/dist/application.js +57 -19
  4. package/dist/capture.d.ts +65 -0
  5. package/dist/capture.js +99 -0
  6. package/dist/chain.d.ts +28 -17
  7. package/dist/chain.js +11 -10
  8. package/dist/command-rules.d.ts +1 -1
  9. package/dist/command-rules.js +2 -2
  10. package/dist/command.d.ts +31 -47
  11. package/dist/command.js +204 -209
  12. package/dist/errors.d.ts +22 -21
  13. package/dist/errors.js +38 -18
  14. package/dist/facts.d.ts +5 -0
  15. package/dist/facts.js +8 -1
  16. package/dist/globals.d.ts +48 -22
  17. package/dist/globals.js +72 -29
  18. package/dist/glyphs.generated.js +1 -1
  19. package/dist/index.d.ts +5 -3
  20. package/dist/index.js +3 -1
  21. package/dist/input-rules.d.ts +20 -2
  22. package/dist/input-rules.js +47 -5
  23. package/dist/inspect.d.ts +33 -17
  24. package/dist/inspect.js +74 -87
  25. package/dist/locate.js +52 -60
  26. package/dist/options.d.ts +101 -83
  27. package/dist/options.js +311 -267
  28. package/dist/parse.d.ts +162 -0
  29. package/dist/parse.js +601 -0
  30. package/dist/plain.d.ts +52 -2
  31. package/dist/plain.js +228 -2
  32. package/dist/plugin-rules.d.ts +8 -4
  33. package/dist/plugin-rules.js +13 -9
  34. package/dist/plugin-settings.d.ts +18 -0
  35. package/dist/plugin-settings.js +38 -0
  36. package/dist/plugin.d.ts +32 -27
  37. package/dist/plugin.js +107 -89
  38. package/dist/sources.d.ts +18 -9
  39. package/dist/sources.js +50 -20
  40. package/dist/style-layout.js +2 -2
  41. package/dist/style-width.d.ts +13 -0
  42. package/dist/style-width.js +170 -0
  43. package/dist/types.d.ts +70 -30
  44. package/dist/unicode.generated.d.ts +27 -0
  45. package/dist/unicode.generated.js +1036 -0
  46. package/dist/validation.d.ts +108 -34
  47. package/dist/validation.js +282 -125
  48. package/dist/view.d.ts +16 -11
  49. package/dist/view.js +13 -4
  50. package/licenses/unicode-LICENSE.txt +41 -0
  51. package/licenses/uucode-LICENSE.md +35 -0
  52. package/package.json +9 -5
@@ -1,7 +1,10 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { CaptureFaults } from './capture.js';
2
3
  import type { Finding } from './diagnostic-text.js';
4
+ import { DeclarationError, InputError } from './errors.js';
5
+ import type { InputProblem } from './errors.js';
3
6
  import type { InputSite } from './facts.js';
4
- import type { OptionValues } from './options.js';
7
+ import type { OptionValues, SpellingTable } from './options.js';
5
8
  import type { ArgumentConfig, ArgumentValue, Host, OptionConfig, OptionValue } from './types.js';
6
9
  /**
7
10
  * One declared input, typed by its literal name and its own config. The value type is derived from
@@ -19,8 +22,14 @@ export interface OptionInput<Name extends string = string, Config extends Option
19
22
  readonly config: Config;
20
23
  }
21
24
  export type InputDeclaration<Name extends string = string> = ArgumentInput<Name> | OptionInput<Name>;
22
- /** Validated defaults, read before any token is parsed. Values stay `unknown` here. */
23
- export type DefaultValues = ReadonlyMap<InputDeclaration, unknown>;
25
+ /**
26
+ * The declared values validated before any token is parsed: each default, and each implied value a
27
+ * bare spelling supplies. Values stay `unknown` here.
28
+ */
29
+ export interface DeclaredValues {
30
+ readonly defaults: ReadonlyMap<InputDeclaration, unknown>;
31
+ readonly implied: ReadonlyMap<InputDeclaration, unknown>;
32
+ }
24
33
  /** The declarations one pass reads, by the scope that holds them: the graph's, then a Command's. */
25
34
  export interface ScopedInputs {
26
35
  globals: readonly InputDeclaration[];
@@ -28,11 +37,15 @@ export interface ScopedInputs {
28
37
  }
29
38
  /**
30
39
  * What the input-source stage leaves for validation's messages, by option name: the label of each
31
- * value it filled, and the variable of each Boolean option whose value is outside the grammar.
40
+ * value it filled, and the variable of each Boolean or counted option whose value is outside its
41
+ * grammar. `unanswered` holds each option a configuration source would have filled had one of its own
42
+ * options not been rejected; such an option reports no missing value and no absence rule judges it,
43
+ * because the operator's configuration may hold it.
32
44
  */
33
- interface Provenance {
45
+ export interface Provenance {
34
46
  labels: ReadonlyMap<string, string>;
35
47
  rejected: ReadonlyMap<string, string>;
48
+ unanswered?: ReadonlySet<InputDeclaration>;
36
49
  }
37
50
  /** The raw tokens one invocation collected, keyed by declaration and by option name. */
38
51
  interface SuppliedValues {
@@ -42,19 +55,31 @@ interface SuppliedValues {
42
55
  /** Everything one invocation validates: its declarations, its tokens, and where they were read. */
43
56
  export interface Invocation {
44
57
  command: readonly string[];
45
- defaults: DefaultValues;
58
+ /** Every declared default and implied value, validated before any token was read. */
59
+ declaredValues: DeclaredValues;
46
60
  host: Host;
47
61
  inputs: ScopedInputs;
48
62
  passthrough: readonly string[];
49
63
  /**
50
- * The plugin options, which are never validated. A Boolean one whose variable is outside the
51
- * grammar is still a problem of this phase, reported after the globals and before the locals.
64
+ * The declarations this pass validates, when it validates only some of `inputs`, such as a
65
+ * configuration source's own options ahead of its call. Every declaration of `inputs` still
66
+ * appears in the validation context's `supplied` record.
52
67
  */
53
- plugins: readonly OptionInput[];
68
+ only?: ReadonlySet<InputDeclaration>;
69
+ /** Where each declaration was declared, which a broken validator's finding rebuilds. */
70
+ places: InputPlaces;
71
+ /**
72
+ * An earlier pass of this invocation, such as the one over a configuration source's own options.
73
+ * This pass reads each value it accepted and each problem it reported, in this pass's own order,
74
+ * and never sends those values to their validators a second time.
75
+ */
76
+ prior?: Validation;
54
77
  /** The run's cancellation signal, which stops this phase between two validator calls. */
55
78
  signal: AbortSignal;
56
79
  sources: Provenance;
57
80
  supplied: SuppliedValues;
81
+ /** The routed Command's spelling table, which names each option the way a problem reports it. */
82
+ table: SpellingTable;
58
83
  }
59
84
  /**
60
85
  * The validated values of one invocation, keyed by declaration. Only `validateValues` constructs
@@ -73,24 +98,40 @@ declare class ValidatedInputs {
73
98
  * middleware's request receives. The declared types stay with the two readers above.
74
99
  */
75
100
  read(input: InputDeclaration): unknown;
101
+ /** Whether this pass validated the declaration's value. */
102
+ has(input: InputDeclaration): boolean;
76
103
  }
77
104
  export type { ValidatedInputs };
105
+ /** The faults a config's capture raises: those of every capture, and a default nested too deep. */
106
+ export interface ConfigFaults extends CaptureFaults {
107
+ /** The default holds a path deeper than `defaultLevels`; the finding prints it elided. */
108
+ readonly tooDeep: () => DeclarationError;
109
+ }
78
110
  /**
79
- * The one check every `argument()`, `option()`, and `globalOption()` call makes before it reads its
80
- * config, so a call in JavaScript that supplies none, or a value of another kind, reports a
81
- * declaration fault and not a TypeError. `place` is where the call sits.
111
+ * Authoring's one read of a config, through `captureDeclaration`: the prototype verdict, the copy of
112
+ * every own string key, the copies of its `extensions` and `aliases` lists, and the snapshot of its
113
+ * default, inside one try. Every later check, the registry entry, and every sentence read the copy
114
+ * and never the author's object again, so a getter runs once and the caller's later changes reach
115
+ * nothing. The default is copied and frozen to `defaultLevels` levels, cycles included, and that
116
+ * copy is the value the graph publishes and a run validates; every other property is captured as
117
+ * declared, because core clones no library object. A read that throws, from a getter or a proxy
118
+ * trap, is the unreadable fault, named by the key it threw in, a default nested deeper is the
119
+ * too-deep fault, and a value that is not a plain object is the not-an-object fault.
82
120
  */
83
- export declare function checkInputConfig(declared: {
84
- readonly config: unknown;
85
- readonly kind: InputDeclaration['kind'];
86
- readonly name: string;
87
- }, place: InputPlace): void;
121
+ export declare function captureConfig<Config extends ArgumentConfig | OptionConfig>(config: Config, faults: ConfigFaults): Config;
122
+ /** The fault of a default nested deeper than `defaultLevels`, declared by `subject`. */
123
+ export declare function defaultDepthFault(subject: string, findings: readonly Finding[]): DeclarationError;
88
124
  /**
89
- * Authoring's snapshot of one config. An array default is the one declared value core hands to an
90
- * action as its own value, so the declaration keeps a copy and the caller keeps its array. Every
91
- * other property is captured as declared, because core clones no library object.
125
+ * The config every `argument()`, `option()`, and `globalOption()` call, and every input a lifecycle
126
+ * hook declares, reads through `captureConfig`. A call in JavaScript that supplies none, or a value
127
+ * of another kind, reports a declaration fault and not a TypeError, and so does a config whose read
128
+ * throws. Each fault marks the config on the call at `place`.
92
129
  */
93
- export declare function captureConfig<Config extends ArgumentConfig | OptionConfig>(config: Config): Config;
130
+ export declare function captureInputConfig<Config extends ArgumentConfig | OptionConfig>(declared: {
131
+ readonly config: Config;
132
+ readonly kind: InputDeclaration['kind'];
133
+ readonly name: string;
134
+ }, place: InputPlace): Config;
94
135
  /**
95
136
  * A declaration error names the declaration, because the author reads the declaration to fix it.
96
137
  * An argument declares and reads under one name, so the two namings differ for options alone.
@@ -99,19 +140,21 @@ export declare function declarationSubject(input: InputDeclaration): string;
99
140
  /** Where the call that declared one input sits: the call's name and the Command it is on. */
100
141
  export type InputPlace = Pick<Finding, 'call' | 'path'>;
101
142
  /**
102
- * Where one input was declared: a global option at its `globalOption()` call, and every other input
103
- * at its own `argument()` or `option()` call on the Command at `path`.
143
+ * Where one Command's own input was declared: its `argument()` or `option()` call on the Command at
144
+ * `path`. A global option's site is the built table's, under `BuiltGlobals.sites`.
104
145
  */
105
- export declare function inputPlace(input: InputDeclaration, scope: {
106
- readonly global: boolean;
107
- readonly path: readonly string[];
108
- }): InputPlace;
146
+ export declare function inputPlace(input: InputDeclaration, path: readonly string[]): InputPlace;
109
147
  /**
110
148
  * The site of the call that declared one input at `place`, rebuilt as `call(name, config)`. Every
111
149
  * finding for an input's own call starts from it, so each marks the call the same way. `subject`
112
150
  * is the sentence's name for the input.
113
151
  */
114
152
  export declare function declaringSite(input: InputDeclaration, place: InputPlace, subject?: string): InputSite;
153
+ /**
154
+ * One input's site with its config printed elided, for a fault judged before the config is read,
155
+ * such as an invalid name, so the fault reads none of the config.
156
+ */
157
+ export declare function configUnread(site: InputSite): InputSite;
115
158
  /**
116
159
  * The declaration flag that sends an omitted value to its own validator. Every declaration reads it
117
160
  * here, and the declaration rules below reject it wherever another rule already decides absence.
@@ -136,12 +179,43 @@ export interface SitedInput {
136
179
  * diagnostics read with; every other caller is named by the declaration itself.
137
180
  */
138
181
  export declare function checkDeclarations(inputs: readonly SitedInput[], named?: string): void;
139
- /** The call that declared one input and the Command it sits on, which a default's fault rebuilds. */
140
- export type InputPlaces = ReadonlyMap<InputDeclaration, InputPlace>;
141
182
  /**
142
- * Every declared default, validated before any token is read. The host is captured by then, so a
143
- * default's validator reads the same Host its action will, under the `default` phase. `places`
144
- * says where each declaration sits, which a rejected default's finding rebuilds.
183
+ * The site of the call that declared each input, which a fault about its default or its validator
184
+ * rebuilds: `globalOption()` or a plugin's `options` record for a global option, and the input's
185
+ * own call on its Command for every other input.
186
+ */
187
+ export type InputPlaces = ReadonlyMap<InputDeclaration, InputSite>;
188
+ /**
189
+ * Every declared default and implied value, validated before any token is read, in declaration
190
+ * order, a declaration's default before its implied value. The host is captured by then, so each
191
+ * validator reads the same Host its action will, under the `default` phase. `places` says where each
192
+ * declaration sits, which a rejected value's finding rebuilds. An implied value is judged whether or
193
+ * not an invocation holds a bare spelling, because the author declared it.
194
+ */
195
+ export declare function prepareDeclaredValues(inputs: ScopedInputs, host: Host, places: InputPlaces): Promise<DeclaredValues>;
196
+ /** One rejected or missing input: the problem it reports, and the lines core's default text holds. */
197
+ interface Report {
198
+ readonly lines: readonly string[];
199
+ readonly problem: InputProblem;
200
+ }
201
+ /**
202
+ * What one validation pass produced: every value its validator accepted, each input's report in
203
+ * reporting order, and those reports aggregated into one failure, or `undefined` when there were
204
+ * none. A pass that found problems still answers with the values it accepted, so a reader of the
205
+ * global options keeps them when only a local input was rejected.
206
+ */
207
+ export interface Validation {
208
+ readonly failure: InputError | undefined;
209
+ readonly reports: ReadonlyMap<InputDeclaration, Report>;
210
+ readonly values: ValidatedInputs;
211
+ }
212
+ /**
213
+ * Whether a pass rejected a global option, which leaves no global value a middleware may read. A
214
+ * global option declares no presence rule, so every problem it reports is a rejected value.
215
+ */
216
+ export declare function rejectsGlobal(validation: Validation): boolean;
217
+ /**
218
+ * Validates one invocation in reporting order: the global options, the application's and then each
219
+ * plugin's, and then the routed Command's own declarations, each in authoring order.
145
220
  */
146
- export declare function prepareInputs(inputs: ScopedInputs, host: Host, places: InputPlaces): Promise<DefaultValues>;
147
- export declare function validateValues(invocation: Invocation): Promise<ValidatedInputs>;
221
+ export declare function validateValues(invocation: Invocation): Promise<Validation>;