@optique/env 1.0.0-dev.463 → 1.0.0-dev.466
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 +15 -14
- package/dist/index.js +15 -14
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -123,25 +123,25 @@ function bindEnv(parser, options) {
|
|
|
123
123
|
...context,
|
|
124
124
|
state: innerState
|
|
125
125
|
} : context;
|
|
126
|
-
const processResult = (result
|
|
127
|
-
if (result
|
|
128
|
-
const cliConsumed = result
|
|
126
|
+
const processResult = (result) => {
|
|
127
|
+
if (result.success) {
|
|
128
|
+
const cliConsumed = result.consumed.length > 0;
|
|
129
129
|
const nextState$1 = {
|
|
130
130
|
[envBindStateKey]: true,
|
|
131
131
|
hasCliValue: cliConsumed,
|
|
132
|
-
cliState: result
|
|
132
|
+
cliState: result.next.state,
|
|
133
133
|
...annotations && { [__optique_core_annotations.annotationKey]: annotations }
|
|
134
134
|
};
|
|
135
135
|
return {
|
|
136
136
|
success: true,
|
|
137
137
|
next: {
|
|
138
|
-
...result
|
|
138
|
+
...result.next,
|
|
139
139
|
state: nextState$1
|
|
140
140
|
},
|
|
141
|
-
consumed: result
|
|
141
|
+
consumed: result.consumed
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
if (result
|
|
144
|
+
if (result.consumed > 0) return result;
|
|
145
145
|
const nextState = {
|
|
146
146
|
[envBindStateKey]: true,
|
|
147
147
|
hasCliValue: false,
|
|
@@ -156,9 +156,7 @@ function bindEnv(parser, options) {
|
|
|
156
156
|
consumed: []
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
|
-
|
|
160
|
-
if (result instanceof Promise) return result.then(processResult);
|
|
161
|
-
return processResult(result);
|
|
159
|
+
return mapModeValue(parser.$mode, parser.parse(innerContext), processResult);
|
|
162
160
|
},
|
|
163
161
|
complete: (state) => {
|
|
164
162
|
if (isEnvBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
@@ -173,8 +171,14 @@ function bindEnv(parser, options) {
|
|
|
173
171
|
}
|
|
174
172
|
function wrapForMode(mode, value) {
|
|
175
173
|
if (mode === "async") return Promise.resolve(value);
|
|
174
|
+
if (value instanceof Promise) throw new TypeError("Synchronous mode cannot wrap Promise value.");
|
|
176
175
|
return value;
|
|
177
176
|
}
|
|
177
|
+
function mapModeValue(mode, value, mapFn) {
|
|
178
|
+
if (mode === "async") return Promise.resolve(value).then(mapFn);
|
|
179
|
+
if (value instanceof Promise) throw new TypeError("Synchronous mode cannot map Promise value.");
|
|
180
|
+
return mapFn(value);
|
|
181
|
+
}
|
|
178
182
|
function getEnvOrDefault(state, options, mode, innerParser, innerState) {
|
|
179
183
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
180
184
|
const sourceData = annotations?.[options.context.id] ?? getActiveEnvSource(options.context.id);
|
|
@@ -182,7 +186,6 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState) {
|
|
|
182
186
|
const rawValue = sourceData?.source(fullKey);
|
|
183
187
|
if (rawValue !== void 0) {
|
|
184
188
|
const parsed = options.parser.parse(rawValue);
|
|
185
|
-
if (parsed instanceof Promise) return parsed;
|
|
186
189
|
return wrapForMode(mode, parsed);
|
|
187
190
|
}
|
|
188
191
|
if (options.default !== void 0) return wrapForMode(mode, {
|
|
@@ -191,9 +194,7 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState) {
|
|
|
191
194
|
});
|
|
192
195
|
if (innerParser != null) {
|
|
193
196
|
const completeState = innerState ?? innerParser.initialState;
|
|
194
|
-
|
|
195
|
-
if (result instanceof Promise) return result;
|
|
196
|
-
return wrapForMode(mode, result);
|
|
197
|
+
return wrapForMode(mode, innerParser.complete(completeState));
|
|
197
198
|
}
|
|
198
199
|
return wrapForMode(mode, {
|
|
199
200
|
success: false,
|
package/dist/index.js
CHANGED
|
@@ -100,25 +100,25 @@ function bindEnv(parser, options) {
|
|
|
100
100
|
...context,
|
|
101
101
|
state: innerState
|
|
102
102
|
} : context;
|
|
103
|
-
const processResult = (result
|
|
104
|
-
if (result
|
|
105
|
-
const cliConsumed = result
|
|
103
|
+
const processResult = (result) => {
|
|
104
|
+
if (result.success) {
|
|
105
|
+
const cliConsumed = result.consumed.length > 0;
|
|
106
106
|
const nextState$1 = {
|
|
107
107
|
[envBindStateKey]: true,
|
|
108
108
|
hasCliValue: cliConsumed,
|
|
109
|
-
cliState: result
|
|
109
|
+
cliState: result.next.state,
|
|
110
110
|
...annotations && { [annotationKey]: annotations }
|
|
111
111
|
};
|
|
112
112
|
return {
|
|
113
113
|
success: true,
|
|
114
114
|
next: {
|
|
115
|
-
...result
|
|
115
|
+
...result.next,
|
|
116
116
|
state: nextState$1
|
|
117
117
|
},
|
|
118
|
-
consumed: result
|
|
118
|
+
consumed: result.consumed
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
if (result
|
|
121
|
+
if (result.consumed > 0) return result;
|
|
122
122
|
const nextState = {
|
|
123
123
|
[envBindStateKey]: true,
|
|
124
124
|
hasCliValue: false,
|
|
@@ -133,9 +133,7 @@ function bindEnv(parser, options) {
|
|
|
133
133
|
consumed: []
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
|
-
|
|
137
|
-
if (result instanceof Promise) return result.then(processResult);
|
|
138
|
-
return processResult(result);
|
|
136
|
+
return mapModeValue(parser.$mode, parser.parse(innerContext), processResult);
|
|
139
137
|
},
|
|
140
138
|
complete: (state) => {
|
|
141
139
|
if (isEnvBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
|
|
@@ -150,8 +148,14 @@ function bindEnv(parser, options) {
|
|
|
150
148
|
}
|
|
151
149
|
function wrapForMode(mode, value) {
|
|
152
150
|
if (mode === "async") return Promise.resolve(value);
|
|
151
|
+
if (value instanceof Promise) throw new TypeError("Synchronous mode cannot wrap Promise value.");
|
|
153
152
|
return value;
|
|
154
153
|
}
|
|
154
|
+
function mapModeValue(mode, value, mapFn) {
|
|
155
|
+
if (mode === "async") return Promise.resolve(value).then(mapFn);
|
|
156
|
+
if (value instanceof Promise) throw new TypeError("Synchronous mode cannot map Promise value.");
|
|
157
|
+
return mapFn(value);
|
|
158
|
+
}
|
|
155
159
|
function getEnvOrDefault(state, options, mode, innerParser, innerState) {
|
|
156
160
|
const annotations = getAnnotations(state);
|
|
157
161
|
const sourceData = annotations?.[options.context.id] ?? getActiveEnvSource(options.context.id);
|
|
@@ -159,7 +163,6 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState) {
|
|
|
159
163
|
const rawValue = sourceData?.source(fullKey);
|
|
160
164
|
if (rawValue !== void 0) {
|
|
161
165
|
const parsed = options.parser.parse(rawValue);
|
|
162
|
-
if (parsed instanceof Promise) return parsed;
|
|
163
166
|
return wrapForMode(mode, parsed);
|
|
164
167
|
}
|
|
165
168
|
if (options.default !== void 0) return wrapForMode(mode, {
|
|
@@ -168,9 +171,7 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState) {
|
|
|
168
171
|
});
|
|
169
172
|
if (innerParser != null) {
|
|
170
173
|
const completeState = innerState ?? innerParser.initialState;
|
|
171
|
-
|
|
172
|
-
if (result instanceof Promise) return result;
|
|
173
|
-
return wrapForMode(mode, result);
|
|
174
|
+
return wrapForMode(mode, innerParser.complete(completeState));
|
|
174
175
|
}
|
|
175
176
|
return wrapForMode(mode, {
|
|
176
177
|
success: 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.466+f096ac54",
|
|
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.466+f096ac54"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^20.19.9",
|