@optique/config 1.0.0-dev.1903 → 1.0.0-dev.1970
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 +19 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -18
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -23,10 +23,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
const node_fs = __toESM(require("node:fs"));
|
|
25
25
|
const node_path = __toESM(require("node:path"));
|
|
26
|
-
const __optique_core_parser = __toESM(require("@optique/core/parser"));
|
|
27
26
|
const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
|
|
27
|
+
const __optique_core_extension = __toESM(require("@optique/core/extension"));
|
|
28
28
|
const __optique_core_message = __toESM(require("@optique/core/message"));
|
|
29
|
-
const __optique_core_mode_dispatch = __toESM(require("@optique/core/mode-dispatch"));
|
|
30
29
|
|
|
31
30
|
//#region src/index.ts
|
|
32
31
|
const phase1ConfigAnnotationMarker = Symbol("@optique/config/phase1Annotation");
|
|
@@ -250,13 +249,12 @@ function bindConfig(parser, options) {
|
|
|
250
249
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
251
250
|
return annotations?.[options.context.id] === phase1ConfigAnnotationMarker;
|
|
252
251
|
}
|
|
253
|
-
const getSuggestInnerState = (state) => isConfigBindState(state) ? state.cliState === void 0 ? (0,
|
|
252
|
+
const getSuggestInnerState = (state) => isConfigBindState(state) ? state.cliState === void 0 ? (0, __optique_core_extension.inheritAnnotations)(state, parser.initialState) : state.cliState : state;
|
|
254
253
|
const boundParser = {
|
|
255
|
-
|
|
254
|
+
mode: parser.mode,
|
|
256
255
|
$valueType: parser.$valueType,
|
|
257
256
|
$stateType: parser.$stateType,
|
|
258
257
|
priority: parser.priority,
|
|
259
|
-
[__optique_core_parser.unmatchedNonCliDependencySourceStateMarker]: true,
|
|
260
258
|
usage: options.default !== void 0 ? [{
|
|
261
259
|
type: "optional",
|
|
262
260
|
terms: parser.usage
|
|
@@ -266,7 +264,7 @@ function bindConfig(parser, options) {
|
|
|
266
264
|
initialState: parser.initialState,
|
|
267
265
|
getSuggestRuntimeNodes(state, path) {
|
|
268
266
|
const innerState = getSuggestInnerState(state);
|
|
269
|
-
return (0,
|
|
267
|
+
return (0, __optique_core_extension.delegateSuggestNodes)(parser, boundParser, state, path, innerState);
|
|
270
268
|
},
|
|
271
269
|
parse: (context) => {
|
|
272
270
|
const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
|
|
@@ -278,12 +276,11 @@ function bindConfig(parser, options) {
|
|
|
278
276
|
const processResult = (result) => {
|
|
279
277
|
if (result.success) {
|
|
280
278
|
const cliConsumed = result.consumed.length > 0;
|
|
281
|
-
const newState$1 = {
|
|
279
|
+
const newState$1 = (0, __optique_core_extension.injectAnnotations)({
|
|
282
280
|
[configBindStateKey]: true,
|
|
283
281
|
hasCliValue: cliConsumed,
|
|
284
|
-
cliState: result.next.state
|
|
285
|
-
|
|
286
|
-
};
|
|
282
|
+
cliState: result.next.state
|
|
283
|
+
}, annotations);
|
|
287
284
|
return {
|
|
288
285
|
success: true,
|
|
289
286
|
...result.provisional ? { provisional: true } : {},
|
|
@@ -295,11 +292,10 @@ function bindConfig(parser, options) {
|
|
|
295
292
|
};
|
|
296
293
|
}
|
|
297
294
|
if (result.consumed > 0) return result;
|
|
298
|
-
const newState = {
|
|
295
|
+
const newState = (0, __optique_core_extension.injectAnnotations)({
|
|
299
296
|
[configBindStateKey]: true,
|
|
300
|
-
hasCliValue: false
|
|
301
|
-
|
|
302
|
-
};
|
|
297
|
+
hasCliValue: false
|
|
298
|
+
}, annotations);
|
|
303
299
|
return {
|
|
304
300
|
success: true,
|
|
305
301
|
next: {
|
|
@@ -309,11 +305,11 @@ function bindConfig(parser, options) {
|
|
|
309
305
|
consumed: []
|
|
310
306
|
};
|
|
311
307
|
};
|
|
312
|
-
return (0,
|
|
308
|
+
return (0, __optique_core_extension.mapModeValue)(parser.mode, parser.parse(innerContext), processResult);
|
|
313
309
|
},
|
|
314
310
|
complete: (state, exec) => {
|
|
315
311
|
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState, exec);
|
|
316
|
-
return getConfigOrDefault(state, options, parser
|
|
312
|
+
return getConfigOrDefault(state, options, parser.mode, parser);
|
|
317
313
|
},
|
|
318
314
|
suggest: (context, prefix) => {
|
|
319
315
|
const innerState = getSuggestInnerState(context.state);
|
|
@@ -329,6 +325,10 @@ function bindConfig(parser, options) {
|
|
|
329
325
|
return parser.getDocFragments(state, defaultValue);
|
|
330
326
|
}
|
|
331
327
|
};
|
|
328
|
+
(0, __optique_core_extension.defineTraits)(boundParser, {
|
|
329
|
+
inheritsAnnotations: true,
|
|
330
|
+
completesFromSource: true
|
|
331
|
+
});
|
|
332
332
|
if ("placeholder" in parser) Object.defineProperty(boundParser, "placeholder", {
|
|
333
333
|
get() {
|
|
334
334
|
return parser.placeholder;
|
|
@@ -346,8 +346,7 @@ function bindConfig(parser, options) {
|
|
|
346
346
|
configurable: true,
|
|
347
347
|
enumerable: false
|
|
348
348
|
});
|
|
349
|
-
(0,
|
|
350
|
-
const dependencyMetadata = (0, __optique_core_parser.composeWrappedSourceMetadata)(parser.dependencyMetadata, (sourceMetadata) => ({
|
|
349
|
+
const dependencyMetadata = (0, __optique_core_extension.mapSourceMetadata)(parser, (sourceMetadata) => ({
|
|
351
350
|
...sourceMetadata,
|
|
352
351
|
getMissingSourceValue: sourceMetadata.preservesSourceValue !== false && options.default !== void 0 ? () => {
|
|
353
352
|
if (typeof parser.validateValue === "function") return parser.validateValue(options.default);
|
|
@@ -407,7 +406,7 @@ function getConfigOrDefault(state, options, mode, innerParser) {
|
|
|
407
406
|
} else configValue = configData[options.key];
|
|
408
407
|
if (configValue !== void 0) return validateFallbackValue(mode, innerParser, configValue);
|
|
409
408
|
if (options.default !== void 0) return validateFallbackValue(mode, innerParser, options.default);
|
|
410
|
-
return (0,
|
|
409
|
+
return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
411
410
|
success: false,
|
|
412
411
|
error: __optique_core_message.message`Missing required configuration value.`
|
|
413
412
|
});
|
|
@@ -426,7 +425,7 @@ function getConfigOrDefault(state, options, mode, innerParser) {
|
|
|
426
425
|
* thrown by the hook escapes through this path.
|
|
427
426
|
*/
|
|
428
427
|
function validateFallbackValue(mode, innerParser, value) {
|
|
429
|
-
if (innerParser == null || typeof innerParser.validateValue !== "function") return (0,
|
|
428
|
+
if (innerParser == null || typeof innerParser.validateValue !== "function") return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
430
429
|
success: true,
|
|
431
430
|
value
|
|
432
431
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { getAnnotations } from "@optique/core/annotations";
|
|
4
|
+
import { defineTraits, delegateSuggestNodes, inheritAnnotations, injectAnnotations, mapModeValue, mapSourceMetadata, wrapForMode } from "@optique/core/extension";
|
|
5
5
|
import { message } from "@optique/core/message";
|
|
6
|
-
import { mapModeValue, wrapForMode } from "@optique/core/mode-dispatch";
|
|
7
6
|
|
|
8
7
|
//#region src/index.ts
|
|
9
8
|
const phase1ConfigAnnotationMarker = Symbol("@optique/config/phase1Annotation");
|
|
@@ -229,11 +228,10 @@ function bindConfig(parser, options) {
|
|
|
229
228
|
}
|
|
230
229
|
const getSuggestInnerState = (state) => isConfigBindState(state) ? state.cliState === void 0 ? inheritAnnotations(state, parser.initialState) : state.cliState : state;
|
|
231
230
|
const boundParser = {
|
|
232
|
-
|
|
231
|
+
mode: parser.mode,
|
|
233
232
|
$valueType: parser.$valueType,
|
|
234
233
|
$stateType: parser.$stateType,
|
|
235
234
|
priority: parser.priority,
|
|
236
|
-
[unmatchedNonCliDependencySourceStateMarker]: true,
|
|
237
235
|
usage: options.default !== void 0 ? [{
|
|
238
236
|
type: "optional",
|
|
239
237
|
terms: parser.usage
|
|
@@ -243,7 +241,7 @@ function bindConfig(parser, options) {
|
|
|
243
241
|
initialState: parser.initialState,
|
|
244
242
|
getSuggestRuntimeNodes(state, path) {
|
|
245
243
|
const innerState = getSuggestInnerState(state);
|
|
246
|
-
return
|
|
244
|
+
return delegateSuggestNodes(parser, boundParser, state, path, innerState);
|
|
247
245
|
},
|
|
248
246
|
parse: (context) => {
|
|
249
247
|
const annotations = getAnnotations(context.state);
|
|
@@ -255,12 +253,11 @@ function bindConfig(parser, options) {
|
|
|
255
253
|
const processResult = (result) => {
|
|
256
254
|
if (result.success) {
|
|
257
255
|
const cliConsumed = result.consumed.length > 0;
|
|
258
|
-
const newState$1 = {
|
|
256
|
+
const newState$1 = injectAnnotations({
|
|
259
257
|
[configBindStateKey]: true,
|
|
260
258
|
hasCliValue: cliConsumed,
|
|
261
|
-
cliState: result.next.state
|
|
262
|
-
|
|
263
|
-
};
|
|
259
|
+
cliState: result.next.state
|
|
260
|
+
}, annotations);
|
|
264
261
|
return {
|
|
265
262
|
success: true,
|
|
266
263
|
...result.provisional ? { provisional: true } : {},
|
|
@@ -272,11 +269,10 @@ function bindConfig(parser, options) {
|
|
|
272
269
|
};
|
|
273
270
|
}
|
|
274
271
|
if (result.consumed > 0) return result;
|
|
275
|
-
const newState = {
|
|
272
|
+
const newState = injectAnnotations({
|
|
276
273
|
[configBindStateKey]: true,
|
|
277
|
-
hasCliValue: false
|
|
278
|
-
|
|
279
|
-
};
|
|
274
|
+
hasCliValue: false
|
|
275
|
+
}, annotations);
|
|
280
276
|
return {
|
|
281
277
|
success: true,
|
|
282
278
|
next: {
|
|
@@ -286,11 +282,11 @@ function bindConfig(parser, options) {
|
|
|
286
282
|
consumed: []
|
|
287
283
|
};
|
|
288
284
|
};
|
|
289
|
-
return mapModeValue(parser
|
|
285
|
+
return mapModeValue(parser.mode, parser.parse(innerContext), processResult);
|
|
290
286
|
},
|
|
291
287
|
complete: (state, exec) => {
|
|
292
288
|
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState, exec);
|
|
293
|
-
return getConfigOrDefault(state, options, parser
|
|
289
|
+
return getConfigOrDefault(state, options, parser.mode, parser);
|
|
294
290
|
},
|
|
295
291
|
suggest: (context, prefix) => {
|
|
296
292
|
const innerState = getSuggestInnerState(context.state);
|
|
@@ -306,6 +302,10 @@ function bindConfig(parser, options) {
|
|
|
306
302
|
return parser.getDocFragments(state, defaultValue);
|
|
307
303
|
}
|
|
308
304
|
};
|
|
305
|
+
defineTraits(boundParser, {
|
|
306
|
+
inheritsAnnotations: true,
|
|
307
|
+
completesFromSource: true
|
|
308
|
+
});
|
|
309
309
|
if ("placeholder" in parser) Object.defineProperty(boundParser, "placeholder", {
|
|
310
310
|
get() {
|
|
311
311
|
return parser.placeholder;
|
|
@@ -323,8 +323,7 @@ function bindConfig(parser, options) {
|
|
|
323
323
|
configurable: true,
|
|
324
324
|
enumerable: false
|
|
325
325
|
});
|
|
326
|
-
|
|
327
|
-
const dependencyMetadata = composeWrappedSourceMetadata(parser.dependencyMetadata, (sourceMetadata) => ({
|
|
326
|
+
const dependencyMetadata = mapSourceMetadata(parser, (sourceMetadata) => ({
|
|
328
327
|
...sourceMetadata,
|
|
329
328
|
getMissingSourceValue: sourceMetadata.preservesSourceValue !== false && options.default !== void 0 ? () => {
|
|
330
329
|
if (typeof parser.validateValue === "function") return parser.validateValue(options.default);
|
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.1970+0182ae32",
|
|
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.1970+0182ae32"
|
|
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.1970+0182ae32"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "tsdown",
|