@optique/config 1.0.0-dev.465 → 1.0.0-dev.467
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/index.cjs +18 -11
- package/dist/index.js +18 -11
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -238,25 +238,25 @@ function bindConfig(parser, options) {
|
|
|
238
238
|
...context,
|
|
239
239
|
state: innerState
|
|
240
240
|
} : context;
|
|
241
|
-
const processResult = (result
|
|
242
|
-
if (result
|
|
243
|
-
const cliConsumed = result
|
|
241
|
+
const processResult = (result) => {
|
|
242
|
+
if (result.success) {
|
|
243
|
+
const cliConsumed = result.consumed.length > 0;
|
|
244
244
|
const newState$1 = {
|
|
245
245
|
[configBindStateKey]: true,
|
|
246
246
|
hasCliValue: cliConsumed,
|
|
247
|
-
cliState: result
|
|
247
|
+
cliState: result.next.state,
|
|
248
248
|
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
249
249
|
};
|
|
250
250
|
return {
|
|
251
251
|
success: true,
|
|
252
252
|
next: {
|
|
253
|
-
...result
|
|
253
|
+
...result.next,
|
|
254
254
|
state: newState$1
|
|
255
255
|
},
|
|
256
|
-
consumed: result
|
|
256
|
+
consumed: result.consumed
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
|
-
if (result
|
|
259
|
+
if (result.consumed > 0) return result;
|
|
260
260
|
const newState = {
|
|
261
261
|
[configBindStateKey]: true,
|
|
262
262
|
hasCliValue: false,
|
|
@@ -271,13 +271,11 @@ function bindConfig(parser, options) {
|
|
|
271
271
|
consumed: []
|
|
272
272
|
};
|
|
273
273
|
};
|
|
274
|
-
|
|
275
|
-
if (result instanceof Promise) return result.then(processResult);
|
|
276
|
-
return processResult(result);
|
|
274
|
+
return mapModeValue(parser.$mode, parser.parse(innerContext), processResult);
|
|
277
275
|
},
|
|
278
276
|
complete: (state) => {
|
|
279
277
|
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
280
|
-
return getConfigOrDefault(state, options);
|
|
278
|
+
return wrapForMode(parser.$mode, getConfigOrDefault(state, options));
|
|
281
279
|
},
|
|
282
280
|
suggest: parser.suggest,
|
|
283
281
|
getDocFragments(state, upperDefaultValue) {
|
|
@@ -286,6 +284,15 @@ function bindConfig(parser, options) {
|
|
|
286
284
|
}
|
|
287
285
|
};
|
|
288
286
|
}
|
|
287
|
+
function wrapForMode(mode, value) {
|
|
288
|
+
if (mode === "async") return Promise.resolve(value);
|
|
289
|
+
return value;
|
|
290
|
+
}
|
|
291
|
+
function mapModeValue(mode, value, mapFn) {
|
|
292
|
+
if (mode === "async") return Promise.resolve(value).then(mapFn);
|
|
293
|
+
if (value instanceof Promise) throw new TypeError("Synchronous mode cannot map Promise value.");
|
|
294
|
+
return mapFn(value);
|
|
295
|
+
}
|
|
289
296
|
/**
|
|
290
297
|
* Helper function to get value from config or default.
|
|
291
298
|
* Checks both annotations (for top-level parsers) and the active config
|
package/dist/index.js
CHANGED
|
@@ -215,25 +215,25 @@ function bindConfig(parser, options) {
|
|
|
215
215
|
...context,
|
|
216
216
|
state: innerState
|
|
217
217
|
} : context;
|
|
218
|
-
const processResult = (result
|
|
219
|
-
if (result
|
|
220
|
-
const cliConsumed = result
|
|
218
|
+
const processResult = (result) => {
|
|
219
|
+
if (result.success) {
|
|
220
|
+
const cliConsumed = result.consumed.length > 0;
|
|
221
221
|
const newState$1 = {
|
|
222
222
|
[configBindStateKey]: true,
|
|
223
223
|
hasCliValue: cliConsumed,
|
|
224
|
-
cliState: result
|
|
224
|
+
cliState: result.next.state,
|
|
225
225
|
...annotations && { [annotationKey]: annotations }
|
|
226
226
|
};
|
|
227
227
|
return {
|
|
228
228
|
success: true,
|
|
229
229
|
next: {
|
|
230
|
-
...result
|
|
230
|
+
...result.next,
|
|
231
231
|
state: newState$1
|
|
232
232
|
},
|
|
233
|
-
consumed: result
|
|
233
|
+
consumed: result.consumed
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
|
-
if (result
|
|
236
|
+
if (result.consumed > 0) return result;
|
|
237
237
|
const newState = {
|
|
238
238
|
[configBindStateKey]: true,
|
|
239
239
|
hasCliValue: false,
|
|
@@ -248,13 +248,11 @@ function bindConfig(parser, options) {
|
|
|
248
248
|
consumed: []
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
|
-
|
|
252
|
-
if (result instanceof Promise) return result.then(processResult);
|
|
253
|
-
return processResult(result);
|
|
251
|
+
return mapModeValue(parser.$mode, parser.parse(innerContext), processResult);
|
|
254
252
|
},
|
|
255
253
|
complete: (state) => {
|
|
256
254
|
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
257
|
-
return getConfigOrDefault(state, options);
|
|
255
|
+
return wrapForMode(parser.$mode, getConfigOrDefault(state, options));
|
|
258
256
|
},
|
|
259
257
|
suggest: parser.suggest,
|
|
260
258
|
getDocFragments(state, upperDefaultValue) {
|
|
@@ -263,6 +261,15 @@ function bindConfig(parser, options) {
|
|
|
263
261
|
}
|
|
264
262
|
};
|
|
265
263
|
}
|
|
264
|
+
function wrapForMode(mode, value) {
|
|
265
|
+
if (mode === "async") return Promise.resolve(value);
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
function mapModeValue(mode, value, mapFn) {
|
|
269
|
+
if (mode === "async") return Promise.resolve(value).then(mapFn);
|
|
270
|
+
if (value instanceof Promise) throw new TypeError("Synchronous mode cannot map Promise value.");
|
|
271
|
+
return mapFn(value);
|
|
272
|
+
}
|
|
266
273
|
/**
|
|
267
274
|
* Helper function to get value from config or default.
|
|
268
275
|
* Checks both annotations (for top-level parsers) and the active config
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/config",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.467+6cd2594b",
|
|
4
4
|
"description": "Configuration file support for Optique with Standard Schema validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@standard-schema/spec": "^1.1.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@optique/core": "1.0.0-dev.
|
|
62
|
+
"@optique/core": "1.0.0-dev.467+6cd2594b"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"tsdown": "^0.13.0",
|
|
68
68
|
"typescript": "^5.8.3",
|
|
69
69
|
"zod": "^3.25.0 || ^4.0.0",
|
|
70
|
-
"@optique/env": "1.0.0-dev.
|
|
70
|
+
"@optique/env": "1.0.0-dev.467+6cd2594b"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "tsdown",
|