@optique/env 1.0.0-dev.1810 → 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 +12 -39
- package/dist/index.d.cts +6 -23
- package/dist/index.d.ts +6 -23
- package/dist/index.js +12 -36
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -28,31 +28,6 @@ const __optique_core_parser = __toESM(require("@optique/core/parser"));
|
|
|
28
28
|
const __optique_core_valueparser = __toESM(require("@optique/core/valueparser"));
|
|
29
29
|
|
|
30
30
|
//#region src/index.ts
|
|
31
|
-
const activeEnvSourceRegistry = /* @__PURE__ */ new Map();
|
|
32
|
-
/**
|
|
33
|
-
* Sets active environment source data for a context.
|
|
34
|
-
*
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
function setActiveEnvSource(contextId, sourceData) {
|
|
38
|
-
activeEnvSourceRegistry.set(contextId, sourceData);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Gets active environment source data for a context.
|
|
42
|
-
*
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
function getActiveEnvSource(contextId) {
|
|
46
|
-
return activeEnvSourceRegistry.get(contextId);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Clears active environment source data for a context.
|
|
50
|
-
*
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
function clearActiveEnvSource(contextId) {
|
|
54
|
-
activeEnvSourceRegistry.delete(contextId);
|
|
55
|
-
}
|
|
56
31
|
function defaultEnvSource(key) {
|
|
57
32
|
const denoGlobal = globalThis.Deno;
|
|
58
33
|
if (typeof denoGlobal?.env?.get === "function") return denoGlobal.env.get(key);
|
|
@@ -62,6 +37,11 @@ function defaultEnvSource(key) {
|
|
|
62
37
|
/**
|
|
63
38
|
* Creates an environment context for use with Optique runners.
|
|
64
39
|
*
|
|
40
|
+
* When calling `context.getAnnotations()` manually, pass the returned
|
|
41
|
+
* annotations to low-level APIs such as `parse()`, `parseAsync()`,
|
|
42
|
+
* `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
|
|
43
|
+
* `getAnnotations()` by itself does not affect later parses.
|
|
44
|
+
*
|
|
65
45
|
* @param options Environment context options.
|
|
66
46
|
* @returns A context that provides environment source annotations.
|
|
67
47
|
* @throws {TypeError} If `prefix` is not a string.
|
|
@@ -86,12 +66,9 @@ function createEnvContext(options = {}) {
|
|
|
86
66
|
prefix,
|
|
87
67
|
source
|
|
88
68
|
};
|
|
89
|
-
setActiveEnvSource(contextId, sourceData);
|
|
90
69
|
return { [contextId]: sourceData };
|
|
91
70
|
},
|
|
92
|
-
[Symbol.dispose]() {
|
|
93
|
-
clearActiveEnvSource(contextId);
|
|
94
|
-
}
|
|
71
|
+
[Symbol.dispose]() {}
|
|
95
72
|
};
|
|
96
73
|
}
|
|
97
74
|
/**
|
|
@@ -274,7 +251,7 @@ function bindEnv(parser, options) {
|
|
|
274
251
|
*/
|
|
275
252
|
function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
276
253
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
277
|
-
const sourceData = annotations?.[options.context.id]
|
|
254
|
+
const sourceData = annotations?.[options.context.id];
|
|
278
255
|
const fullKey = `${sourceData?.prefix ?? options.context.prefix}${options.key}`;
|
|
279
256
|
const rawValue = sourceData?.source(fullKey);
|
|
280
257
|
const validateSync = (parsed) => {
|
|
@@ -322,10 +299,9 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
322
299
|
/**
|
|
323
300
|
* Resolves an env-backed dependency source with env and default fallbacks.
|
|
324
301
|
*
|
|
325
|
-
* This first checks annotations
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* extractor.
|
|
302
|
+
* This first checks annotations for the bound variable. If no env-backed value
|
|
303
|
+
* is available, it falls back to `options.default` and finally delegates to
|
|
304
|
+
* the wrapped parser's source extractor.
|
|
329
305
|
*
|
|
330
306
|
* When `innerParser` exposes a `validateValue` hook, env-sourced values
|
|
331
307
|
* and the configured default are re-validated against the inner parser's
|
|
@@ -350,7 +326,7 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
350
326
|
*/
|
|
351
327
|
function getEnvSourceValue(state, options, innerState, extractInnerSourceValue, innerParser) {
|
|
352
328
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
353
|
-
const sourceData = annotations?.[options.context.id]
|
|
329
|
+
const sourceData = annotations?.[options.context.id];
|
|
354
330
|
const fullKey = `${sourceData?.prefix ?? options.context.prefix}${options.key}`;
|
|
355
331
|
const rawValue = sourceData?.source(fullKey);
|
|
356
332
|
const validateFallback = (parsed) => {
|
|
@@ -442,7 +418,4 @@ function bool(options = {}) {
|
|
|
442
418
|
//#endregion
|
|
443
419
|
exports.bindEnv = bindEnv;
|
|
444
420
|
exports.bool = bool;
|
|
445
|
-
exports.
|
|
446
|
-
exports.createEnvContext = createEnvContext;
|
|
447
|
-
exports.getActiveEnvSource = getActiveEnvSource;
|
|
448
|
-
exports.setActiveEnvSource = setActiveEnvSource;
|
|
421
|
+
exports.createEnvContext = createEnvContext;
|
package/dist/index.d.cts
CHANGED
|
@@ -11,10 +11,6 @@ import { NonEmptyString, ValueParser } from "@optique/core/valueparser";
|
|
|
11
11
|
* @since 1.0.0
|
|
12
12
|
*/
|
|
13
13
|
type EnvSource = (key: string) => string | undefined;
|
|
14
|
-
interface EnvSourceData {
|
|
15
|
-
readonly prefix: string;
|
|
16
|
-
readonly source: EnvSource;
|
|
17
|
-
}
|
|
18
14
|
/**
|
|
19
15
|
* Context for environment-variable-based fallback values.
|
|
20
16
|
*
|
|
@@ -49,27 +45,14 @@ interface EnvContextOptions {
|
|
|
49
45
|
*/
|
|
50
46
|
readonly source?: EnvSource;
|
|
51
47
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Sets active environment source data for a context.
|
|
54
|
-
*
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
declare function setActiveEnvSource(contextId: symbol, sourceData: EnvSourceData): void;
|
|
58
|
-
/**
|
|
59
|
-
* Gets active environment source data for a context.
|
|
60
|
-
*
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
declare function getActiveEnvSource(contextId: symbol): EnvSourceData | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Clears active environment source data for a context.
|
|
66
|
-
*
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
declare function clearActiveEnvSource(contextId: symbol): void;
|
|
70
48
|
/**
|
|
71
49
|
* Creates an environment context for use with Optique runners.
|
|
72
50
|
*
|
|
51
|
+
* When calling `context.getAnnotations()` manually, pass the returned
|
|
52
|
+
* annotations to low-level APIs such as `parse()`, `parseAsync()`,
|
|
53
|
+
* `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
|
|
54
|
+
* `getAnnotations()` by itself does not affect later parses.
|
|
55
|
+
*
|
|
73
56
|
* @param options Environment context options.
|
|
74
57
|
* @returns A context that provides environment source annotations.
|
|
75
58
|
* @throws {TypeError} If `prefix` is not a string.
|
|
@@ -168,4 +151,4 @@ interface BoolOptions {
|
|
|
168
151
|
*/
|
|
169
152
|
declare function bool(options?: BoolOptions): ValueParser<"sync", boolean>;
|
|
170
153
|
//#endregion
|
|
171
|
-
export { BindEnvOptions, BoolOptions, EnvContext, EnvContextOptions, EnvSource, bindEnv, bool,
|
|
154
|
+
export { BindEnvOptions, BoolOptions, EnvContext, EnvContextOptions, EnvSource, bindEnv, bool, createEnvContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,10 +11,6 @@ import { SourceContext } from "@optique/core/context";
|
|
|
11
11
|
* @since 1.0.0
|
|
12
12
|
*/
|
|
13
13
|
type EnvSource = (key: string) => string | undefined;
|
|
14
|
-
interface EnvSourceData {
|
|
15
|
-
readonly prefix: string;
|
|
16
|
-
readonly source: EnvSource;
|
|
17
|
-
}
|
|
18
14
|
/**
|
|
19
15
|
* Context for environment-variable-based fallback values.
|
|
20
16
|
*
|
|
@@ -49,27 +45,14 @@ interface EnvContextOptions {
|
|
|
49
45
|
*/
|
|
50
46
|
readonly source?: EnvSource;
|
|
51
47
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Sets active environment source data for a context.
|
|
54
|
-
*
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
declare function setActiveEnvSource(contextId: symbol, sourceData: EnvSourceData): void;
|
|
58
|
-
/**
|
|
59
|
-
* Gets active environment source data for a context.
|
|
60
|
-
*
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
declare function getActiveEnvSource(contextId: symbol): EnvSourceData | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Clears active environment source data for a context.
|
|
66
|
-
*
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
|
-
declare function clearActiveEnvSource(contextId: symbol): void;
|
|
70
48
|
/**
|
|
71
49
|
* Creates an environment context for use with Optique runners.
|
|
72
50
|
*
|
|
51
|
+
* When calling `context.getAnnotations()` manually, pass the returned
|
|
52
|
+
* annotations to low-level APIs such as `parse()`, `parseAsync()`,
|
|
53
|
+
* `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
|
|
54
|
+
* `getAnnotations()` by itself does not affect later parses.
|
|
55
|
+
*
|
|
73
56
|
* @param options Environment context options.
|
|
74
57
|
* @returns A context that provides environment source annotations.
|
|
75
58
|
* @throws {TypeError} If `prefix` is not a string.
|
|
@@ -168,4 +151,4 @@ interface BoolOptions {
|
|
|
168
151
|
*/
|
|
169
152
|
declare function bool(options?: BoolOptions): ValueParser<"sync", boolean>;
|
|
170
153
|
//#endregion
|
|
171
|
-
export { BindEnvOptions, BoolOptions, EnvContext, EnvContextOptions, EnvSource, bindEnv, bool,
|
|
154
|
+
export { BindEnvOptions, BoolOptions, EnvContext, EnvContextOptions, EnvSource, bindEnv, bool, createEnvContext };
|
package/dist/index.js
CHANGED
|
@@ -5,31 +5,6 @@ import { composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDeleg
|
|
|
5
5
|
import { ensureNonEmptyString, isValueParser } from "@optique/core/valueparser";
|
|
6
6
|
|
|
7
7
|
//#region src/index.ts
|
|
8
|
-
const activeEnvSourceRegistry = /* @__PURE__ */ new Map();
|
|
9
|
-
/**
|
|
10
|
-
* Sets active environment source data for a context.
|
|
11
|
-
*
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
function setActiveEnvSource(contextId, sourceData) {
|
|
15
|
-
activeEnvSourceRegistry.set(contextId, sourceData);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Gets active environment source data for a context.
|
|
19
|
-
*
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
function getActiveEnvSource(contextId) {
|
|
23
|
-
return activeEnvSourceRegistry.get(contextId);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Clears active environment source data for a context.
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
function clearActiveEnvSource(contextId) {
|
|
31
|
-
activeEnvSourceRegistry.delete(contextId);
|
|
32
|
-
}
|
|
33
8
|
function defaultEnvSource(key) {
|
|
34
9
|
const denoGlobal = globalThis.Deno;
|
|
35
10
|
if (typeof denoGlobal?.env?.get === "function") return denoGlobal.env.get(key);
|
|
@@ -39,6 +14,11 @@ function defaultEnvSource(key) {
|
|
|
39
14
|
/**
|
|
40
15
|
* Creates an environment context for use with Optique runners.
|
|
41
16
|
*
|
|
17
|
+
* When calling `context.getAnnotations()` manually, pass the returned
|
|
18
|
+
* annotations to low-level APIs such as `parse()`, `parseAsync()`,
|
|
19
|
+
* `parser.complete()`, `suggest()`, or `getDocPage()`. Calling
|
|
20
|
+
* `getAnnotations()` by itself does not affect later parses.
|
|
21
|
+
*
|
|
42
22
|
* @param options Environment context options.
|
|
43
23
|
* @returns A context that provides environment source annotations.
|
|
44
24
|
* @throws {TypeError} If `prefix` is not a string.
|
|
@@ -63,12 +43,9 @@ function createEnvContext(options = {}) {
|
|
|
63
43
|
prefix,
|
|
64
44
|
source
|
|
65
45
|
};
|
|
66
|
-
setActiveEnvSource(contextId, sourceData);
|
|
67
46
|
return { [contextId]: sourceData };
|
|
68
47
|
},
|
|
69
|
-
[Symbol.dispose]() {
|
|
70
|
-
clearActiveEnvSource(contextId);
|
|
71
|
-
}
|
|
48
|
+
[Symbol.dispose]() {}
|
|
72
49
|
};
|
|
73
50
|
}
|
|
74
51
|
/**
|
|
@@ -251,7 +228,7 @@ function bindEnv(parser, options) {
|
|
|
251
228
|
*/
|
|
252
229
|
function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
253
230
|
const annotations = getAnnotations(state);
|
|
254
|
-
const sourceData = annotations?.[options.context.id]
|
|
231
|
+
const sourceData = annotations?.[options.context.id];
|
|
255
232
|
const fullKey = `${sourceData?.prefix ?? options.context.prefix}${options.key}`;
|
|
256
233
|
const rawValue = sourceData?.source(fullKey);
|
|
257
234
|
const validateSync = (parsed) => {
|
|
@@ -299,10 +276,9 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
299
276
|
/**
|
|
300
277
|
* Resolves an env-backed dependency source with env and default fallbacks.
|
|
301
278
|
*
|
|
302
|
-
* This first checks annotations
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
* extractor.
|
|
279
|
+
* This first checks annotations for the bound variable. If no env-backed value
|
|
280
|
+
* is available, it falls back to `options.default` and finally delegates to
|
|
281
|
+
* the wrapped parser's source extractor.
|
|
306
282
|
*
|
|
307
283
|
* When `innerParser` exposes a `validateValue` hook, env-sourced values
|
|
308
284
|
* and the configured default are re-validated against the inner parser's
|
|
@@ -327,7 +303,7 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
327
303
|
*/
|
|
328
304
|
function getEnvSourceValue(state, options, innerState, extractInnerSourceValue, innerParser) {
|
|
329
305
|
const annotations = getAnnotations(state);
|
|
330
|
-
const sourceData = annotations?.[options.context.id]
|
|
306
|
+
const sourceData = annotations?.[options.context.id];
|
|
331
307
|
const fullKey = `${sourceData?.prefix ?? options.context.prefix}${options.key}`;
|
|
332
308
|
const rawValue = sourceData?.source(fullKey);
|
|
333
309
|
const validateFallback = (parsed) => {
|
|
@@ -417,4 +393,4 @@ function bool(options = {}) {
|
|
|
417
393
|
}
|
|
418
394
|
|
|
419
395
|
//#endregion
|
|
420
|
-
export { bindEnv, bool,
|
|
396
|
+
export { bindEnv, bool, createEnvContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/env",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.1826+dae48c84",
|
|
4
4
|
"description": "Environment variable support for Optique",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"sideEffects": false,
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@optique/core": "1.0.0-dev.
|
|
57
|
+
"@optique/core": "1.0.0-dev.1826+dae48c84"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^20.19.9",
|