@optique/config 1.0.0-dev.1818 → 1.0.0-dev.1826

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 CHANGED
@@ -30,64 +30,10 @@ const __optique_core_mode_dispatch = __toESM(require("@optique/core/mode-dispatc
30
30
 
31
31
  //#region src/index.ts
32
32
  const phase2UndefinedParsedValueKey = Symbol("@optique/config/phase2UndefinedParsedValue");
33
- /**
34
- * Internal registry for active config data during config context execution.
35
- * This is a workaround for the limitation that object() doesn't propagate
36
- * annotations to child field parsers.
37
- * @internal
38
- */
39
- const activeConfigRegistry = /* @__PURE__ */ new Map();
40
- /**
41
- * Internal registry for active config metadata during config context execution.
42
- * @internal
43
- */
44
- const activeConfigMetaRegistry = /* @__PURE__ */ new Map();
45
33
  const phase1ConfigAnnotationMarker = Symbol("@optique/config/phase1Annotation");
46
34
  function isPhase2UndefinedParsedValue(value) {
47
35
  return value != null && typeof value === "object" && phase2UndefinedParsedValueKey in value;
48
36
  }
49
- /**
50
- * Sets active config data for a context.
51
- * @internal
52
- */
53
- function setActiveConfig(contextId, data) {
54
- activeConfigRegistry.set(contextId, data);
55
- }
56
- /**
57
- * Gets active config data for a context.
58
- * @internal
59
- */
60
- function getActiveConfig(contextId) {
61
- return activeConfigRegistry.get(contextId);
62
- }
63
- /**
64
- * Clears active config data for a context.
65
- * @internal
66
- */
67
- function clearActiveConfig(contextId) {
68
- activeConfigRegistry.delete(contextId);
69
- }
70
- /**
71
- * Sets active config metadata for a context.
72
- * @internal
73
- */
74
- function setActiveConfigMeta(contextId, meta) {
75
- activeConfigMetaRegistry.set(contextId, meta);
76
- }
77
- /**
78
- * Gets active config metadata for a context.
79
- * @internal
80
- */
81
- function getActiveConfigMeta(contextId) {
82
- return activeConfigMetaRegistry.get(contextId);
83
- }
84
- /**
85
- * Clears active config metadata for a context.
86
- * @internal
87
- */
88
- function clearActiveConfigMeta(contextId) {
89
- activeConfigMetaRegistry.delete(contextId);
90
- }
91
37
  function getTypeName(value) {
92
38
  if (value === null) return "null";
93
39
  if (Array.isArray(value)) return "array";
@@ -149,6 +95,10 @@ function validateWithSchema(schema, rawData) {
149
95
  * The config context implements the `SourceContext` interface and can be used
150
96
  * with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
151
97
  * *@optique/run* to provide configuration file support.
98
+ * When calling `context.getAnnotations()` manually, pass the returned
99
+ * annotations to low-level APIs such as `parse()`, `parseAsync()`,
100
+ * `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
101
+ * `getAnnotations()` by itself does not affect later parses.
152
102
  *
153
103
  * @template T The output type of the config schema.
154
104
  * @template TConfigMeta The metadata type for config sources.
@@ -197,21 +147,13 @@ function createConfigContext(options) {
197
147
  if (!opts.load && opts.getConfigPath !== void 0 && typeof opts.getConfigPath !== "function") throw new TypeError(`Expected getConfigPath to be a function, but got: ${getTypeName(opts.getConfigPath)}.`);
198
148
  const parsedValue = isPhase2UndefinedParsedValue(parsed) ? void 0 : parsed;
199
149
  const parsedPlaceholder = parsedValue;
200
- const emptyAnnotations = () => {
201
- clearActiveConfig(contextId);
202
- clearActiveConfigMeta(contextId);
203
- return {};
204
- };
150
+ const emptyAnnotations = () => ({});
205
151
  const buildAnnotations = (configData, configMeta) => {
206
152
  if (configData === void 0 || configData === null) return emptyAnnotations();
207
- setActiveConfig(contextId, configData);
208
- if (configMeta !== void 0) {
209
- setActiveConfigMeta(contextId, configMeta);
210
- return { [contextId]: {
211
- data: configData,
212
- meta: configMeta
213
- } };
214
- }
153
+ if (configMeta !== void 0) return { [contextId]: {
154
+ data: configData,
155
+ meta: configMeta
156
+ } };
215
157
  return { [contextId]: { data: configData } };
216
158
  };
217
159
  const validateAndBuildAnnotations = (rawData, configMeta) => {
@@ -257,10 +199,7 @@ function createConfigContext(options) {
257
199
  }
258
200
  return emptyAnnotations();
259
201
  },
260
- [Symbol.dispose]() {
261
- clearActiveConfig(contextId);
262
- clearActiveConfigMeta(contextId);
263
- }
202
+ [Symbol.dispose]() {}
264
203
  };
265
204
  return context;
266
205
  }
@@ -438,9 +377,7 @@ function bindConfig(parser, options) {
438
377
  }
439
378
  /**
440
379
  * Helper function to get value from config or default.
441
- * Checks both annotations (for top-level parsers) and the active config
442
- * registry (for parsers nested inside object() when used with context-aware
443
- * runners).
380
+ * Reads only from explicit annotations carried by the current parse state.
444
381
  *
445
382
  * When `innerParser.validateValue` is available, the returned fallback
446
383
  * value is routed through it so that the inner CLI parser's constraints
@@ -462,12 +399,8 @@ function getConfigOrDefault(state, options, mode, innerParser) {
462
399
  const annotations = (0, __optique_core_annotations.getAnnotations)(state);
463
400
  const contextId = options.context.id;
464
401
  const annotationValue = annotations?.[contextId];
465
- let configData = annotationValue?.data;
466
- let configMeta = annotationValue?.meta;
467
- if (configData === void 0 || configData === null) {
468
- configData = getActiveConfig(contextId);
469
- configMeta = getActiveConfigMeta(contextId);
470
- }
402
+ const configData = annotationValue?.data;
403
+ const configMeta = annotationValue?.meta;
471
404
  let configValue;
472
405
  if (configData !== void 0 && configData !== null) if (typeof options.key === "function") {
473
406
  configValue = options.key(configData, configMeta);
@@ -503,10 +436,9 @@ function validateFallbackValue(mode, innerParser, value) {
503
436
  /**
504
437
  * Resolves a config-backed dependency source with fallback priority.
505
438
  *
506
- * This first checks annotations or the active config registry via
507
- * {@link getConfigOrDefault}. If no config-backed value is available, it falls
508
- * back to `options.default` and finally delegates to the wrapped parser's
509
- * source extractor.
439
+ * This first checks annotations via {@link getConfigOrDefault}. If no
440
+ * config-backed value is available, it falls back to `options.default` and
441
+ * finally delegates to the wrapped parser's source extractor.
510
442
  *
511
443
  * When `innerParser` exposes `validateValue`, the returned fallback is
512
444
  * routed through it so that the inner CLI parser's constraints are
@@ -534,7 +466,7 @@ function getConfigSourceValue(state, options, innerState, extractInnerSourceValu
534
466
  const annotations = (0, __optique_core_annotations.getAnnotations)(state);
535
467
  const contextId = options.context.id;
536
468
  const annotationValue = annotations?.[contextId];
537
- const configData = annotationValue?.data ?? getActiveConfig(contextId);
469
+ const configData = annotationValue?.data;
538
470
  const validateFallback = (parsed) => {
539
471
  if (!parsed.success) return parsed;
540
472
  if (innerParser == null || typeof innerParser.validateValue !== "function") return parsed;
@@ -553,10 +485,4 @@ function getConfigSourceValue(state, options, innerState, extractInnerSourceValu
553
485
 
554
486
  //#endregion
555
487
  exports.bindConfig = bindConfig;
556
- exports.clearActiveConfig = clearActiveConfig;
557
- exports.clearActiveConfigMeta = clearActiveConfigMeta;
558
- exports.createConfigContext = createConfigContext;
559
- exports.getActiveConfig = getActiveConfig;
560
- exports.getActiveConfigMeta = getActiveConfigMeta;
561
- exports.setActiveConfig = setActiveConfig;
562
- exports.setActiveConfigMeta = setActiveConfigMeta;
488
+ exports.createConfigContext = createConfigContext;
package/dist/index.d.cts CHANGED
@@ -19,36 +19,6 @@ interface ConfigMeta {
19
19
  */
20
20
  readonly configPath: string;
21
21
  }
22
- /**
23
- * Sets active config data for a context.
24
- * @internal
25
- */
26
- declare function setActiveConfig<T>(contextId: symbol, data: T): void;
27
- /**
28
- * Gets active config data for a context.
29
- * @internal
30
- */
31
- declare function getActiveConfig<T>(contextId: symbol): T | undefined;
32
- /**
33
- * Clears active config data for a context.
34
- * @internal
35
- */
36
- declare function clearActiveConfig(contextId: symbol): void;
37
- /**
38
- * Sets active config metadata for a context.
39
- * @internal
40
- */
41
- declare function setActiveConfigMeta<T>(contextId: symbol, meta: T): void;
42
- /**
43
- * Gets active config metadata for a context.
44
- * @internal
45
- */
46
- declare function getActiveConfigMeta<T>(contextId: symbol): T | undefined;
47
- /**
48
- * Clears active config metadata for a context.
49
- * @internal
50
- */
51
- declare function clearActiveConfigMeta(contextId: symbol): void;
52
22
  /**
53
23
  * Options for creating a config context.
54
24
  *
@@ -157,6 +127,10 @@ interface ConfigContext<T, TConfigMeta = ConfigMeta> extends SourceContext<Confi
157
127
  * The config context implements the `SourceContext` interface and can be used
158
128
  * with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
159
129
  * *@optique/run* to provide configuration file support.
130
+ * When calling `context.getAnnotations()` manually, pass the returned
131
+ * annotations to low-level APIs such as `parse()`, `parseAsync()`,
132
+ * `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
133
+ * `getAnnotations()` by itself does not affect later parses.
160
134
  *
161
135
  * @template T The output type of the config schema.
162
136
  * @template TConfigMeta The metadata type for config sources.
@@ -245,4 +219,4 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
245
219
  */
246
220
  declare function bindConfig<M extends "sync" | "async", TValue, TState, T, TConfigMeta = ConfigMeta>(parser: Parser<M, TValue, TState>, options: BindConfigOptions<T, TValue, TConfigMeta>): Parser<M, TValue, TState>;
247
221
  //#endregion
248
- export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, clearActiveConfig, clearActiveConfigMeta, createConfigContext, getActiveConfig, getActiveConfigMeta, setActiveConfig, setActiveConfigMeta };
222
+ export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, createConfigContext };
package/dist/index.d.ts CHANGED
@@ -19,36 +19,6 @@ interface ConfigMeta {
19
19
  */
20
20
  readonly configPath: string;
21
21
  }
22
- /**
23
- * Sets active config data for a context.
24
- * @internal
25
- */
26
- declare function setActiveConfig<T>(contextId: symbol, data: T): void;
27
- /**
28
- * Gets active config data for a context.
29
- * @internal
30
- */
31
- declare function getActiveConfig<T>(contextId: symbol): T | undefined;
32
- /**
33
- * Clears active config data for a context.
34
- * @internal
35
- */
36
- declare function clearActiveConfig(contextId: symbol): void;
37
- /**
38
- * Sets active config metadata for a context.
39
- * @internal
40
- */
41
- declare function setActiveConfigMeta<T>(contextId: symbol, meta: T): void;
42
- /**
43
- * Gets active config metadata for a context.
44
- * @internal
45
- */
46
- declare function getActiveConfigMeta<T>(contextId: symbol): T | undefined;
47
- /**
48
- * Clears active config metadata for a context.
49
- * @internal
50
- */
51
- declare function clearActiveConfigMeta(contextId: symbol): void;
52
22
  /**
53
23
  * Options for creating a config context.
54
24
  *
@@ -157,6 +127,10 @@ interface ConfigContext<T, TConfigMeta = ConfigMeta> extends SourceContext<Confi
157
127
  * The config context implements the `SourceContext` interface and can be used
158
128
  * with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
159
129
  * *@optique/run* to provide configuration file support.
130
+ * When calling `context.getAnnotations()` manually, pass the returned
131
+ * annotations to low-level APIs such as `parse()`, `parseAsync()`,
132
+ * `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
133
+ * `getAnnotations()` by itself does not affect later parses.
160
134
  *
161
135
  * @template T The output type of the config schema.
162
136
  * @template TConfigMeta The metadata type for config sources.
@@ -245,4 +219,4 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
245
219
  */
246
220
  declare function bindConfig<M extends "sync" | "async", TValue, TState, T, TConfigMeta = ConfigMeta>(parser: Parser<M, TValue, TState>, options: BindConfigOptions<T, TValue, TConfigMeta>): Parser<M, TValue, TState>;
247
221
  //#endregion
248
- export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, clearActiveConfig, clearActiveConfigMeta, createConfigContext, getActiveConfig, getActiveConfigMeta, setActiveConfig, setActiveConfigMeta };
222
+ export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, createConfigContext };
package/dist/index.js CHANGED
@@ -7,64 +7,10 @@ import { mapModeValue, wrapForMode } from "@optique/core/mode-dispatch";
7
7
 
