@optique/core 1.3.0-dev.2441 → 1.3.0-dev.2444

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.
@@ -39,6 +39,13 @@ function withDependencyRuntimeExec(usage, exec, runtime) {
39
39
  dependencyRegistry: runtime.registry
40
40
  };
41
41
  }
42
+ function withoutRepublishInstruction(exec) {
43
+ if (exec?.republishCachedCompletions == null) return exec;
44
+ return {
45
+ ...exec,
46
+ republishCachedCompletions: void 0
47
+ };
48
+ }
42
49
  function withChildContext$1(context, segment, state, parser, usage) {
43
50
  const childState = parser == null ? state : require_annotation_state.getWrappedChildParseState(context.state, state, parser);
44
51
  return require_execution_context.withChildContext(context, segment, childState, usage);
@@ -430,10 +437,12 @@ async function scheduleEffectfulSourceCompletions(nodes, state, runtime, exec, p
430
437
  if (optedIn || expandedNode === node) collected.add(expandedNode);
431
438
  }
432
439
  }
440
+ const republish = exec?.republishCachedCompletions === true;
433
441
  const effectful = await require_dependency_runtime.completeEffectfulSourcesAsync(expandedNodes, state, runtime, exec, {
434
442
  ...demandNodes != null ? { demandNodes: expandEffectfulRuntimeNodes(demandNodes) } : {},
435
443
  isReusable: (node) => direct.has(node),
436
- isCollected: (node) => collected.has(node)
444
+ isCollected: republish ? () => true : (node) => collected.has(node),
445
+ ...republish ? { includeStructural: true } : {}
437
446
  });
438
447
  if (!effectful.success) return {
439
448
  success: false,
@@ -2690,7 +2699,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2690
2699
  const preCompleted = preCompleteAndRegisterDependencies(state, typedParserPairs, runtime.registry, childExec);
2691
2700
  const phase3Exec = {
2692
2701
  ...childExec,
2693
- preCompletedByParser: void 0
2702
+ preCompletedByParser: void 0,
2703
+ republishCachedCompletions: void 0
2694
2704
  };
2695
2705
  const getFieldState = createFieldStateGetter(state);
2696
2706
  const annotatedState = {};
@@ -2743,7 +2753,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2743
2753
  const preCompleted = await preCompleteAndRegisterDependenciesAsync(state, asyncParserPairs, runtime.registry, childExec);
2744
2754
  const phase3Exec = {
2745
2755
  ...childExec,
2746
- preCompletedByParser: void 0
2756
+ preCompletedByParser: void 0,
2757
+ republishCachedCompletions: void 0
2747
2758
  };
2748
2759
  const getFieldState = createFieldStateGetter(state);
2749
2760
  const annotatedState = {};
@@ -2826,7 +2837,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2826
2837
  const preCompleted = preCompleteAndRegisterDependencies(state, typedParserPairs, runtime.registry, childExec);
2827
2838
  const phase3Exec = {
2828
2839
  ...childExec,
2829
- preCompletedByParser: void 0
2840
+ preCompletedByParser: void 0,
2841
+ republishCachedCompletions: void 0
2830
2842
  };
2831
2843
  const getFieldState = createFieldStateGetter(state);
2832
2844
  const annotatedState = {};
@@ -2869,7 +2881,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2869
2881
  const preCompleted = await preCompleteAndRegisterDependenciesAsync(state, asyncParserPairs, runtime.registry, childExec);
2870
2882
  const phase3Exec = {
2871
2883
  ...childExec,
2872
- preCompletedByParser: void 0
2884
+ preCompletedByParser: void 0,
2885
+ republishCachedCompletions: void 0
2873
2886
  };
2874
2887
  const getFieldState = createFieldStateGetter(state);
2875
2888
  const annotatedState = {};
@@ -3264,7 +3277,8 @@ function createSeqComplete(parsers, combinedMode) {
3264
3277
  require_dependency_runtime.collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
3265
3278
  const phase3Exec = {
3266
3279
  ...childExec,
3267
- preCompletedByParser: void 0
3280
+ preCompletedByParser: void 0,
3281
+ republishCachedCompletions: void 0
3268
3282
  };
3269
3283
  const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
3270
3284
  const result = [];
@@ -3308,7 +3322,8 @@ function createSeqComplete(parsers, combinedMode) {
3308
3322
  if (effectfulFailure != null) return effectfulFailure;
3309
3323
  const phase3Exec = {
3310
3324
  ...childExec,
3311
- preCompletedByParser: void 0
3325
+ preCompletedByParser: void 0,
3326
+ republishCachedCompletions: void 0
3312
3327
  };
3313
3328
  const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
3314
3329
  const result = [];
@@ -3752,7 +3767,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3752
3767
  require_dependency_runtime.collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
3753
3768
  const phase3Exec = {
3754
3769
  ...childExec,
3755
- preCompletedByParser: void 0
3770
+ preCompletedByParser: void 0,
3771
+ republishCachedCompletions: void 0
3756
3772
  };
3757
3773
  const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
3758
3774
  const result = [];
@@ -3803,7 +3819,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3803
3819
  if (effectfulFailure != null) return effectfulFailure;
3804
3820
  const phase3Exec = {
3805
3821
  ...childExec,
3806
- preCompletedByParser: void 0
3822
+ preCompletedByParser: void 0,
3823
+ republishCachedCompletions: void 0
3807
3824
  };
3808
3825
  const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
3809
3826
  const result = [];
@@ -3850,7 +3867,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3850
3867
  require_dependency_runtime.collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
3851
3868
  const phase3Exec = {
3852
3869
  ...childExec,
3853
- preCompletedByParser: void 0
3870
+ preCompletedByParser: void 0,
3871
+ republishCachedCompletions: void 0
3854
3872
  };
3855
3873
  const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
3856
3874
  const result = [];
@@ -3891,7 +3909,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3891
3909
  if (effectfulFailure != null) return null;
3892
3910
  const phase3Exec = {
3893
3911
  ...childExec,
3894
- preCompletedByParser: void 0
3912
+ preCompletedByParser: void 0,
3913
+ republishCachedCompletions: void 0
3895
3914
  };
3896
3915
  const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
3897
3916
  const result = [];
@@ -4116,7 +4135,8 @@ function seq(...rawArgs) {
4116
4135
  require_dependency_runtime.collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
4117
4136
  const phase3Exec = {
4118
4137
  ...childExec,
4119
- preCompletedByParser: void 0
4138
+ preCompletedByParser: void 0,
4139
+ republishCachedCompletions: void 0
4120
4140
  };
4121
4141
  const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
4122
4142
  const result = [];
@@ -4157,7 +4177,8 @@ function seq(...rawArgs) {
4157
4177
  if (effectfulFailure != null) return null;
4158
4178
  const phase3Exec = {
4159
4179
  ...childExec,
4160
- preCompletedByParser: void 0
4180
+ preCompletedByParser: void 0,
4181
+ republishCachedCompletions: void 0
4161
4182
  };
4162
4183
  const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
4163
4184
  const result = [];
@@ -4846,7 +4867,7 @@ function merge(...args) {
4846
4867
  const parser = syncParsers[i];
4847
4868
  const parserState = extractCompleteState(parser, resolvedState, i);
4848
4869
  const { cache, excludedSourceFields } = perChildPhase1[i];
4849
- const childCompleteExec = require_execution_context.withChildExecPath(childExec, i);
4870
+ const childCompleteExec = require_execution_context.withChildExecPath(withoutRepublishInstruction(childExec), i);
4850
4871
  const completeExec = excludedSourceFields == null ? {
4851
4872
  ...childCompleteExec,
4852
4873
  preCompletedByParser: cache
@@ -4938,7 +4959,7 @@ function merge(...args) {
4938
4959
  const parser = parsers[i];
4939
4960
  const parserState = extractCompleteState(parser, resolvedState, i);
4940
4961
  const { cache: asyncCache, excludedSourceFields } = perChildPhase1[i];
4941
- const childCompleteExec = require_execution_context.withChildExecPath(childExec, i);
4962
+ const childCompleteExec = require_execution_context.withChildExecPath(withoutRepublishInstruction(childExec), i);
4942
4963
  const completeExec = excludedSourceFields == null ? {
4943
4964
  ...childCompleteExec,
4944
4965
  preCompletedByParser: asyncCache
@@ -5021,7 +5042,7 @@ function merge(...args) {
5021
5042
  const parser = syncParsers[i];
5022
5043
  const parserState = extractMergeCompleteState(parser, resolvedState, i);
5023
5044
  const { cache, excludedSourceFields } = perChildPhase1[i];
5024
- const childCompleteExec = require_execution_context.withChildExecPath(childExec, i);
5045
+ const childCompleteExec = require_execution_context.withChildExecPath(withoutRepublishInstruction(childExec), i);
5025
5046
  const completeExec = excludedSourceFields == null ? {
5026
5047
  ...childCompleteExec,
5027
5048
  preCompletedByParser: cache
@@ -5106,7 +5127,7 @@ function merge(...args) {
5106
5127
  const parser = parsers[i];
5107
5128
  const parserState = extractMergeCompleteState(parser, resolvedState, i);
5108
5129
  const { cache: asyncCache, excludedSourceFields } = perChildPhase1[i];
5109
- const childCompleteExec = require_execution_context.withChildExecPath(childExec, i);
5130
+ const childCompleteExec = require_execution_context.withChildExecPath(withoutRepublishInstruction(childExec), i);
5110
5131
  const completeExec = excludedSourceFields == null ? {
5111
5132
  ...childCompleteExec,
5112
5133
  preCompletedByParser: asyncCache
@@ -5685,7 +5706,8 @@ function concat(...parsers) {
5685
5706
  require_dependency_runtime.collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
5686
5707
  const phase3Exec = {
5687
5708
  ...childExec,
5688
- preCompletedByParser: void 0
5709
+ preCompletedByParser: void 0,
5710
+ republishCachedCompletions: void 0
5689
5711
  };
5690
5712
  const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
5691
5713
  const results = [];
@@ -5739,7 +5761,8 @@ function concat(...parsers) {
5739
5761
  if (effectfulFailure != null) return effectfulFailure;
5740
5762
  const phase3Exec = {
5741
5763
  ...childExec,
5742
- preCompletedByParser: void 0
5764
+ preCompletedByParser: void 0,
5765
+ republishCachedCompletions: void 0
5743
5766
  };
5744
5767
  const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
5745
5768
  const results = [];
@@ -5809,7 +5832,8 @@ function concat(...parsers) {
5809
5832
  require_dependency_runtime.collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(require_dependency_runtime.buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
5810
5833
  const phase3Exec = {
5811
5834
  ...childExec,
5812
- preCompletedByParser: void 0
5835
+ preCompletedByParser: void 0,
5836
+ republishCachedCompletions: void 0
5813
5837
  };
5814
5838
  const resolvedArray = require_dependency_runtime.resolveStateWithRuntime(stateArray, runtime);
5815
5839
  const results = [];
@@ -5847,7 +5871,8 @@ function concat(...parsers) {
5847
5871
  if (effectfulFailure != null) return null;
5848
5872
  const phase3Exec = {
5849
5873
  ...childExec,
5850
- preCompletedByParser: void 0
5874
+ preCompletedByParser: void 0,
5875
+ republishCachedCompletions: void 0
5851
5876
  };
5852
5877
  const resolvedArray = await require_dependency_runtime.resolveStateWithRuntimeAsync(stateArray, runtime);
5853
5878
  const results = [];
@@ -6848,7 +6873,8 @@ function conditional(discriminator, branches, defaultBranch, options) {
6848
6873
  if (discriminatorResult == null && innerCompleteSource == null) {
6849
6874
  const discriminatorExec = ctx.exec == null ? void 0 : {
6850
6875
  ...ctx.exec,
6851
- path: [...parentPath ?? [], "_discriminator"]
6876
+ path: [...parentPath ?? [], "_discriminator"],
6877
+ republishCachedCompletions: void 0
6852
6878
  };
6853
6879
  discriminatorResult = unwrapCompleteResult(await discriminator.complete(annotatedDiscriminatorState, discriminatorExec));
6854
6880
  }
@@ -6859,7 +6885,8 @@ function conditional(discriminator, branches, defaultBranch, options) {
6859
6885
  if (branchParser != null) {
6860
6886
  const branchExec = ctx.exec == null ? void 0 : {
6861
6887
  ...ctx.exec,
6862
- path: [...parentPath ?? [], "_branch"]
6888
+ path: [...parentPath ?? [], "_branch"],
6889
+ republishCachedCompletions: void 0
6863
6890
  };
6864
6891
  const annotatedInitial = require_annotation_state.getWrappedChildState(conditionalState, branchParser.initialState, branchParser);
6865
6892
  const replayResult = await branchParser.parse({
@@ -6947,12 +6974,13 @@ function conditional(discriminator, branches, defaultBranch, options) {
6947
6974
  prepared = exec.effectfulCompletionSession.preparedByPath.get(preparedKeyFor(exec.path));
6948
6975
  }
6949
6976
  const annotatedDiscriminatorStateForDeferred = require_annotation_state.getWrappedChildState(state, state.discriminatorState, discriminator);
6950
- const deferredDiscriminatorResult = prepared != null ? prepared.discriminatorResult : unwrapCompleteResult(await discriminator.complete(annotatedDiscriminatorStateForDeferred, require_execution_context.withChildExecPath(exec, "_discriminator")));
6977
+ const childExec = withoutRepublishInstruction(exec);
6978
+ const deferredDiscriminatorResult = prepared != null ? prepared.discriminatorResult : unwrapCompleteResult(await discriminator.complete(annotatedDiscriminatorStateForDeferred, require_execution_context.withChildExecPath(childExec, "_discriminator")));
6951
6979
  if (deferredDiscriminatorResult.success) {
6952
6980
  const deferredValue = deferredDiscriminatorResult.value;
6953
6981
  const deferredBranch = branches[deferredValue];
6954
6982
  if (deferredBranch) {
6955
- const branchExec = require_execution_context.withChildExecPath(exec, "_branch");
6983
+ const branchExec = require_execution_context.withChildExecPath(childExec, "_branch");
6956
6984
  let branchState;
6957
6985
  if (prepared != null && prepared.branchKey === deferredValue) branchState = prepared.branchState;
6958
6986
  else {
@@ -6998,7 +7026,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
6998
7026
  };
6999
7027
  if (defaultBranch !== void 0) {
7000
7028
  const branchState = require_annotation_state.getWrappedChildState(state, (prepared != null && prepared.branchKey == null ? prepared.branchState : void 0) ?? state.branchState ?? defaultBranch.initialState, defaultBranch);
7001
- const defaultResult = unwrapCompleteResult(await defaultBranch.complete(branchState, require_execution_context.withChildExecPath(exec, "_branch")));
7029
+ const defaultResult = unwrapCompleteResult(await defaultBranch.complete(branchState, require_execution_context.withChildExecPath(withoutRepublishInstruction(exec), "_branch")));
7002
7030
  if (!defaultResult.success) return defaultResult;
7003
7031
  return {
7004
7032
  success: true,
@@ -7039,15 +7067,16 @@ function conditional(discriminator, branches, defaultBranch, options) {
7039
7067
  const schedulingFailure = await scheduleEffectfulSourceCompletions(schedulingNodes, combinedState, runtime, completionExec, /* @__PURE__ */ new Map());
7040
7068
  if (schedulingFailure != null) return schedulingFailure;
7041
7069
  }
7070
+ const childCompletionExec = withoutRepublishInstruction(completionExec);
7042
7071
  const needsDiscriminatorCompletion = state.selectedBranch.kind !== "default" && !(state.discriminatorValue != null && state.discriminatorValue === state.selectedBranch.key);
7043
- let discriminatorCompletionExec = completionExec;
7072
+ let discriminatorCompletionExec = childCompletionExec;
7044
7073
  if (wasSpeculative && needsDiscriminatorCompletion) {
7045
7074
  const discOnlyState = { _discriminator: annotatedDiscriminatorState };
7046
7075
  const discOnlyRuntime = require_dependency_runtime.createDependencyRuntimeContext(exec?.dependencyRegistry?.clone());
7047
7076
  await require_dependency_runtime.collectExplicitSourceValuesAsync(expandSourceCollectionNodes(require_dependency_runtime.buildRuntimeNodesFromPairs([["_discriminator", discriminator]], discOnlyState, exec?.path)), discOnlyRuntime);
7048
7077
  require_dependency_runtime.collectSourcesFromState(discOnlyState, discOnlyRuntime);
7049
7078
  discriminatorCompletionExec = {
7050
- ...completionExec,
7079
+ ...childCompletionExec,
7051
7080
  dependencyRuntime: discOnlyRuntime,
7052
7081
  dependencyRegistry: discOnlyRuntime.registry
7053
7082
  };
@@ -7063,8 +7092,27 @@ function conditional(discriminator, branches, defaultBranch, options) {
7063
7092
  else discriminatorValue = state.selectedBranch.key;
7064
7093
  }
7065
7094
  if (wasSpeculative && state.selectedBranch.kind === "branch" && discriminatorValue !== state.selectedBranch.key) return branchMismatchFailure(discriminatorValue, state.selectedBranch.key);
7095
+ const branchCompletionExec = {
7096
+ ...childCompletionExec,
7097
+ path: [...childCompletionExec.path, "_branch"],
7098
+ ...wasSpeculative ? { republishCachedCompletions: true } : {}
7099
+ };
7100
+ if (wasSpeculative) {
7101
+ const replayFailure = await scheduleEffectfulSourceCompletions(buildConditionalSchedulingNodes(state, exec?.path).slice(1), combinedState, runtime, {
7102
+ ...completionExec,
7103
+ republishCachedCompletions: true
7104
+ }, /* @__PURE__ */ new Map());
7105
+ if (replayFailure != null) {
7106
+ const branchError = options?.errors?.branchError;
7107
+ if (branchError == null || discriminatorValue === void 0 || require_dependency_runtime.replaceCachedBarrierFailure(completionExec.effectfulCompletionSession, replayFailure, replayFailure)) return replayFailure;
7108
+ return {
7109
+ success: false,
7110
+ error: branchError(discriminatorValue, replayFailure.error)
7111
+ };
7112
+ }
7113
+ }
7066
7114
  const resolvedBranchState = require_annotation_state.getWrappedChildState(state, await require_dependency_runtime.resolveStateWithRuntimeAsync(state.branchState, runtime), branchParser);
7067
- const branchResult = unwrapCompleteResult(await branchParser.complete(resolvedBranchState, require_execution_context.withChildExecPath(completionExec, "_branch")));
7115
+ const branchResult = unwrapCompleteResult(await branchParser.complete(resolvedBranchState, branchCompletionExec));
7068
7116
  if (!branchResult.success) {
7069
7117
  if (discriminatorValue !== void 0 && options?.errors?.branchError) return {
7070
7118
  success: false,
@@ -39,6 +39,13 @@ function withDependencyRuntimeExec(usage, exec, runtime) {
39
39
  dependencyRegistry: runtime.registry
40
40
  };
41
41
  }
42
+ function withoutRepublishInstruction(exec) {
43
+ if (exec?.republishCachedCompletions == null) return exec;
44
+ return {
45
+ ...exec,
46
+ republishCachedCompletions: void 0
47
+ };
48
+ }
42
49
  function withChildContext$1(context, segment, state, parser, usage) {
43
50
  const childState = parser == null ? state : getWrappedChildParseState(context.state, state, parser);
44
51
  return withChildContext(context, segment, childState, usage);
@@ -430,10 +437,12 @@ async function scheduleEffectfulSourceCompletions(nodes, state, runtime, exec, p
430
437
  if (optedIn || expandedNode === node) collected.add(expandedNode);
431
438
  }
432
439
  }
440
+ const republish = exec?.republishCachedCompletions === true;
433
441
  const effectful = await completeEffectfulSourcesAsync(expandedNodes, state, runtime, exec, {
434
442
  ...demandNodes != null ? { demandNodes: expandEffectfulRuntimeNodes(demandNodes) } : {},
435
443
  isReusable: (node) => direct.has(node),
436
- isCollected: (node) => collected.has(node)
444
+ isCollected: republish ? () => true : (node) => collected.has(node),
445
+ ...republish ? { includeStructural: true } : {}
437
446
  });
438
447
  if (!effectful.success) return {
439
448
  success: false,
@@ -2690,7 +2699,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2690
2699
  const preCompleted = preCompleteAndRegisterDependencies(state, typedParserPairs, runtime.registry, childExec);
2691
2700
  const phase3Exec = {
2692
2701
  ...childExec,
2693
- preCompletedByParser: void 0
2702
+ preCompletedByParser: void 0,
2703
+ republishCachedCompletions: void 0
2694
2704
  };
2695
2705
  const getFieldState = createFieldStateGetter(state);
2696
2706
  const annotatedState = {};
@@ -2743,7 +2753,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2743
2753
  const preCompleted = await preCompleteAndRegisterDependenciesAsync(state, asyncParserPairs, runtime.registry, childExec);
2744
2754
  const phase3Exec = {
2745
2755
  ...childExec,
2746
- preCompletedByParser: void 0
2756
+ preCompletedByParser: void 0,
2757
+ republishCachedCompletions: void 0
2747
2758
  };
2748
2759
  const getFieldState = createFieldStateGetter(state);
2749
2760
  const annotatedState = {};
@@ -2826,7 +2837,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2826
2837
  const preCompleted = preCompleteAndRegisterDependencies(state, typedParserPairs, runtime.registry, childExec);
2827
2838
  const phase3Exec = {
2828
2839
  ...childExec,
2829
- preCompletedByParser: void 0
2840
+ preCompletedByParser: void 0,
2841
+ republishCachedCompletions: void 0
2830
2842
  };
2831
2843
  const getFieldState = createFieldStateGetter(state);
2832
2844
  const annotatedState = {};
@@ -2869,7 +2881,8 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2869
2881
  const preCompleted = await preCompleteAndRegisterDependenciesAsync(state, asyncParserPairs, runtime.registry, childExec);
2870
2882
  const phase3Exec = {
2871
2883
  ...childExec,
2872
- preCompletedByParser: void 0
2884
+ preCompletedByParser: void 0,
2885
+ republishCachedCompletions: void 0
2873
2886
  };
2874
2887
  const getFieldState = createFieldStateGetter(state);
2875
2888
  const annotatedState = {};
@@ -3264,7 +3277,8 @@ function createSeqComplete(parsers, combinedMode) {
3264
3277
  collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
3265
3278
  const phase3Exec = {
3266
3279
  ...childExec,
3267
- preCompletedByParser: void 0
3280
+ preCompletedByParser: void 0,
3281
+ republishCachedCompletions: void 0
3268
3282
  };
3269
3283
  const resolvedArray = resolveStateWithRuntime(stateArray, runtime);
3270
3284
  const result = [];
@@ -3308,7 +3322,8 @@ function createSeqComplete(parsers, combinedMode) {
3308
3322
  if (effectfulFailure != null) return effectfulFailure;
3309
3323
  const phase3Exec = {
3310
3324
  ...childExec,
3311
- preCompletedByParser: void 0
3325
+ preCompletedByParser: void 0,
3326
+ republishCachedCompletions: void 0
3312
3327
  };
3313
3328
  const resolvedArray = await resolveStateWithRuntimeAsync(stateArray, runtime);
3314
3329
  const result = [];
@@ -3752,7 +3767,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3752
3767
  collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
3753
3768
  const phase3Exec = {
3754
3769
  ...childExec,
3755
- preCompletedByParser: void 0
3770
+ preCompletedByParser: void 0,
3771
+ republishCachedCompletions: void 0
3756
3772
  };
3757
3773
  const resolvedArray = resolveStateWithRuntime(stateArray, runtime);
3758
3774
  const result = [];
@@ -3803,7 +3819,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3803
3819
  if (effectfulFailure != null) return effectfulFailure;
3804
3820
  const phase3Exec = {
3805
3821
  ...childExec,
3806
- preCompletedByParser: void 0
3822
+ preCompletedByParser: void 0,
3823
+ republishCachedCompletions: void 0
3807
3824
  };
3808
3825
  const resolvedArray = await resolveStateWithRuntimeAsync(stateArray, runtime);
3809
3826
  const result = [];
@@ -3850,7 +3867,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3850
3867
  collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
3851
3868
  const phase3Exec = {
3852
3869
  ...childExec,
3853
- preCompletedByParser: void 0
3870
+ preCompletedByParser: void 0,
3871
+ republishCachedCompletions: void 0
3854
3872
  };
3855
3873
  const resolvedArray = resolveStateWithRuntime(stateArray, runtime);
3856
3874
  const result = [];
@@ -3891,7 +3909,8 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3891
3909
  if (effectfulFailure != null) return null;
3892
3910
  const phase3Exec = {
3893
3911
  ...childExec,
3894
- preCompletedByParser: void 0
3912
+ preCompletedByParser: void 0,
3913
+ republishCachedCompletions: void 0
3895
3914
  };
3896
3915
  const resolvedArray = await resolveStateWithRuntimeAsync(stateArray, runtime);
3897
3916
  const result = [];
@@ -4116,7 +4135,8 @@ function seq(...rawArgs) {
4116
4135
  collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
4117
4136
  const phase3Exec = {
4118
4137
  ...childExec,
4119
- preCompletedByParser: void 0
4138
+ preCompletedByParser: void 0,
4139
+ republishCachedCompletions: void 0
4120
4140
  };
4121
4141
  const resolvedArray = resolveStateWithRuntime(stateArray, runtime);
4122
4142
  const result = [];
@@ -4157,7 +4177,8 @@ function seq(...rawArgs) {
4157
4177
  if (effectfulFailure != null) return null;
4158
4178
  const phase3Exec = {
4159
4179
  ...childExec,
4160
- preCompletedByParser: void 0
4180
+ preCompletedByParser: void 0,
4181
+ republishCachedCompletions: void 0
4161
4182
  };
4162
4183
  const resolvedArray = await resolveStateWithRuntimeAsync(stateArray, runtime);
4163
4184
  const result = [];
@@ -4846,7 +4867,7 @@ function merge(...args) {
4846
4867
  const parser = syncParsers[i];
4847
4868
  const parserState = extractCompleteState(parser, resolvedState, i);
4848
4869
  const { cache, excludedSourceFields } = perChildPhase1[i];
4849
- const childCompleteExec = withChildExecPath(childExec, i);
4870
+ const childCompleteExec = withChildExecPath(withoutRepublishInstruction(childExec), i);
4850
4871
  const completeExec = excludedSourceFields == null ? {
4851
4872
  ...childCompleteExec,
4852
4873
  preCompletedByParser: cache
@@ -4938,7 +4959,7 @@ function merge(...args) {
4938
4959
  const parser = parsers[i];
4939
4960
  const parserState = extractCompleteState(parser, resolvedState, i);
4940
4961
  const { cache: asyncCache, excludedSourceFields } = perChildPhase1[i];
4941
- const childCompleteExec = withChildExecPath(childExec, i);
4962
+ const childCompleteExec = withChildExecPath(withoutRepublishInstruction(childExec), i);
4942
4963
  const completeExec = excludedSourceFields == null ? {
4943
4964
  ...childCompleteExec,
4944
4965
  preCompletedByParser: asyncCache
@@ -5021,7 +5042,7 @@ function merge(...args) {
5021
5042
  const parser = syncParsers[i];
5022
5043
  const parserState = extractMergeCompleteState(parser, resolvedState, i);
5023
5044
  const { cache, excludedSourceFields } = perChildPhase1[i];
5024
- const childCompleteExec = withChildExecPath(childExec, i);
5045
+ const childCompleteExec = withChildExecPath(withoutRepublishInstruction(childExec), i);
5025
5046
  const completeExec = excludedSourceFields == null ? {
5026
5047
  ...childCompleteExec,
5027
5048
  preCompletedByParser: cache
@@ -5106,7 +5127,7 @@ function merge(...args) {
5106
5127
  const parser = parsers[i];
5107
5128
  const parserState = extractMergeCompleteState(parser, resolvedState, i);
5108
5129
  const { cache: asyncCache, excludedSourceFields } = perChildPhase1[i];
5109
- const childCompleteExec = withChildExecPath(childExec, i);
5130
+ const childCompleteExec = withChildExecPath(withoutRepublishInstruction(childExec), i);
5110
5131
  const completeExec = excludedSourceFields == null ? {
5111
5132
  ...childCompleteExec,
5112
5133
  preCompletedByParser: asyncCache
@@ -5685,7 +5706,8 @@ function concat(...parsers) {
5685
5706
  collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
5686
5707
  const phase3Exec = {
5687
5708
  ...childExec,
5688
- preCompletedByParser: void 0
5709
+ preCompletedByParser: void 0,
5710
+ republishCachedCompletions: void 0
5689
5711
  };
5690
5712
  const resolvedArray = resolveStateWithRuntime(stateArray, runtime);
5691
5713
  const results = [];
@@ -5739,7 +5761,8 @@ function concat(...parsers) {
5739
5761
  if (effectfulFailure != null) return effectfulFailure;
5740
5762
  const phase3Exec = {
5741
5763
  ...childExec,
5742
- preCompletedByParser: void 0
5764
+ preCompletedByParser: void 0,
5765
+ republishCachedCompletions: void 0
5743
5766
  };
5744
5767
  const resolvedArray = await resolveStateWithRuntimeAsync(stateArray, runtime);
5745
5768
  const results = [];
@@ -5809,7 +5832,8 @@ function concat(...parsers) {
5809
5832
  collectExplicitSourceValues(expandSourceCollectionNodes(filterPreCompletedRuntimeNodes(buildRuntimeNodesFromArray(syncParsers, stateArray, exec?.path), new Set(preCompleted.keys()))), runtime);
5810
5833
  const phase3Exec = {
5811
5834
  ...childExec,
5812
- preCompletedByParser: void 0
5835
+ preCompletedByParser: void 0,
5836
+ republishCachedCompletions: void 0
5813
5837
  };
5814
5838
  const resolvedArray = resolveStateWithRuntime(stateArray, runtime);
5815
5839
  const results = [];
@@ -5847,7 +5871,8 @@ function concat(...parsers) {
5847
5871
  if (effectfulFailure != null) return null;
5848
5872
  const phase3Exec = {
5849
5873
  ...childExec,
5850
- preCompletedByParser: void 0
5874
+ preCompletedByParser: void 0,
5875
+ republishCachedCompletions: void 0
5851
5876
  };
5852
5877
  const resolvedArray = await resolveStateWithRuntimeAsync(stateArray, runtime);
5853
5878
  const results = [];
@@ -6848,7 +6873,8 @@ function conditional(discriminator, branches, defaultBranch, options) {
6848
6873
  if (discriminatorResult == null && innerCompleteSource == null) {
6849
6874
  const discriminatorExec = ctx.exec == null ? void 0 : {
6850
6875
  ...ctx.exec,
6851
- path: [...parentPath ?? [], "_discriminator"]
6876
+ path: [...parentPath ?? [], "_discriminator"],
6877
+ republishCachedCompletions: void 0
6852
6878
  };
6853
6879
  discriminatorResult = unwrapCompleteResult(await discriminator.complete(annotatedDiscriminatorState, discriminatorExec));
6854
6880
  }
@@ -6859,7 +6885,8 @@ function conditional(discriminator, branches, defaultBranch, options) {
6859
6885
  if (branchParser != null) {
6860
6886
  const branchExec = ctx.exec == null ? void 0 : {
6861
6887
  ...ctx.exec,
6862
- path: [...parentPath ?? [], "_branch"]
6888
+ path: [...parentPath ?? [], "_branch"],
6889
+ republishCachedCompletions: void 0
6863
6890
  };
6864
6891
  const annotatedInitial = getWrappedChildState(conditionalState, branchParser.initialState, branchParser);
6865
6892
  const replayResult = await branchParser.parse({
@@ -6947,12 +6974,13 @@ function conditional(discriminator, branches, defaultBranch, options) {
6947
6974
  prepared = exec.effectfulCompletionSession.preparedByPath.get(preparedKeyFor(exec.path));
6948
6975
  }
6949
6976
  const annotatedDiscriminatorStateForDeferred = getWrappedChildState(state, state.discriminatorState, discriminator);
6950
- const deferredDiscriminatorResult = prepared != null ? prepared.discriminatorResult : unwrapCompleteResult(await discriminator.complete(annotatedDiscriminatorStateForDeferred, withChildExecPath(exec, "_discriminator")));
6977
+ const childExec = withoutRepublishInstruction(exec);
6978
+ const deferredDiscriminatorResult = prepared != null ? prepared.discriminatorResult : unwrapCompleteResult(await discriminator.complete(annotatedDiscriminatorStateForDeferred, withChildExecPath(childExec, "_discriminator")));
6951
6979
  if (deferredDiscriminatorResult.success) {
6952
6980
  const deferredValue = deferredDiscriminatorResult.value;
6953
6981
  const deferredBranch = branches[deferredValue];
6954
6982
  if (deferredBranch) {
6955
- const branchExec = withChildExecPath(exec, "_branch");
6983
+ const branchExec = withChildExecPath(childExec, "_branch");
6956
6984
  let branchState;
6957
6985
  if (prepared != null && prepared.branchKey === deferredValue) branchState = prepared.branchState;
6958
6986
  else {
@@ -6998,7 +7026,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
6998
7026
  };
6999
7027
  if (defaultBranch !== void 0) {
7000
7028
  const branchState = getWrappedChildState(state, (prepared != null && prepared.branchKey == null ? prepared.branchState : void 0) ?? state.branchState ?? defaultBranch.initialState, defaultBranch);
7001
- const defaultResult = unwrapCompleteResult(await defaultBranch.complete(branchState, withChildExecPath(exec, "_branch")));
7029
+ const defaultResult = unwrapCompleteResult(await defaultBranch.complete(branchState, withChildExecPath(withoutRepublishInstruction(exec), "_branch")));
7002
7030
  if (!defaultResult.success) return defaultResult;
7003
7031
  return {
7004
7032
  success: true,
@@ -7039,15 +7067,16 @@ function conditional(discriminator, branches, defaultBranch, options) {
7039
7067
  const schedulingFailure = await scheduleEffectfulSourceCompletions(schedulingNodes, combinedState, runtime, completionExec, /* @__PURE__ */ new Map());
7040
7068
  if (schedulingFailure != null) return schedulingFailure;
7041
7069
  }
7070
+ const childCompletionExec = withoutRepublishInstruction(completionExec);
7042
7071
  const needsDiscriminatorCompletion = state.selectedBranch.kind !== "default" && !(state.discriminatorValue != null && state.discriminatorValue === state.selectedBranch.key);
7043
- let discriminatorCompletionExec = completionExec;
7072
+ let discriminatorCompletionExec = childCompletionExec;
7044
7073
  if (wasSpeculative && needsDiscriminatorCompletion) {
7045
7074
  const discOnlyState = { _discriminator: annotatedDiscriminatorState };
7046
7075
  const discOnlyRuntime = createDependencyRuntimeContext(exec?.dependencyRegistry?.clone());
7047
7076
  await collectExplicitSourceValuesAsync(expandSourceCollectionNodes(buildRuntimeNodesFromPairs([["_discriminator", discriminator]], discOnlyState, exec?.path)), discOnlyRuntime);
7048
7077
  collectSourcesFromState(discOnlyState, discOnlyRuntime);
7049
7078
  discriminatorCompletionExec = {
7050
- ...completionExec,
7079
+ ...childCompletionExec,
7051
7080
  dependencyRuntime: discOnlyRuntime,
7052
7081
  dependencyRegistry: discOnlyRuntime.registry
7053
7082
  };
@@ -7063,8 +7092,27 @@ function conditional(discriminator, branches, defaultBranch, options) {
7063
7092
  else discriminatorValue = state.selectedBranch.key;
7064
7093
  }
7065
7094
  if (wasSpeculative && state.selectedBranch.kind === "branch" && discriminatorValue !== state.selectedBranch.key) return branchMismatchFailure(discriminatorValue, state.selectedBranch.key);
7095
+ const branchCompletionExec = {
7096
+ ...childCompletionExec,
7097
+ path: [...childCompletionExec.path, "_branch"],
7098
+ ...wasSpeculative ? { republishCachedCompletions: true } : {}
7099
+ };
7100
+ if (wasSpeculative) {
7101
+ const replayFailure = await scheduleEffectfulSourceCompletions(buildConditionalSchedulingNodes(state, exec?.path).slice(1), combinedState, runtime, {
7102
+ ...completionExec,
7103
+ republishCachedCompletions: true
7104
+ }, /* @__PURE__ */ new Map());
7105
+ if (replayFailure != null) {
7106
+ const branchError = options?.errors?.branchError;
7107
+ if (branchError == null || discriminatorValue === void 0 || replaceCachedBarrierFailure(completionExec.effectfulCompletionSession, replayFailure, replayFailure)) return replayFailure;
7108
+ return {
7109
+ success: false,
7110
+ error: branchError(discriminatorValue, replayFailure.error)
7111
+ };
7112
+ }
7113
+ }
7066
7114
  const resolvedBranchState = getWrappedChildState(state, await resolveStateWithRuntimeAsync(state.branchState, runtime), branchParser);
7067
- const branchResult = unwrapCompleteResult(await branchParser.complete(resolvedBranchState, withChildExecPath(completionExec, "_branch")));
7115
+ const branchResult = unwrapCompleteResult(await branchParser.complete(resolvedBranchState, branchCompletionExec));
7068
7116
  if (!branchResult.success) {
7069
7117
  if (discriminatorValue !== void 0 && options?.errors?.branchError) return {
7070
7118
  success: false,
@@ -1525,13 +1525,15 @@ async function completeEffectfulSourcesAsync(nodes, state, runtime, exec, option
1525
1525
  key: node.path[node.path.length - 1],
1526
1526
  result: priorResult
1527
1527
  });
1528
+ if (exec.republishCachedCompletions === true && priorResult.success && priorResult.value !== void 0) publishFromNode(node, source.sourceId, priorResult.value);
1528
1529
  continue;
1529
1530
  }
1530
1531
  const reusable = source.preservesSourceValue && (options?.isReusable?.(node) ?? true);
1531
1532
  if (!reusable && session == null) continue;
1532
1533
  const childExec = {
1533
1534
  ...exec,
1534
- path: node.path
1535
+ path: node.path,
1536
+ republishCachedCompletions: void 0
1535
1537
  };
1536
1538
  const result = await source.completeSource(node.state, childExec);
1537
1539
  if (result == null) continue;
@@ -1525,13 +1525,15 @@ async function completeEffectfulSourcesAsync(nodes, state, runtime, exec, option
1525
1525
  key: node.path[node.path.length - 1],
1526
1526
  result: priorResult
1527
1527
  });
1528
+ if (exec.republishCachedCompletions === true && priorResult.success && priorResult.value !== void 0) publishFromNode(node, source.sourceId, priorResult.value);
1528
1529
  continue;
1529
1530
  }
1530
1531
  const reusable = source.preservesSourceValue && (options?.isReusable?.(node) ?? true);
1531
1532
  if (!reusable && session == null) continue;
1532
1533
  const childExec = {
1533
1534
  ...exec,
1534
- path: node.path
1535
+ path: node.path,
1536
+ republishCachedCompletions: void 0
1535
1537
  };
1536
1538
  const result = await source.completeSource(node.state, childExec);
1537
1539
  if (result == null) continue;
@@ -467,7 +467,9 @@ interface EffectfulCompletionSession {
467
467
  * owning nested construct's own scheduling pass reuses it instead of
468
468
  * completing the same node again—keeping lazy wrapper defaults at one
469
469
  * evaluation per pass and the registered dependency value identical to
470
- * the field's final value.
470
+ * the field's final value. A pass whose execution context carries
471
+ * {@link ExecutionContext.republishCachedCompletions} re-registers a
472
+ * reused result's value at the node's declaration position.
471
473
  */
472
474
  readonly completedByPath: Map<string, ValueParserResult<unknown>>;
473
475
  /**
@@ -576,6 +578,29 @@ interface ExecutionContext {
576
578
  * @internal
577
579
  */
578
580
  readonly preCompletedByParser?: ReadonlyMap<string | symbol, unknown>;
581
+ /**
582
+ * Re-registers effectful completion results already cached in the
583
+ * run-scoped session at their declaration positions during the
584
+ * receiving construct's own effectful scheduling pass. A
585
+ * `conditional()` sets this for the completion of a branch it selected
586
+ * during completion: the branch completes against a fresh runtime
587
+ * cloned after the enclosing pass restored later-declared occurrences,
588
+ * and the branch's cached publishes have no structural carrier, so
589
+ * without this the branch's deferred derived consumers would read the
590
+ * outer occurrence instead of the branch's own publish. No effect
591
+ * re-runs; only the cached value is re-registered.
592
+ *
593
+ * Path-transparent wrappers (`command()`, `or()`, modifiers) forward
594
+ * it unchanged. A construct that runs the scheduling pass consumes it
595
+ * there and must drop it from the execution contexts of its own
596
+ * children, exactly as it drops {@link preCompletedByParser}, so nested
597
+ * passes keep skipping cached completions instead of re-asserting them
598
+ * over a later sibling occurrence.
599
+ *
600
+ * @see https://github.com/dahlia/optique/issues/929
601
+ * @internal
602
+ */
603
+ readonly republishCachedCompletions?: boolean;
579
604
  /**
580
605
  * Field names that should be ignored when a construct seeds dependency
581
606
  * sources from child state during completion.
@@ -467,7 +467,9 @@ interface EffectfulCompletionSession {
467
467
  * owning nested construct's own scheduling pass reuses it instead of
468
468
  * completing the same node again—keeping lazy wrapper defaults at one
469
469
  * evaluation per pass and the registered dependency value identical to
470
- * the field's final value.
470
+ * the field's final value. A pass whose execution context carries
471
+ * {@link ExecutionContext.republishCachedCompletions} re-registers a
472
+ * reused result's value at the node's declaration position.
471
473
  */
472
474
  readonly completedByPath: Map<string, ValueParserResult<unknown>>;
473
475
  /**
@@ -576,6 +578,29 @@ interface ExecutionContext {
576
578
  * @internal
577
579
  */
578
580
  readonly preCompletedByParser?: ReadonlyMap<string | symbol, unknown>;
581
+ /**
582
+ * Re-registers effectful completion results already cached in the
583
+ * run-scoped session at their declaration positions during the
584
+ * receiving construct's own effectful scheduling pass. A
585
+ * `conditional()` sets this for the completion of a branch it selected
586
+ * during completion: the branch completes against a fresh runtime
587
+ * cloned after the enclosing pass restored later-declared occurrences,
588
+ * and the branch's cached publishes have no structural carrier, so
589
+ * without this the branch's deferred derived consumers would read the
590
+ * outer occurrence instead of the branch's own publish. No effect
591
+ * re-runs; only the cached value is re-registered.
592
+ *
593
+ * Path-transparent wrappers (`command()`, `or()`, modifiers) forward
594
+ * it unchanged. A construct that runs the scheduling pass consumes it
595
+ * there and must drop it from the execution contexts of its own
596
+ * children, exactly as it drops {@link preCompletedByParser}, so nested
597
+ * passes keep skipping cached completions instead of re-asserting them
598
+ * over a later sibling occurrence.
599
+ *
600
+ * @see https://github.com/dahlia/optique/issues/929
601
+ * @internal
602
+ */
603
+ readonly republishCachedCompletions?: boolean;
579
604
  /**
580
605
  * Field names that should be ignored when a construct seeds dependency
581
606
  * sources from child state during completion.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.3.0-dev.2441",
3
+ "version": "1.3.0-dev.2444",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -221,7 +221,7 @@
221
221
  },
222
222
  "sideEffects": false,
223
223
  "devDependencies": {
224
- "@optique/env": "1.3.0-dev.2441+5735b624",
224
+ "@optique/env": "1.3.0-dev.2444+f99a5325",
225
225
  "@types/node": "^24.0.0",
226
226
  "fast-check": "^4.7.0",
227
227
  "tsdown": "^0.13.0",