@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.
Files changed (77) hide show
  1. package/dist/application.d.ts +18 -2
  2. package/dist/application.js +266 -71
  3. package/dist/bindings.d.ts +15 -10
  4. package/dist/bindings.js +34 -15
  5. package/dist/chain.d.ts +15 -6
  6. package/dist/chain.js +40 -20
  7. package/dist/command-rules.d.ts +55 -0
  8. package/dist/command-rules.js +142 -0
  9. package/dist/command.d.ts +65 -23
  10. package/dist/command.js +695 -226
  11. package/dist/controls.d.ts +8 -0
  12. package/dist/controls.js +23 -0
  13. package/dist/defect.d.ts +18 -0
  14. package/dist/defect.js +272 -0
  15. package/dist/developer.d.ts +24 -0
  16. package/dist/developer.js +52 -0
  17. package/dist/diagnostic-text.d.ts +81 -0
  18. package/dist/diagnostic-text.js +283 -0
  19. package/dist/diagnostic.d.ts +11 -0
  20. package/dist/diagnostic.js +70 -0
  21. package/dist/errors.d.ts +108 -24
  22. package/dist/errors.js +324 -53
  23. package/dist/exit-codes.d.ts +45 -0
  24. package/dist/exit-codes.js +46 -0
  25. package/dist/extension.d.ts +41 -8
  26. package/dist/extension.js +142 -57
  27. package/dist/facts.d.ts +66 -11
  28. package/dist/facts.js +98 -22
  29. package/dist/globals.d.ts +29 -21
  30. package/dist/globals.js +115 -46
  31. package/dist/hints.d.ts +79 -0
  32. package/dist/hints.js +247 -0
  33. package/dist/host.d.ts +13 -0
  34. package/dist/host.js +43 -1
  35. package/dist/identity.d.ts +19 -0
  36. package/dist/identity.js +72 -0
  37. package/dist/index.d.ts +11 -2
  38. package/dist/index.js +5 -0
  39. package/dist/input-rules.d.ts +64 -0
  40. package/dist/input-rules.js +145 -0
  41. package/dist/inspect.d.ts +12 -4
  42. package/dist/inspect.js +88 -28
  43. package/dist/lanes.js +1 -1
  44. package/dist/locate.js +4 -4
  45. package/dist/options.d.ts +23 -2
  46. package/dist/options.js +135 -44
  47. package/dist/output.d.ts +9 -2
  48. package/dist/output.js +18 -2
  49. package/dist/plain.d.ts +6 -0
  50. package/dist/plain.js +12 -0
  51. package/dist/plugin-rules.d.ts +62 -0
  52. package/dist/plugin-rules.js +155 -0
  53. package/dist/plugin.d.ts +22 -10
  54. package/dist/plugin.js +348 -116
  55. package/dist/prototypes.d.ts +7 -0
  56. package/dist/prototypes.js +29 -0
  57. package/dist/rendering.d.ts +6 -1
  58. package/dist/rendering.js +23 -5
  59. package/dist/rules.d.ts +51 -0
  60. package/dist/rules.js +115 -0
  61. package/dist/sequence.js +6 -1
  62. package/dist/sources.d.ts +6 -4
  63. package/dist/sources.js +22 -13
  64. package/dist/style-wire.js +1 -1
  65. package/dist/style.js +1 -1
  66. package/dist/theme.d.ts +4 -0
  67. package/dist/theme.js +25 -5
  68. package/dist/thenable.d.ts +15 -0
  69. package/dist/thenable.js +29 -0
  70. package/dist/translators.d.ts +69 -0
  71. package/dist/translators.js +253 -0
  72. package/dist/types.d.ts +11 -1
  73. package/dist/validation.d.ts +44 -3
  74. package/dist/validation.js +156 -57
  75. package/dist/view.d.ts +48 -14
  76. package/dist/view.js +155 -77
  77. package/package.json +1 -1
package/dist/command.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import type { Finding } from './diagnostic-text.js';
1
2
  import type { RegisteredGlobals } from './environment.js';
2
- import type { AnyExtension, DescriptorRegistry, ExtensionRecords, ExtensionStore, ExtensionSubject, ExtensionValue } from './extension.js';
3
+ import type { LoomError } from './errors.js';
4
+ import type { AdmittedDescriptor, DescriptorRegistry, ExtensionRecords, ExtensionStore, ExtensionSubject, ExtensionValue } from './extension.js';
3
5
  import type { BuiltGlobals, GlobalsState, GlobalTable, InputRecords } from './globals.js';