8
8
  //#region src/index.ts
9
9
  const phase2UndefinedParsedValueKey = Symbol("@optique/config/phase2UndefinedParsedValue");
10
- /**
11
- * Internal registry for active config data during config context execution.
12
- * This is a workaround for the limitation that object() doesn't propagate
13
- * annotations to child field parsers.
14
- * @internal
15
- */
16
- const activeConfigRegistry = /* @__PURE__ */ new Map();
17
- /**
18
- * Internal registry for active config metadata during config context execution.
19
- * @internal
20
- */
21
- const activeConfigMetaRegistry = /* @__PURE__ */ new Map();
22
10
  const phase1ConfigAnnotationMarker = Symbol("@optique/config/phase1Annotation");
23
11
  function isPhase2UndefinedParsedValue(value) {
24
12
  return value != null && typeof value === "object" && phase2UndefinedParsedValueKey in value;
25
13
  }
26
- /**
27
- * Sets active config data for a context.
28
- * @internal
29
- */
30
- function setActiveConfig(contextId, data) {
31
- activeConfigRegistry.set(contextId, data);
32
- }
33
- /**
34
- * Gets active config data for a context.
35
- * @internal
36
- */
37
- function getActiveConfig(contextId) {
38
- return activeConfigRegistry.get(contextId);
39
- }
40
- /**
41
- * Clears active config data for a context.
42
- * @internal
43
- */
44
- function clearActiveConfig(contextId) {
45
- activeConfigRegistry.delete(contextId);
46
- }
47
- /**
48
- * Sets active config metadata for a context.
49
- * @internal
50
- */
51
- function setActiveConfigMeta(contextId, meta) {
52
- activeConfigMetaRegistry.set(contextId, meta);
53
- }
54
- /**
55
- * Gets active config metadata for a context.
56
- * @internal
57
- */
58
- function getActiveConfigMeta(contextId) {
59
- return activeConfigMetaRegistry.get(contextId);
60
- }
61
- /**
62
- * Clears active config metadata for a context.
63
- * @internal
64
- */
65
- function clearActiveConfigMeta(contextId) {
66
- activeConfigMetaRegistry.delete(contextId);
67
- }
68
14
  function getTypeName(value) {
69
15
  if (value === null) return "null";
70
16
  if (Array.isArray(value)) return "array";
@@ -126,6 +72,10 @@ function validateWithSchema(schema, rawData) {
126
72
  * The config context implements the `SourceContext` interface and can be used
127
73
  * with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
128
74
  * *@optique/run* to provide configuration file support.
75
+ * When calling `context.getAnnotations()` manually, pass the returned
76
+ * annotations to low-level APIs such as `parse()`, `parseAsync()`,
77
+ * `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
78
+ * `getAnnotations()` by itself does not affect later parses.
129
79
  *
130
80
  * @template T The output type of the config schema.
131
81
  * @template TConfigMeta The metadata type for config sources.
@@ -174,21 +124,13 @@ function createConfigContext(options) {
174
124
  if (!opts.load && opts.getConfigPath !== void 0 && typeof opts.getConfigPath !== "function") throw new TypeError(`Expected getConfigPath to be a function, but got: ${getTypeName(opts.getConfigPath)}.`);
175
125
  const parsedValue = isPhase2UndefinedParsedValue(parsed) ? void 0 : parsed;
176
126
  const parsedPlaceholder = parsedValue;
177
- const emptyAnnotations = () => {
178
- clearActiveConfig(contextId);
179
- clearActiveConfigMeta(contextId);
180
- return {};
181
- };
127
+ const emptyAnnotations = () => ({});
182
128
  const buildAnnotations = (configData, configMeta) => {
183
129
  if (configData === void 0 || configData === null) return emptyAnnotations();
184
- setActiveConfig(contextId, configData);
185
- if (configMeta !== void 0) {
186
- setActiveConfigMeta(contextId, configMeta);
187
- return { [contextId]: {
188
- data: configData,
189
- meta: configMeta
190
- } };
191
- }
130
+ if (configMeta !== void 0) return { [contextId]: {
131
+ data: configData,
132
+ meta: configMeta
133
+ } };
192
134
  return { [contextId]: { data: configData } };
193
135
  };
194
136
  const validateAndBuildAnnotations = (rawData, configMeta) => {
@@ -234,10 +176,7 @@ function createConfigContext(options) {
234
176
  }
235
177
  return emptyAnnotations();
236
178
  },
237
- [Symbol.dispose]() {
238
- clearActiveConfig(contextId);
239
- clearActiveConfigMeta(contextId);
240
- }
179
+ [Symbol.dispose]() {}
241
180
  };
242
181
  return context;
243
182
  }
@@ -415,9 +354,7 @@ function bindConfig(parser, options) {
415
354
  }
416
355
  /**
417
356
  * Helper function to get value from config or default.
418
- * Checks both annotations (for top-level parsers) and the active config
419
- * registry (for parsers nested inside object() when used with context-aware
420
- * runners).
357
+ * Reads only from explicit annotations carried by the current parse state.
421
358
  *
422
359
  * When `innerParser.validateValue` is available, the returned fallback
423
360
  * value is routed through it so that the inner CLI parser's constraints
@@ -439,12 +376,8 @@ function getConfigOrDefault(state, options, mode, innerParser) {
439
376
  const annotations = getAnnotations(state);
440
377
  const contextId = options.context.id;
441
378
  const annotationValue = annotations?.[contextId];
442
- let configData = annotationValue?.data;
443
- let configMeta = annotationValue?.meta;
444
- if (configData === void 0 || configData === null) {
445
- configData = getActiveConfig(contextId);
446
- configMeta = getActiveConfigMeta(contextId);
447
- }
379
+ const configData = annotationValue?.data;
380
+ const configMeta = annotationValue?.meta;
448
381
  let configValue;
449
382
  if (configData !== void 0 && configData !== null) if (typeof options.key === "function") {
450
383
  configValue = options.key(configData, configMeta);
@@ -480,10 +413,9 @@ function validateFallbackValue(mode, innerParser, value) {
480
413
  /**
481
414
  * Resolves a config-backed dependency source with fallback priority.
482
415
  *
483
- * This first checks annotations or the active config registry via
484
- * {@link getConfigOrDefault}. If no config-backed value is available, it falls
485
- * back to `options.default` and finally delegates to the wrapped parser's
486
- * source extractor.
416
+ * This first checks annotations via {@link getConfigOrDefault}. If no
417
+ * config-backed value is available, it falls back to `options.default` and
418
+ * finally delegates to the wrapped parser's source extractor.
487
419
  *
488
420
  * When `innerParser` exposes `validateValue`, the returned fallback is
489
421
  * routed through it so that the inner CLI parser's constraints are
@@ -511,7 +443,7 @@ function getConfigSourceValue(state, options, innerState, extractInnerSourceValu
511
443
  const annotations = getAnnotations(state);
512
444
  const contextId = options.context.id;
513
445
  const annotationValue = annotations?.[contextId];
514
- const configData = annotationValue?.data ?? getActiveConfig(contextId);
446
+ const configData = annotationValue?.data;
515
447
  const validateFallback = (parsed) => {
516
448
  if (!parsed.success) return parsed;
517
449
  if (innerParser == null || typeof innerParser.validateValue !== "function") return parsed;
@@ -529,4 +461,4 @@ function getConfigSourceValue(state, options, innerState, extractInnerSourceValu
529
461
  }
530
462
 
531
463
  //#endregion
532
- export { bindConfig, clearActiveConfig, clearActiveConfigMeta, createConfigContext, getActiveConfig, getActiveConfigMeta, setActiveConfig, setActiveConfigMeta };
464
+ export { bindConfig, createConfigContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/config",
3
- "version": "1.0.0-dev.1818+1aa43bd4",
3
+ "version": "1.0.0-dev.1826+dae48c84",
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.1818+1aa43bd4"
62
+ "@optique/core": "1.0.0-dev.1826+dae48c84"
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.1818+1aa43bd4"
70
+ "@optique/env": "1.0.0-dev.1826+dae48c84"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsdown",