@optique/core 1.3.0-dev.2398 → 1.3.0-dev.2401

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.
@@ -7,6 +7,29 @@ import { ExecutionContext } from "./internal/parser.cjs";
7
7
 
8
8
  //#region src/dependency-runtime.d.ts
9
9
 
10
+ /**
11
+ * Stores the raw token parsed by a derived value parser on structural parser
12
+ * states that can safely carry an in-band annotation.
13
+ *
14
+ * The execution trace remains the canonical diagnostic record. This state
15
+ * marker lets construct-independent dependency resolution replay a derived
16
+ * source before downstream fields complete.
17
+ * @internal
18
+ * @since 1.3.0
19
+ */
20
+ declare const derivedRawInputKey: unique symbol;
21
+ /**
22
+ * Records a derived parser's raw token without modifying its parse result.
23
+ *
24
+ * Parse results may be frozen or carry class private state, so primitives keep
25
+ * their original identity and associate replay metadata out of band.
26
+ *
27
+ * @param state The original value parser result.
28
+ * @param rawInput The token parsed into that result.
29
+ * @internal
30
+ * @since 1.3.0
31
+ */
32
+ declare function recordDerivedRawInput(state: object, rawInput: string): void;
10
33
  /**
11
34
  * A request to resolve one or more dependency values.
12
35
  *
@@ -89,6 +112,8 @@ interface RuntimeNode {
89
112
  };
90
113
  /** The parser's current state. */
91
114
  readonly state: unknown;
115
+ /** Raw input captured for a derived parser, when this node matched. */
116
+ readonly rawInput?: string;
92
117
  /**
93
118
  * Whether the parser consumed explicit input during parsing.
94
119
  * When `true`, the parser's state reflects user-provided input (which
@@ -142,6 +167,20 @@ interface RuntimeNode {
142
167
  */
143
168
  readonly requiresSourceId?: symbol;
144
169
  }
170
+ /**
171
+ * Options for resolving matched derived source values.
172
+ *
173
+ * @internal
174
+ * @since 1.3.0
175
+ */
176
+ interface ResolveDerivedSourceValuesOptions {
177
+ /**
178
+ * Whether an unpopulated effectful source can still provide a value later.
179
+ * Suggestion generation sets this to `"inactive"` because it never runs
180
+ * effects and must let downstream parsers use declared dependency defaults.
181
+ */
182
+ readonly effectfulProviders?: "pending" | "inactive";
183
+ }
145
184
  /**
146
185
  * The context handed to a {@link RuntimeNode.prepare} barrier.
147
186
  *
@@ -190,6 +229,15 @@ interface DependencyRuntimeContext {
190
229
  * defaults for failed sources.
191
230
  */
192
231
  markSourceFailed(sourceId: symbol): void;
232
+ /** Register a source's diagnostic label and upstream dependencies. */
233
+ registerSourceMetadata(sourceId: symbol, label: string, dependencyIds?: readonly symbol[]): void;
234
+ /**
235
+ * Propagate a failed upstream source through one derived dependency edge.
236
+ * Returns whether any upstream source had failed.
237
+ */
238
+ propagateSourceFailure(dependencyIds: readonly symbol[], label: string, sourceId?: symbol): boolean;
239
+ /** Return the most informative dependency chain for a failed source. */
240
+ getSourceFailureChain(sourceId: symbol): readonly string[] | undefined;
193
241
  /**
194
242
  * Check if a source was explicitly attempted but failed validation.
195
243
  */
@@ -242,6 +290,36 @@ declare function collectExplicitSourceValues(nodes: readonly RuntimeNode[], runt
242
290
  * @since 1.0.0
243
291
  */
244
292
  declare function collectExplicitSourceValuesAsync(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext): Promise<void>;
293
+ /**
294
+ * Orders runtime nodes so every in-scope provider precedes a derived source
295
+ * that consumes it. Independent nodes retain declaration order.
296
+ *
297
+ * Missing providers create no edge because the consumer may use its declared
298
+ * default. Scheduling barriers act as providers for the source IDs their
299
+ * selected subtree may expose and depend on their discriminator source.
300
+ *
301
+ * @param nodes Runtime nodes in declaration order.
302
+ * @returns The same nodes in stable dependency order.
303
+ * @throws {TypeError} If active provider edges contain a cycle.
304
+ * @internal
305
+ * @since 1.3.0
306
+ */
307
+ declare function orderDependencyNodes(nodes: readonly RuntimeNode[]): readonly RuntimeNode[];
308
+ /** Resolves and publishes matched derived sources in stable dependency order. */
309
+ declare function resolveDerivedSourceValues(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext, options?: ResolveDerivedSourceValuesOptions): void;
310
+ /** Async version of {@link resolveDerivedSourceValues}. */
311
+ declare function resolveDerivedSourceValuesAsync(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext, options?: ResolveDerivedSourceValuesOptions): Promise<void>;
312
+ /**
313
+ * Appends the recorded dependency chain to a source failure.
314
+ *
315
+ * @param error The source failure to annotate.
316
+ * @param sourceId The identifier of the failed source.
317
+ * @param runtime The dependency runtime that recorded the failure chain.
318
+ * @returns The annotated failure, or the original failure when no chain exists.
319
+ * @internal
320
+ * @since 1.3.0
321
+ */
322
+ declare function includeSourceFailureChain(error: Message, sourceId: symbol, runtime: DependencyRuntimeContext): Message;
245
323
  /**
246
324
  * Fills missing source defaults for source parsers whose state is
247
325
  * unpopulated.
@@ -616,4 +694,4 @@ declare function buildRuntimeNodesFromArray(parsers: ReadonlyArray<{
616
694
  readonly initialState?: unknown;
617
695
  }>, stateArray: readonly unknown[], parentPath?: readonly PropertyKey[]): readonly RuntimeNode[];
618
696
  //#endregion
619
- export { CompleteEffectfulSourcesOptions, DependencyRequest, DependencyResolution, DependencyRuntimeContext, EffectfulSchedulingNodesFn, EffectfulSourceCompletion, EffectfulSourceCompletionResult, ReplayKey, RuntimeNode, SchedulingBarrierContext, SourceDefaultFailure, buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectDemandedDependencyIds, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, completeEffectfulSourcesAsync, createDependencyFingerprint, createDependencyRuntimeContext, createReplayKey, defineForwardedEffectfulSchedulingNodes, effectfulSchedulingNodesKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, replayDerivedParser, replayDerivedParserAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync, serializeSchedulingPath, sourceCollectionExpansionKey, staticSourceScopeKey };
697
+ export { CompleteEffectfulSourcesOptions, DependencyRequest, DependencyResolution, DependencyRuntimeContext, EffectfulSchedulingNodesFn, EffectfulSourceCompletion, EffectfulSourceCompletionResult, ReplayKey, ResolveDerivedSourceValuesOptions, RuntimeNode, SchedulingBarrierContext, SourceDefaultFailure, buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectDemandedDependencyIds, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, completeEffectfulSourcesAsync, createDependencyFingerprint, createDependencyRuntimeContext, createReplayKey, defineForwardedEffectfulSchedulingNodes, derivedRawInputKey, effectfulSchedulingNodesKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, includeSourceFailureChain, orderDependencyNodes, recordDerivedRawInput, replayDerivedParser, replayDerivedParserAsync, resolveDerivedSourceValues, resolveDerivedSourceValuesAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync, serializeSchedulingPath, sourceCollectionExpansionKey, staticSourceScopeKey };
@@ -7,6 +7,29 @@ import { ExecutionContext } from "./internal/parser.js";
7
7
 
8
8
  //#region src/dependency-runtime.d.ts
9
9
 
10
+ /**
11
+ * Stores the raw token parsed by a derived value parser on structural parser
12
+ * states that can safely carry an in-band annotation.
13
+ *
14
+ * The execution trace remains the canonical diagnostic record. This state
15
+ * marker lets construct-independent dependency resolution replay a derived
16
+ * source before downstream fields complete.
17
+ * @internal
18
+ * @since 1.3.0
19
+ */
20
+ declare const derivedRawInputKey: unique symbol;
21
+ /**
22
+ * Records a derived parser's raw token without modifying its parse result.
23
+ *
24
+ * Parse results may be frozen or carry class private state, so primitives keep
25
+ * their original identity and associate replay metadata out of band.
26
+ *
27
+ * @param state The original value parser result.
28
+ * @param rawInput The token parsed into that result.
29
+ * @internal
30
+ * @since 1.3.0
31
+ */
32
+ declare function recordDerivedRawInput(state: object, rawInput: string): void;
10
33
  /**
11
34
  * A request to resolve one or more dependency values.
12
35
  *
@@ -89,6 +112,8 @@ interface RuntimeNode {
89
112
  };
90
113
  /** The parser's current state. */
91
114
  readonly state: unknown;
115
+ /** Raw input captured for a derived parser, when this node matched. */
116
+ readonly rawInput?: string;
92
117
  /**
93
118
  * Whether the parser consumed explicit input during parsing.
94
119
  * When `true`, the parser's state reflects user-provided input (which
@@ -142,6 +167,20 @@ interface RuntimeNode {
142
167
  */
143
168
  readonly requiresSourceId?: symbol;
144
169
  }
170
+ /**
171
+ * Options for resolving matched derived source values.
172
+ *
173
+ * @internal
174
+ * @since 1.3.0
175
+ */
176
+ interface ResolveDerivedSourceValuesOptions {
177
+ /**
178
+ * Whether an unpopulated effectful source can still provide a value later.
179
+ * Suggestion generation sets this to `"inactive"` because it never runs
180
+ * effects and must let downstream parsers use declared dependency defaults.
181
+ */
182
+ readonly effectfulProviders?: "pending" | "inactive";
183
+ }
145
184
  /**
146
185
  * The context handed to a {@link RuntimeNode.prepare} barrier.
147
186
  *
@@ -190,6 +229,15 @@ interface DependencyRuntimeContext {
190
229
  * defaults for failed sources.
191
230
  */
192
231
  markSourceFailed(sourceId: symbol): void;
232
+ /** Register a source's diagnostic label and upstream dependencies. */
233
+ registerSourceMetadata(sourceId: symbol, label: string, dependencyIds?: readonly symbol[]): void;
234
+ /**
235
+ * Propagate a failed upstream source through one derived dependency edge.
236
+ * Returns whether any upstream source had failed.
237
+ */
238
+ propagateSourceFailure(dependencyIds: readonly symbol[], label: string, sourceId?: symbol): boolean;
239
+ /** Return the most informative dependency chain for a failed source. */
240
+ getSourceFailureChain(sourceId: symbol): readonly string[] | undefined;
193
241
  /**
194
242
  * Check if a source was explicitly attempted but failed validation.
195
243
  */
@@ -242,6 +290,36 @@ declare function collectExplicitSourceValues(nodes: readonly RuntimeNode[], runt
242
290
  * @since 1.0.0
243
291
  */
244
292
  declare function collectExplicitSourceValuesAsync(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext): Promise<void>;
293
+ /**
294
+ * Orders runtime nodes so every in-scope provider precedes a derived source
295
+ * that consumes it. Independent nodes retain declaration order.
296
+ *
297
+ * Missing providers create no edge because the consumer may use its declared
298
+ * default. Scheduling barriers act as providers for the source IDs their
299
+ * selected subtree may expose and depend on their discriminator source.
300
+ *
301
+ * @param nodes Runtime nodes in declaration order.
302
+ * @returns The same nodes in stable dependency order.
303
+ * @throws {TypeError} If active provider edges contain a cycle.
304
+ * @internal
305
+ * @since 1.3.0
306
+ */
307
+ declare function orderDependencyNodes(nodes: readonly RuntimeNode[]): readonly RuntimeNode[];
308
+ /** Resolves and publishes matched derived sources in stable dependency order. */
309
+ declare function resolveDerivedSourceValues(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext, options?: ResolveDerivedSourceValuesOptions): void;
310
+ /** Async version of {@link resolveDerivedSourceValues}. */
311
+ declare function resolveDerivedSourceValuesAsync(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext, options?: ResolveDerivedSourceValuesOptions): Promise<void>;
312
+ /**
313
+ * Appends the recorded dependency chain to a source failure.
314
+ *
315
+ * @param error The source failure to annotate.
316
+ * @param sourceId The identifier of the failed source.
317
+ * @param runtime The dependency runtime that recorded the failure chain.
318
+ * @returns The annotated failure, or the original failure when no chain exists.
319
+ * @internal
320
+ * @since 1.3.0
321
+ */
322
+ declare function includeSourceFailureChain(error: Message, sourceId: symbol, runtime: DependencyRuntimeContext): Message;
245
323
  /**
246
324
  * Fills missing source defaults for source parsers whose state is
247
325
  * unpopulated.
@@ -616,4 +694,4 @@ declare function buildRuntimeNodesFromArray(parsers: ReadonlyArray<{
616
694
  readonly initialState?: unknown;
617
695
  }>, stateArray: readonly unknown[], parentPath?: readonly PropertyKey[]): readonly RuntimeNode[];
618
696
  //#endregion
619
- export { CompleteEffectfulSourcesOptions, DependencyRequest, DependencyResolution, DependencyRuntimeContext, EffectfulSchedulingNodesFn, EffectfulSourceCompletion, EffectfulSourceCompletionResult, ReplayKey, RuntimeNode, SchedulingBarrierContext, SourceDefaultFailure, buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectDemandedDependencyIds, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, completeEffectfulSourcesAsync, createDependencyFingerprint, createDependencyRuntimeContext, createReplayKey, defineForwardedEffectfulSchedulingNodes, effectfulSchedulingNodesKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, replayDerivedParser, replayDerivedParserAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync, serializeSchedulingPath, sourceCollectionExpansionKey, staticSourceScopeKey };
697
+ export { CompleteEffectfulSourcesOptions, DependencyRequest, DependencyResolution, DependencyRuntimeContext, EffectfulSchedulingNodesFn, EffectfulSourceCompletion, EffectfulSourceCompletionResult, ReplayKey, ResolveDerivedSourceValuesOptions, RuntimeNode, SchedulingBarrierContext, SourceDefaultFailure, buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectDemandedDependencyIds, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, completeEffectfulSourcesAsync, createDependencyFingerprint, createDependencyRuntimeContext, createReplayKey, defineForwardedEffectfulSchedulingNodes, derivedRawInputKey, effectfulSchedulingNodesKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, includeSourceFailureChain, orderDependencyNodes, recordDerivedRawInput, replayDerivedParser, replayDerivedParserAsync, resolveDerivedSourceValues, resolveDerivedSourceValuesAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync, serializeSchedulingPath, sourceCollectionExpansionKey, staticSourceScopeKey };