@optique/core 1.0.0-dev.757 → 1.0.0-dev.767
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constructs.cjs +4 -0
- package/dist/constructs.js +4 -0
- package/dist/modifiers.cjs +25 -2
- package/dist/modifiers.js +26 -3
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const require_usage_internals = require('./usage-internals.cjs');
|
|
|
8
8
|
|
|
9
9
|
//#region src/constructs.ts
|
|
10
10
|
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
11
|
+
const deferPromptUntilConfigResolvesKey = Symbol.for("@optique/config/deferPromptUntilResolved");
|
|
11
12
|
function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput, parsers, customFormatter) {
|
|
12
13
|
const options = /* @__PURE__ */ new Set();
|
|
13
14
|
const commands = /* @__PURE__ */ new Set();
|
|
@@ -2185,6 +2186,8 @@ function concat(...parsers) {
|
|
|
2185
2186
|
};
|
|
2186
2187
|
}
|
|
2187
2188
|
function group(label, parser, options = {}) {
|
|
2189
|
+
const deferPromptHook = Reflect.get(parser, deferPromptUntilConfigResolvesKey);
|
|
2190
|
+
const deferPromptMarker = typeof deferPromptHook === "function" ? { [deferPromptUntilConfigResolvesKey]: deferPromptHook } : {};
|
|
2188
2191
|
return {
|
|
2189
2192
|
$mode: parser.$mode,
|
|
2190
2193
|
$valueType: parser.$valueType,
|
|
@@ -2192,6 +2195,7 @@ function group(label, parser, options = {}) {
|
|
|
2192
2195
|
priority: parser.priority,
|
|
2193
2196
|
usage: applyHiddenToUsage(parser.usage, options.hidden),
|
|
2194
2197
|
initialState: parser.initialState,
|
|
2198
|
+
...deferPromptMarker,
|
|
2195
2199
|
parse: (context) => parser.parse(context),
|
|
2196
2200
|
complete: (state) => parser.complete(state),
|
|
2197
2201
|
suggest: (context, prefix) => {
|
package/dist/constructs.js
CHANGED
|
@@ -8,6 +8,7 @@ import { collectLeadingCandidates } from "./usage-internals.js";
|
|
|
8
8
|
|
|
9
9
|
//#region src/constructs.ts
|
|
10
10
|
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
11
|
+
const deferPromptUntilConfigResolvesKey = Symbol.for("@optique/config/deferPromptUntilResolved");
|
|
11
12
|
function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput, parsers, customFormatter) {
|
|
12
13
|
const options = /* @__PURE__ */ new Set();
|
|
13
14
|
const commands = /* @__PURE__ */ new Set();
|
|
@@ -2185,6 +2186,8 @@ function concat(...parsers) {
|
|
|
2185
2186
|
};
|
|
2186
2187
|
}
|
|
2187
2188
|
function group(label, parser, options = {}) {
|
|
2189
|
+
const deferPromptHook = Reflect.get(parser, deferPromptUntilConfigResolvesKey);
|
|
2190
|
+
const deferPromptMarker = typeof deferPromptHook === "function" ? { [deferPromptUntilConfigResolvesKey]: deferPromptHook } : {};
|
|
2188
2191
|
return {
|
|
2189
2192
|
$mode: parser.$mode,
|
|
2190
2193
|
$valueType: parser.$valueType,
|
|
@@ -2192,6 +2195,7 @@ function group(label, parser, options = {}) {
|
|
|
2192
2195
|
priority: parser.priority,
|
|
2193
2196
|
usage: applyHiddenToUsage(parser.usage, options.hidden),
|
|
2194
2197
|
initialState: parser.initialState,
|
|
2198
|
+
...deferPromptMarker,
|
|
2195
2199
|
parse: (context) => parser.parse(context),
|
|
2196
2200
|
complete: (state) => parser.complete(state),
|
|
2197
2201
|
suggest: (context, prefix) => {
|
package/dist/modifiers.cjs
CHANGED
|
@@ -4,6 +4,7 @@ const require_dependency = require('./dependency.cjs');
|
|
|
4
4
|
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/modifiers.ts
|
|
7
|
+
const deferPromptUntilConfigResolvesKey = Symbol.for("@optique/config/deferPromptUntilResolved");
|
|
7
8
|
/**
|
|
8
9
|
* Internal helper for optional-style parsing logic shared by optional()
|
|
9
10
|
* and withDefault(). Handles the common pattern of:
|
|
@@ -96,6 +97,8 @@ function optional(parser) {
|
|
|
96
97
|
const wrappedDependencyMarker = innerHasWrappedDependency ? { [require_dependency.wrappedDependencySourceMarker]: parser[require_dependency.wrappedDependencySourceMarker] } : innerHasDirectDependency ? { [require_dependency.wrappedDependencySourceMarker]: syncParser.initialState } : {};
|
|
97
98
|
const hasWrappedDependencySource = require_dependency.wrappedDependencySourceMarker in wrappedDependencyMarker;
|
|
98
99
|
const wrappedPendingState = hasWrappedDependencySource ? wrappedDependencyMarker[require_dependency.wrappedDependencySourceMarker] : void 0;
|
|
100
|
+
const deferPromptHook = Reflect.get(parser, deferPromptUntilConfigResolvesKey);
|
|
101
|
+
const deferPromptMarker = typeof deferPromptHook === "function" ? { [deferPromptUntilConfigResolvesKey]: deferPromptHook } : {};
|
|
99
102
|
return {
|
|
100
103
|
$mode: parser.$mode,
|
|
101
104
|
$valueType: [],
|
|
@@ -107,12 +110,23 @@ function optional(parser) {
|
|
|
107
110
|
}],
|
|
108
111
|
initialState: void 0,
|
|
109
112
|
...wrappedDependencyMarker,
|
|
113
|
+
...deferPromptMarker,
|
|
110
114
|
parse(context) {
|
|
111
115
|
return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
112
116
|
},
|
|
113
117
|
complete(state) {
|
|
114
118
|
if (!Array.isArray(state)) {
|
|
115
119
|
if (innerHasWrappedDependency && wrappedPendingState) return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete([wrappedPendingState]), () => parser.complete([wrappedPendingState]));
|
|
120
|
+
if (typeof deferPromptHook === "function" && state != null && typeof state === "object") {
|
|
121
|
+
const innerComplete = () => {
|
|
122
|
+
const innerResult = require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
123
|
+
return require_mode_dispatch.mapModeValue(parser.$mode, innerResult, (result) => result.success ? result : {
|
|
124
|
+
success: true,
|
|
125
|
+
value: void 0
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return innerComplete();
|
|
129
|
+
}
|
|
116
130
|
return {
|
|
117
131
|
success: true,
|
|
118
132
|
value: void 0
|
|
@@ -125,7 +139,8 @@ function optional(parser) {
|
|
|
125
139
|
value: void 0
|
|
126
140
|
};
|
|
127
141
|
}
|
|
128
|
-
|
|
142
|
+
const innerElement = require_annotations.getAnnotations(state) != null && state[0] != null && typeof state[0] === "object" ? require_annotations.inheritAnnotations(state, state[0]) : state[0];
|
|
143
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(innerElement), () => parser.complete(innerElement));
|
|
129
144
|
},
|
|
130
145
|
suggest(context, prefix) {
|
|
131
146
|
return require_mode_dispatch.dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
@@ -202,6 +217,8 @@ function withDefault(parser, defaultValue, options) {
|
|
|
202
217
|
}
|
|
203
218
|
const innerInitialState = syncParser.initialState;
|
|
204
219
|
const wrappedDependencyMarker = require_dependency.isPendingDependencySourceState(innerInitialState) ? { [require_dependency.wrappedDependencySourceMarker]: innerInitialState } : require_dependency.isWrappedDependencySource(parser) ? { [require_dependency.wrappedDependencySourceMarker]: parser[require_dependency.wrappedDependencySourceMarker] } : {};
|
|
220
|
+
const deferPromptHookDefault = Reflect.get(parser, deferPromptUntilConfigResolvesKey);
|
|
221
|
+
const deferPromptMarkerDefault = typeof deferPromptHookDefault === "function" ? { [deferPromptUntilConfigResolvesKey]: deferPromptHookDefault } : {};
|
|
205
222
|
return {
|
|
206
223
|
$mode: parser.$mode,
|
|
207
224
|
$valueType: [],
|
|
@@ -213,6 +230,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
213
230
|
}],
|
|
214
231
|
initialState: void 0,
|
|
215
232
|
...wrappedDependencyMarker,
|
|
233
|
+
...deferPromptMarkerDefault,
|
|
216
234
|
parse(context) {
|
|
217
235
|
return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
218
236
|
},
|
|
@@ -261,6 +279,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
261
279
|
error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
|
|
262
280
|
};
|
|
263
281
|
}
|
|
282
|
+
if (typeof deferPromptHookDefault === "function" && state != null && typeof state === "object") {
|
|
283
|
+
const innerResult = require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
284
|
+
return innerResult;
|
|
285
|
+
}
|
|
264
286
|
try {
|
|
265
287
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
266
288
|
return {
|
|
@@ -318,7 +340,8 @@ function withDefault(parser, defaultValue, options) {
|
|
|
318
340
|
};
|
|
319
341
|
}
|
|
320
342
|
}
|
|
321
|
-
|
|
343
|
+
const innerElement = require_annotations.getAnnotations(state) != null && state[0] != null && typeof state[0] === "object" ? require_annotations.inheritAnnotations(state, state[0]) : state[0];
|
|
344
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(innerElement), () => parser.complete(innerElement));
|
|
322
345
|
},
|
|
323
346
|
suggest(context, prefix) {
|
|
324
347
|
return require_mode_dispatch.dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
package/dist/modifiers.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { annotateFreshArray, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
1
|
+
import { annotateFreshArray, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
2
2
|
import { formatMessage, message, text } from "./message.js";
|
|
3
3
|
import { createDependencySourceState, dependencyId, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
4
4
|
import { dispatchByMode, dispatchIterableByMode, mapModeValue } from "./mode-dispatch.js";
|
|
5
5
|
|
|
6
6
|
//#region src/modifiers.ts
|
|
7
|
+
const deferPromptUntilConfigResolvesKey = Symbol.for("@optique/config/deferPromptUntilResolved");
|
|
7
8
|
/**
|
|
8
9
|
* Internal helper for optional-style parsing logic shared by optional()
|
|
9
10
|
* and withDefault(). Handles the common pattern of:
|
|
@@ -96,6 +97,8 @@ function optional(parser) {
|
|
|
96
97
|
const wrappedDependencyMarker = innerHasWrappedDependency ? { [wrappedDependencySourceMarker]: parser[wrappedDependencySourceMarker] } : innerHasDirectDependency ? { [wrappedDependencySourceMarker]: syncParser.initialState } : {};
|
|
97
98
|
const hasWrappedDependencySource = wrappedDependencySourceMarker in wrappedDependencyMarker;
|
|
98
99
|
const wrappedPendingState = hasWrappedDependencySource ? wrappedDependencyMarker[wrappedDependencySourceMarker] : void 0;
|
|
100
|
+
const deferPromptHook = Reflect.get(parser, deferPromptUntilConfigResolvesKey);
|
|
101
|
+
const deferPromptMarker = typeof deferPromptHook === "function" ? { [deferPromptUntilConfigResolvesKey]: deferPromptHook } : {};
|
|
99
102
|
return {
|
|
100
103
|
$mode: parser.$mode,
|
|
101
104
|
$valueType: [],
|
|
@@ -107,12 +110,23 @@ function optional(parser) {
|
|
|
107
110
|
}],
|
|
108
111
|
initialState: void 0,
|
|
109
112
|
...wrappedDependencyMarker,
|
|
113
|
+
...deferPromptMarker,
|
|
110
114
|
parse(context) {
|
|
111
115
|
return dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
112
116
|
},
|
|
113
117
|
complete(state) {
|
|
114
118
|
if (!Array.isArray(state)) {
|
|
115
119
|
if (innerHasWrappedDependency && wrappedPendingState) return dispatchByMode(parser.$mode, () => syncParser.complete([wrappedPendingState]), () => parser.complete([wrappedPendingState]));
|
|
120
|
+
if (typeof deferPromptHook === "function" && state != null && typeof state === "object") {
|
|
121
|
+
const innerComplete = () => {
|
|
122
|
+
const innerResult = dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
123
|
+
return mapModeValue(parser.$mode, innerResult, (result) => result.success ? result : {
|
|
124
|
+
success: true,
|
|
125
|
+
value: void 0
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return innerComplete();
|
|
129
|
+
}
|
|
116
130
|
return {
|
|
117
131
|
success: true,
|
|
118
132
|
value: void 0
|
|
@@ -125,7 +139,8 @@ function optional(parser) {
|
|
|
125
139
|
value: void 0
|
|
126
140
|
};
|
|
127
141
|
}
|
|
128
|
-
|
|
142
|
+
const innerElement = getAnnotations(state) != null && state[0] != null && typeof state[0] === "object" ? inheritAnnotations(state, state[0]) : state[0];
|
|
143
|
+
return dispatchByMode(parser.$mode, () => syncParser.complete(innerElement), () => parser.complete(innerElement));
|
|
129
144
|
},
|
|
130
145
|
suggest(context, prefix) {
|
|
131
146
|
return dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
@@ -202,6 +217,8 @@ function withDefault(parser, defaultValue, options) {
|
|
|
202
217
|
}
|
|
203
218
|
const innerInitialState = syncParser.initialState;
|
|
204
219
|
const wrappedDependencyMarker = isPendingDependencySourceState(innerInitialState) ? { [wrappedDependencySourceMarker]: innerInitialState } : isWrappedDependencySource(parser) ? { [wrappedDependencySourceMarker]: parser[wrappedDependencySourceMarker] } : {};
|
|
220
|
+
const deferPromptHookDefault = Reflect.get(parser, deferPromptUntilConfigResolvesKey);
|
|
221
|
+
const deferPromptMarkerDefault = typeof deferPromptHookDefault === "function" ? { [deferPromptUntilConfigResolvesKey]: deferPromptHookDefault } : {};
|
|
205
222
|
return {
|
|
206
223
|
$mode: parser.$mode,
|
|
207
224
|
$valueType: [],
|
|
@@ -213,6 +230,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
213
230
|
}],
|
|
214
231
|
initialState: void 0,
|
|
215
232
|
...wrappedDependencyMarker,
|
|
233
|
+
...deferPromptMarkerDefault,
|
|
216
234
|
parse(context) {
|
|
217
235
|
return dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
218
236
|
},
|
|
@@ -261,6 +279,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
261
279
|
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
262
280
|
};
|
|
263
281
|
}
|
|
282
|
+
if (typeof deferPromptHookDefault === "function" && state != null && typeof state === "object") {
|
|
283
|
+
const innerResult = dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
284
|
+
return innerResult;
|
|
285
|
+
}
|
|
264
286
|
try {
|
|
265
287
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
266
288
|
return {
|
|
@@ -318,7 +340,8 @@ function withDefault(parser, defaultValue, options) {
|
|
|
318
340
|
};
|
|
319
341
|
}
|
|
320
342
|
}
|
|
321
|
-
|
|
343
|
+
const innerElement = getAnnotations(state) != null && state[0] != null && typeof state[0] === "object" ? inheritAnnotations(state, state[0]) : state[0];
|
|
344
|
+
return dispatchByMode(parser.$mode, () => syncParser.complete(innerElement), () => parser.complete(innerElement));
|
|
322
345
|
},
|
|
323
346
|
suggest(context, prefix) {
|
|
324
347
|
return dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|