@optique/env 1.0.0-dev.1901 → 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 +31 -25
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -21
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -22,9 +22,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
24
|
const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
|
|
25
|
+
const __optique_core_extension = __toESM(require("@optique/core/extension"));
|
|
25
26
|
const __optique_core_message = __toESM(require("@optique/core/message"));
|
|
26
|
-
const __optique_core_mode_dispatch = __toESM(require("@optique/core/mode-dispatch"));
|
|
27
|
-
const __optique_core_parser = __toESM(require("@optique/core/parser"));
|
|
28
27
|
const __optique_core_valueparser = __toESM(require("@optique/core/valueparser"));
|
|
29
28
|
|
|
30
29
|
//#region src/index.ts
|
|
@@ -106,11 +105,10 @@ function bindEnv(parser, options) {
|
|
|
106
105
|
}
|
|
107
106
|
const deferPromptUntilConfigResolves = parser.shouldDeferCompletion;
|
|
108
107
|
const boundParser = {
|
|
109
|
-
|
|
108
|
+
mode: parser.mode,
|
|
110
109
|
$valueType: parser.$valueType,
|
|
111
110
|
$stateType: parser.$stateType,
|
|
112
111
|
priority: parser.priority,
|
|
113
|
-
[__optique_core_parser.unmatchedNonCliDependencySourceStateMarker]: true,
|
|
114
112
|
usage: options.default !== void 0 ? [{
|
|
115
113
|
type: "optional",
|
|
116
114
|
terms: parser.usage
|
|
@@ -120,7 +118,7 @@ function bindEnv(parser, options) {
|
|
|
120
118
|
initialState: parser.initialState,
|
|
121
119
|
getSuggestRuntimeNodes(state, path) {
|
|
122
120
|
const innerState = isEnvBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
|
|
123
|
-
return (0,
|
|
121
|
+
return (0, __optique_core_extension.delegateSuggestNodes)(parser, boundParser, state, path, innerState);
|
|
124
122
|
},
|
|
125
123
|
parse: (context) => {
|
|
126
124
|
const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
|
|
@@ -132,12 +130,11 @@ function bindEnv(parser, options) {
|
|
|
132
130
|
const processResult = (result) => {
|
|
133
131
|
if (result.success) {
|
|
134
132
|
const cliConsumed = result.consumed.length > 0;
|
|
135
|
-
const nextState$1 = {
|
|
133
|
+
const nextState$1 = (0, __optique_core_extension.injectAnnotations)({
|
|
136
134
|
[envBindStateKey]: true,
|
|
137
135
|
hasCliValue: cliConsumed,
|
|
138
|
-
cliState: result.next.state
|
|
139
|
-
|
|
140
|
-
};
|
|
136
|
+
cliState: result.next.state
|
|
137
|
+
}, annotations);
|
|
141
138
|
return {
|
|
142
139
|
success: true,
|
|
143
140
|
...result.provisional ? { provisional: true } : {},
|
|
@@ -149,11 +146,10 @@ function bindEnv(parser, options) {
|
|
|
149
146
|
};
|
|
150
147
|
}
|
|
151
148
|
if (result.consumed > 0) return result;
|
|
152
|
-
const nextState = {
|
|
149
|
+
const nextState = (0, __optique_core_extension.injectAnnotations)({
|
|
153
150
|
[envBindStateKey]: true,
|
|
154
|
-
hasCliValue: false
|
|
155
|
-
|
|
156
|
-
};
|
|
151
|
+
hasCliValue: false
|
|
152
|
+
}, annotations);
|
|
157
153
|
return {
|
|
158
154
|
success: true,
|
|
159
155
|
next: {
|
|
@@ -163,11 +159,11 @@ function bindEnv(parser, options) {
|
|
|
163
159
|
consumed: []
|
|
164
160
|
};
|
|
165
161
|
};
|
|
166
|
-
return (0,
|
|
162
|
+
return (0, __optique_core_extension.mapModeValue)(parser.mode, parser.parse(innerContext), processResult);
|
|
167
163
|
},
|
|
168
164
|
complete: (state, exec) => {
|
|
169
165
|
if (isEnvBindState(state) && state.hasCliValue) return parser.complete(state.cliState, exec);
|
|
170
|
-
return getEnvOrDefault(state, options, parser
|
|
166
|
+
return getEnvOrDefault(state, options, parser.mode, parser, isEnvBindState(state) ? state.cliState : (0, __optique_core_extension.isInjectedAnnotationState)(state) ? void 0 : state, exec);
|
|
171
167
|
},
|
|
172
168
|
suggest: parser.suggest,
|
|
173
169
|
...typeof deferPromptUntilConfigResolves === "function" ? { shouldDeferCompletion: (state, exec) => deferPromptUntilConfigResolves.call(parser, state, exec) } : {},
|
|
@@ -176,7 +172,10 @@ function bindEnv(parser, options) {
|
|
|
176
172
|
return parser.getDocFragments(state, defaultValue);
|
|
177
173
|
}
|
|
178
174
|
};
|
|
179
|
-
(0,
|
|
175
|
+
(0, __optique_core_extension.defineTraits)(boundParser, {
|
|
176
|
+
inheritsAnnotations: true,
|
|
177
|
+
completesFromSource: true
|
|
178
|
+
});
|
|
180
179
|
if ("placeholder" in parser) Object.defineProperty(boundParser, "placeholder", {
|
|
181
180
|
get() {
|
|
182
181
|
return parser.placeholder;
|
|
@@ -194,8 +193,15 @@ function bindEnv(parser, options) {
|
|
|
194
193
|
configurable: true,
|
|
195
194
|
enumerable: false
|
|
196
195
|
});
|
|
197
|
-
const dependencyMetadata = (0,
|
|
196
|
+
const dependencyMetadata = (0, __optique_core_extension.mapSourceMetadata)(parser, (sourceMetadata) => ({
|
|
198
197
|
...sourceMetadata,
|
|
198
|
+
getMissingSourceValue: sourceMetadata.preservesSourceValue !== false && options.default !== void 0 ? () => {
|
|
199
|
+
if (typeof parser.validateValue === "function") return parser.validateValue(options.default);
|
|
200
|
+
return {
|
|
201
|
+
success: true,
|
|
202
|
+
value: options.default
|
|
203
|
+
};
|
|
204
|
+
} : void 0,
|
|
199
205
|
extractSourceValue: (state) => {
|
|
200
206
|
if (!isEnvBindState(state)) {
|
|
201
207
|
if (sourceMetadata.preservesSourceValue) return getEnvSourceValue(state, options, state, sourceMetadata.extractSourceValue, parser);
|
|
@@ -268,12 +274,12 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
268
274
|
if (rawValue !== void 0) {
|
|
269
275
|
if (typeof rawValue !== "string") {
|
|
270
276
|
const type = rawValue === null ? "null" : Array.isArray(rawValue) ? "array" : typeof rawValue;
|
|
271
|
-
return (0,
|
|
277
|
+
return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
272
278
|
success: false,
|
|
273
279
|
error: __optique_core_message.message`Environment variable ${(0, __optique_core_message.envVar)(fullKey)} must be a string, but got: ${type}.`
|
|
274
280
|
});
|
|
275
281
|
}
|
|
276
|
-
return (0,
|
|
282
|
+
return (0, __optique_core_extension.dispatchByMode)(mode, () => {
|
|
277
283
|
const parsed = options.parser.parse(rawValue);
|
|
278
284
|
return validateSync(parsed);
|
|
279
285
|
}, async () => {
|
|
@@ -281,7 +287,7 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
281
287
|
return await validateAsync(parsed);
|
|
282
288
|
});
|
|
283
289
|
}
|
|
284
|
-
if (options.default !== void 0) return (0,
|
|
290
|
+
if (options.default !== void 0) return (0, __optique_core_extension.dispatchByMode)(mode, () => validateSync({
|
|
285
291
|
success: true,
|
|
286
292
|
value: options.default
|
|
287
293
|
}), () => validateAsync({
|
|
@@ -289,10 +295,10 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
289
295
|
value: options.default
|
|
290
296
|
}));
|
|
291
297
|
if (innerParser != null) {
|
|
292
|
-
const completeState = innerState ?? (annotations != null && innerParser.initialState == null &&
|
|
293
|
-
return (0,
|
|
298
|
+
const completeState = innerState ?? (annotations != null && innerParser.initialState == null && (0, __optique_core_extension.getTraits)(innerParser).inheritsAnnotations === true ? (0, __optique_core_extension.injectAnnotations)(innerParser.initialState, annotations) : innerParser.initialState);
|
|
299
|
+
return (0, __optique_core_extension.wrapForMode)(mode, innerParser.complete(completeState, exec));
|
|
294
300
|
}
|
|
295
|
-
return (0,
|
|
301
|
+
return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
296
302
|
success: false,
|
|
297
303
|
error: __optique_core_message.message`Missing required environment variable: ${(0, __optique_core_message.envVar)(fullKey)}`
|
|
298
304
|
});
|
|
@@ -343,7 +349,7 @@ function getEnvSourceValue(state, options, innerState, extractInnerSourceValue,
|
|
|
343
349
|
error: __optique_core_message.message`Environment variable ${(0, __optique_core_message.envVar)(fullKey)} must be a string, but got: ${type}.`
|
|
344
350
|
};
|
|
345
351
|
}
|
|
346
|
-
return (0,
|
|
352
|
+
return (0, __optique_core_extension.mapModeValue)(options.parser.mode, options.parser.parse(rawValue), (p) => validateFallback(p));
|
|
347
353
|
}
|
|
348
354
|
if (options.default !== void 0) return validateFallback({
|
|
349
355
|
success: true,
|
|
@@ -380,7 +386,7 @@ function bool(options = {}) {
|
|
|
380
386
|
const metavar = options.metavar ?? "BOOLEAN";
|
|
381
387
|
(0, __optique_core_valueparser.ensureNonEmptyString)(metavar);
|
|
382
388
|
return {
|
|
383
|
-
|
|
389
|
+
mode: "sync",
|
|
384
390
|
metavar,
|
|
385
391
|
placeholder: false,
|
|
386
392
|
choices: [true, false],
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Message } from "@optique/core/message";
|
|
2
|
-
import { Mode, Parser } from "@optique/core/parser";
|
|
3
2
|
import { NonEmptyString, ValueParser } from "@optique/core/valueparser";
|
|
4
3
|
import { SourceContext } from "@optique/core/context";
|
|
4
|
+
import { Mode, Parser } from "@optique/core/parser";
|
|
5
5
|
|
|
6
6
|
//#region src/index.d.ts
|
|
7
7
|
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAnnotations } from "@optique/core/annotations";
|
|
2
|
+
import { defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, wrapForMode } from "@optique/core/extension";
|
|
2
3
|
import { envVar, message, valueSet } from "@optique/core/message";
|
|
3
|
-
import { dispatchByMode, mapModeValue, wrapForMode } from "@optique/core/mode-dispatch";
|
|
4
|
-
import { composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDelegatingSuggestRuntimeNodes, inheritParentAnnotationsKey, unmatchedNonCliDependencySourceStateMarker } from "@optique/core/parser";
|
|
5
4
|
import { ensureNonEmptyString, isValueParser } from "@optique/core/valueparser";
|
|
6
5
|
|
|
7
6
|
//#region src/index.ts
|
|
@@ -83,11 +82,10 @@ function bindEnv(parser, options) {
|
|
|
83
82
|
}
|
|
84
83
|
const deferPromptUntilConfigResolves = parser.shouldDeferCompletion;
|
|
85
84
|
const boundParser = {
|
|
86
|
-
|
|
85
|
+
mode: parser.mode,
|
|
87
86
|
$valueType: parser.$valueType,
|
|
88
87
|
$stateType: parser.$stateType,
|
|
89
88
|
priority: parser.priority,
|
|
90
|
-
[unmatchedNonCliDependencySourceStateMarker]: true,
|
|
91
89
|
usage: options.default !== void 0 ? [{
|
|
92
90
|
type: "optional",
|
|
93
91
|
terms: parser.usage
|
|
@@ -97,7 +95,7 @@ function bindEnv(parser, options) {
|
|
|
97
95
|
initialState: parser.initialState,
|
|
98
96
|
getSuggestRuntimeNodes(state, path) {
|
|
99
97
|
const innerState = isEnvBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
|
|
100
|
-
return
|
|
98
|
+
return delegateSuggestNodes(parser, boundParser, state, path, innerState);
|
|
101
99
|
},
|
|
102
100
|
parse: (context) => {
|
|
103
101
|
const annotations = getAnnotations(context.state);
|
|
@@ -109,12 +107,11 @@ function bindEnv(parser, options) {
|
|
|
109
107
|
const processResult = (result) => {
|
|
110
108
|
if (result.success) {
|
|
111
109
|
const cliConsumed = result.consumed.length > 0;
|
|
112
|
-
const nextState$1 = {
|
|
110
|
+
const nextState$1 = injectAnnotations({
|
|
113
111
|
[envBindStateKey]: true,
|
|
114
112
|
hasCliValue: cliConsumed,
|
|
115
|
-
cliState: result.next.state
|
|
116
|
-
|
|
117
|
-
};
|
|
113
|
+
cliState: result.next.state
|
|
114
|
+
}, annotations);
|
|
118
115
|
return {
|
|
119
116
|
success: true,
|
|
120
117
|
...result.provisional ? { provisional: true } : {},
|
|
@@ -126,11 +123,10 @@ function bindEnv(parser, options) {
|
|
|
126
123
|
};
|
|
127
124
|
}
|
|
128
125
|
if (result.consumed > 0) return result;
|
|
129
|
-
const nextState = {
|
|
126
|
+
const nextState = injectAnnotations({
|
|
130
127
|
[envBindStateKey]: true,
|
|
131
|
-
hasCliValue: false
|
|
132
|
-
|
|
133
|
-
};
|
|
128
|
+
hasCliValue: false
|
|
129
|
+
}, annotations);
|
|
134
130
|
return {
|
|
135
131
|
success: true,
|
|
136
132
|
next: {
|
|
@@ -140,11 +136,11 @@ function bindEnv(parser, options) {
|
|
|
140
136
|
consumed: []
|
|
141
137
|
};
|
|
142
138
|
};
|
|
143
|
-
return mapModeValue(parser
|
|
139
|
+
return mapModeValue(parser.mode, parser.parse(innerContext), processResult);
|
|
144
140
|
},
|
|
145
141
|
complete: (state, exec) => {
|
|
146
142
|
if (isEnvBindState(state) && state.hasCliValue) return parser.complete(state.cliState, exec);
|
|
147
|
-
return getEnvOrDefault(state, options, parser
|
|
143
|
+
return getEnvOrDefault(state, options, parser.mode, parser, isEnvBindState(state) ? state.cliState : isInjectedAnnotationState(state) ? void 0 : state, exec);
|
|
148
144
|
},
|
|
149
145
|
suggest: parser.suggest,
|
|
150
146
|
...typeof deferPromptUntilConfigResolves === "function" ? { shouldDeferCompletion: (state, exec) => deferPromptUntilConfigResolves.call(parser, state, exec) } : {},
|
|
@@ -153,7 +149,10 @@ function bindEnv(parser, options) {
|
|
|
153
149
|
return parser.getDocFragments(state, defaultValue);
|
|
154
150
|
}
|
|
155
151
|
};
|
|
156
|
-
|
|
152
|
+
defineTraits(boundParser, {
|
|
153
|
+
inheritsAnnotations: true,
|
|
154
|
+
completesFromSource: true
|
|
155
|
+
});
|
|
157
156
|
if ("placeholder" in parser) Object.defineProperty(boundParser, "placeholder", {
|
|
158
157
|
get() {
|
|
159
158
|
return parser.placeholder;
|
|
@@ -171,8 +170,15 @@ function bindEnv(parser, options) {
|
|
|
171
170
|
configurable: true,
|
|
172
171
|
enumerable: false
|
|
173
172
|
});
|
|
174
|
-
const dependencyMetadata =
|
|
173
|
+
const dependencyMetadata = mapSourceMetadata(parser, (sourceMetadata) => ({
|
|
175
174
|
...sourceMetadata,
|
|
175
|
+
getMissingSourceValue: sourceMetadata.preservesSourceValue !== false && options.default !== void 0 ? () => {
|
|
176
|
+
if (typeof parser.validateValue === "function") return parser.validateValue(options.default);
|
|
177
|
+
return {
|
|
178
|
+
success: true,
|
|
179
|
+
value: options.default
|
|
180
|
+
};
|
|
181
|
+
} : void 0,
|
|
176
182
|
extractSourceValue: (state) => {
|
|
177
183
|
if (!isEnvBindState(state)) {
|
|
178
184
|
if (sourceMetadata.preservesSourceValue) return getEnvSourceValue(state, options, state, sourceMetadata.extractSourceValue, parser);
|
|
@@ -266,7 +272,7 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
|
266
272
|
value: options.default
|
|
267
273
|
}));
|
|
268
274
|
if (innerParser != null) {
|
|
269
|
-
const completeState = innerState ?? (annotations != null && innerParser.initialState == null &&
|
|
275
|
+
const completeState = innerState ?? (annotations != null && innerParser.initialState == null && getTraits(innerParser).inheritsAnnotations === true ? injectAnnotations(innerParser.initialState, annotations) : innerParser.initialState);
|
|
270
276
|
return wrapForMode(mode, innerParser.complete(completeState, exec));
|
|
271
277
|
}
|
|
272
278
|
return wrapForMode(mode, {
|
|
@@ -320,7 +326,7 @@ function getEnvSourceValue(state, options, innerState, extractInnerSourceValue,
|
|
|
320
326
|
error: message`Environment variable ${envVar(fullKey)} must be a string, but got: ${type}.`
|
|
321
327
|
};
|
|
322
328
|
}
|
|
323
|
-
return mapModeValue(options.parser
|
|
329
|
+
return mapModeValue(options.parser.mode, options.parser.parse(rawValue), (p) => validateFallback(p));
|
|
324
330
|
}
|
|
325
331
|
if (options.default !== void 0) return validateFallback({
|
|
326
332
|
success: true,
|
|
@@ -357,7 +363,7 @@ function bool(options = {}) {
|
|
|
357
363
|
const metavar = options.metavar ?? "BOOLEAN";
|
|
358
364
|
ensureNonEmptyString(metavar);
|
|
359
365
|
return {
|
|
360
|
-
|
|
366
|
+
mode: "sync",
|
|
361
367
|
metavar,
|
|
362
368
|
placeholder: false,
|
|
363
369
|
choices: [true, false],
|
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.1970+0182ae32",
|
|
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.1970+0182ae32"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^20.19.9",
|