4
6
  import type { CommandGraph, CommandNode } from './inspect.js';
5
7
  import { compileOptions } from './options.js';
@@ -7,7 +9,7 @@ import type { OptionValues } from './options.js';
7
9
  import type { BuiltPlugin } from './plugin.js';
8
10
  import type { ContextualStyle } from './style.js';
9
11
  import type { Action, ActionChannel, ArgumentConfig, ArgumentValue, declaredTypes, DeclaredResult, DeclaredTypes, DefaultConstraint, GlobalNameConstraint, Host, PerValueConstraint, NameConstraint, OpenResult, OptionConfig, OptionValue, Out, Request, ResultBinding, ResultViews, ResultViewsOf, RowViews, ValidateOmittedConstraint } from './types.js';
10
- import type { ArgumentInput, DefaultValues, InputDeclaration, OptionInput, ValidatedInputs } from './validation.js';
12
+ import type { ArgumentInput, DefaultValues, InputPlaces, InputDeclaration, OptionInput, ValidatedInputs } from './validation.js';
11
13
  /** One positional slot: the declaration it fills and whether it takes the remaining tokens. */
12
14
  export interface ArgumentSlot {
13
15
  input: InputDeclaration;
@@ -88,10 +90,14 @@ export interface CommandNodeHandle {
88
90
  readonly name: string;
89
91
  build(context: BuildContext): BuiltCommand;
90
92
  }
91
- /** One attached child, under the canonical name its parent's namespace holds it by. */
93
+ /**
94
+ * One attached child, under the canonical name its parent's namespace holds it by, with the call
95
+ * that attached it, which a diagnostic about the child as a whole marks.
96
+ */
92
97
  export interface AttachedChild {
93
98
  readonly name: string;
94
99
  readonly node: CommandNodeHandle;
100
+ readonly placement: Finding;
95
101
  }
96
102
  /**
97
103
  * One graph build's shared state. `globals` compiles once and every Command reads it. The build is
@@ -108,6 +114,12 @@ interface BuildContext {
108
114
  }
109
115
  /** The handle behind a value an author built as a Command, or nothing for any other value. */
110
116
  export declare function commandNode(value: unknown): CommandNodeHandle | undefined;
117
+ /** A call's arguments as its author wrote them: the trailing ones left undefined are dropped. */
118
+ export declare function callArguments(...values: readonly unknown[]): readonly unknown[];
119
+ /** A Command value as a finding prints it, which it would otherwise print as an ellipsis. */
120
+ export declare function commandCode(name: string): object;
121
+ /** The finding for one `command()` call that attached a child under the Command at `path`. */
122
+ export declare function commandPlacement(path: readonly string[], child: string): Finding;
111
123
  /**
112
124
  * The portable name rule, for every name an operator types as a command at a shell prompt: the
113
125
  * application name, every Command name, and every alias. The characters are the POSIX portable
@@ -118,17 +130,20 @@ export declare function isPortableName(name: unknown): name is string;
118
130
  /** The one correction every portable name diagnostic ends with. */
119
131
  export declare const portableNameCorrection = "Use a nonempty name of A-Z, a-z, 0-9, \".\", \"_\", and \"-\" that does not start with \"-\" or \".\".";
120
132
  /**
121
- * One call of the results lane, in the order it was made. A `result()` or `rows()` call declares
122
- * the unit, and a `views()` call reshapes the views of whichever declaration it follows.
133
+ * One call of the results lane, in the order it was made, with the arguments a finding rebuilds it
134
+ * from. A `result()` or `rows()` call declares the unit, and a `views()` call reshapes the views of
135
+ * whichever declaration it follows.
123
136
  */
124
137
  export type ResultCall = {
138
+ arguments: readonly unknown[];
139
+ } & ({
125
140
  kind: 'value' | 'rows';
126
141
  views: unknown;
127
142
  } | {
128
143
  default: unknown;
129
144
  kind: 'views';
130
145
  views: unknown;
131
- };
146
+ });
132
147
  /** The core facts a named Command declares, which its constructor checked. The root carries none. */
133
148
  export interface CommandFacts {
134
149
  deprecated: string | undefined;
@@ -157,7 +172,7 @@ export interface CommandState<Args, Options, Globals> {
157
172
  * Every descriptor this declaration's extension values name, by identity. The root's holds the
158
173
  * whole Application's: its plugins', its global options', and every attached subtree's.
159
174
  */
160
- descriptors: ReadonlyMap<string, AnyExtension>;
175
+ descriptors: ReadonlyMap<string, AdmittedDescriptor>;
161
176
  /** The extension values of every layer, validated at the call that carried each one. */
162
177
  extensions: ExtensionStore;
163
178
  facts: CommandFacts;
@@ -176,19 +191,19 @@ export declare function layerOf(name: string | null): ExtensionSubject;
176
191
  * declaration values arrive checked, because the constructor that read them threw for any fault.
177
192
  */
178
193
  export declare function freshState<Globals>(declaration: {
179
- descriptors: ReadonlyMap<string, AnyExtension>;
194
+ descriptors: ReadonlyMap<string, AdmittedDescriptor>;
180
195
  extensions: ExtensionStore;
181
196
  facts: CommandFacts;
182
197
  name: string | null;
183
198
  }): CommandState<{}, {}, Globals>;
184
199
  /** The declared value joins `args` under its literal name, typed by its own config. */
185
- export declare function declareArgument<Args, Options, Globals, Name extends string, Config extends ArgumentConfig>(state: CommandState<Args, Options, Globals>, input: ArgumentInput<Name, Config>): CommandState<Args & Record<Name, ArgumentValue<Config>>, Options, Globals>;
200
+ export declare function declareArgument<Args, Options, Globals, Name extends string, Config extends ArgumentConfig>(state: CommandState<Args, Options, Globals>, declared: ArgumentInput<Name, Config>): CommandState<Args & Record<Name, ArgumentValue<Config>>, Options, Globals>;
186
201
  /**
187
202
  * The declared value joins `options` under its literal name, typed by its own config. The root's
188
203
  * options also meet the Application's globals table, which a named Command meets when its subtree
189
204
  * joins an Application.
190
205
  */
191
- export declare function declareOption<Args, Options, Globals, Name extends string, Config extends OptionConfig>(state: CommandState<Args, Options, Globals>, input: OptionInput<Name, Config>, table?: GlobalTable): CommandState<Args, Options & Record<Name, OptionValue<Config>>, Globals>;
206
+ export declare function declareOption<Args, Options, Globals, Name extends string, Config extends OptionConfig>(state: CommandState<Args, Options, Globals>, declared: OptionInput<Name, Config>, table?: GlobalTable): CommandState<Args, Options & Record<Name, OptionValue<Config>>, Globals>;
192
207
  /**
193
208
  * One call's names join the Command's aliases. A call that names none, which the types reject and
194
209
  * a JavaScript author can still write, reports as the call it is.
@@ -211,35 +226,48 @@ export declare function declareAction<Args, Options, Globals, Result>(state: Com
211
226
  export declare function declareResult<Args, Options, Globals>(state: CommandState<Args, Options, Globals>, kind: 'value' | 'rows', declaration: unknown): CommandState<Args, Options, Globals>;
212
227
  /** A `views()` call reshapes views and closes nothing, so it is never a late declaration. */
213
228
  export declare function declareResultViews<Args, Options, Globals>(state: CommandState<Args, Options, Globals>, replacements: unknown, options: unknown): CommandState<Args, Options, Globals>;
214
- /** The parent one attach reads: its name, the children it holds, and the calls that close it. */
215
- interface AttachParent {
229
+ /** One Command a rule judges: the name its sentence reads, and the path its findings open with. */
230
+ interface CommandPlace {
231
+ name: string | null;
232
+ path: readonly string[];
233
+ }
234
+ /** The parent one attach reads: its place, the children it holds, and the calls that close it. */
235
+ interface AttachParent extends CommandPlace {
216
236
  /** The first argument the parent declares, which no child may sit beside. */
217
- argument: string | undefined;
237
+ argument: InputDeclaration | undefined;
218
238
  children: readonly AttachedChild[];
219
239
  hasAction: boolean;
220
- name: string | null;
221
240
  }
222
241
  /**
223
242
  * The one attach operation `Command.command()`, `Application.command()`, and a plugin's
224
243
  * `commands` list share. A Command is an immutable value, so the child is final here: it is checked
225
244
  * as a finished Command, against the parent's current children, and against the nesting cap from
226
- * the shallowest level the parent can sit at.
245
+ * the shallowest level the parent can sit at. The placement is the call that attached it, which a
246
+ * finding about the child as a whole marks.
227
247
  */
228
- export declare function attach(parent: AttachParent, node: CommandNodeHandle): AttachedChild;
248
+ export declare function attach(parent: AttachParent, node: CommandNodeHandle, placement: Finding): AttachedChild;
229
249
  /** The handle behind the value one `command()` call received; anything else is a declaration error. */
230
250
  export declare function childNode(parent: string | null, child: unknown): CommandNodeHandle;
251
+ /** The first place an Application holds one Command value: its parent's name and the attach call. */
252
+ export interface ChildOwner {
253
+ name: string | null;
254
+ placement: Finding;
255
+ }
231
256
  /** What an Application holds while a subtree joins it, each register a copy the caller commits. */
232
257
  interface JoinScope {
233
258
  descriptors: DescriptorRegistry;
234
- /** The parent that claimed each node the Application holds, by the name a diagnostic reads. */
235
- owners: Map<CommandNodeHandle, string | null>;
259
+ /** The first place that claimed each node the Application holds. */
260
+ owners: Map<CommandNodeHandle, ChildOwner>;
236
261
  table: GlobalTable;
237
262
  }
238
263
  /**
239
264
  * Attaches one child to an Application's root and walks the subtree it brings, once. The scope's
240
265
  * registers are copies: the caller commits the owners, and the returned root holds the descriptors.
241
266
  */
242
- export declare function attachToRoot<Args, Options, Globals>(state: CommandState<Args, Options, Globals>, node: CommandNodeHandle, scope: JoinScope): CommandState<Args, Options, Globals>;
267
+ export declare function attachToRoot<Args, Options, Globals>(state: CommandState<Args, Options, Globals>, child: {
268
+ node: CommandNodeHandle;
269
+ placement: Finding;
270
+ }, scope: JoinScope): CommandState<Args, Options, Globals>;
243
271
  /**
244
272
  * A declaration's own options and every attached Command's, against a globals table that has just
245
273
  * grown. The table's new option reads as the other side of any collision.
@@ -340,13 +368,22 @@ type CommandConstructor = new (name: string, options?: CommandOptions) => Comman
340
368
  export declare const Command: CommandConstructor;
341
369
  /** Every declaration in the graph, so defaults are validated before any token is read. */
342
370
  export declare function collectInputs(command: BuiltCommand): InputDeclaration[];
371
+ /**
372
+ * Where every input of one graph was declared: each global option at its `globalOption()` call,
373
+ * and each Command's own inputs at their calls on the Command, under its path from the root.
374
+ */
375
+ export declare function inputPlaces(graph: BuiltGraph): InputPlaces;
343
376
  /**
344
377
  * Whether a token names one of the Command's children: the Command has children and the token is
345
378
  * no option token. Routing and `locate` read a bare word through this rule.
346
379
  */
347
380
  export declare function readsAsChild(command: BuiltCommand, token: string): boolean;
348
- /** Bare tokens, names or aliases, select children until a Command has none; a hyphen commits. */
349
- export declare function route(root: BuiltCommand, tokens: readonly string[]): {
381
+ /**
382
+ * Bare tokens, names or aliases, select children until a Command has none; a hyphen commits.
383
+ * `walked` receives the path after each name routes, so an unknown Command leaves its caller
384
+ * holding the partial path walked before it.
385
+ */
386
+ export declare function route(root: BuiltCommand, tokens: readonly string[], walked?: (path: readonly string[]) => void): {
350
387
  command: BuiltCommand;
351
388
  path: string[];
352
389
  tokens: string[];
@@ -363,8 +400,11 @@ export interface RoutedInvocation {
363
400
  scan: OptionValues;
364
401
  tokens: readonly string[];
365
402
  }
366
- /** Consumes the globals table, then routes the remaining bare tokens to a Command. */
367
- export declare function routeInvocation(graph: BuiltGraph, argv: readonly string[]): RoutedInvocation;
403
+ /**
404
+ * Consumes the globals table, then routes the remaining bare tokens to a Command. `walked`
405
+ * receives the path as routing extends it, the partial path of an unknown Command included.
406
+ */
407
+ export declare function routeInvocation(graph: BuiltGraph, argv: readonly string[], walked: (path: readonly string[]) => void): RoutedInvocation;
368
408
  /** What one invocation reaches the middleware chain with. */
369
409
  export interface DispatchInvocation {
370
410
  /** The channel the action receives, which the results lane builds from the routed node. */
@@ -373,6 +413,8 @@ export interface DispatchInvocation {
373
413
  host: Host;
374
414
  /** The graph `inspect()` returns for the run, built on its first read, which a source reads. */
375
415
  inspected: () => CommandGraph;
416
+ /** Offers a configuration source's foreign throw to the translators where its call settles. */
417
+ offer: (thrown: unknown) => LoomError | undefined;
376
418
  signal: AbortSignal;
377
419
  /** The channel a configuration source writes through, whose results call names the source. */
378
420
  sourceOut: Out<OpenResult>;