@optique/env 1.0.0-dev.555 → 1.0.0-dev.556

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
@@ -23,6 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  //#endregion
24
24
  const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
25
25
  const __optique_core_message = __toESM(require("@optique/core/message"));
26
+ const __optique_core_mode_dispatch = __toESM(require("@optique/core/mode-dispatch"));
26
27
  const __optique_core_valueparser = __toESM(require("@optique/core/valueparser"));
27
28
 
28
29
  //#region src/index.ts
@@ -156,7 +157,7 @@ function bindEnv(parser, options) {
156
157
  consumed: []
157
158
  };
158
159
  };
159
- return mapModeValue(parser.$mode, parser.parse(innerContext), processResult);
160
+ return (0, __optique_core_mode_dispatch.mapModeValue)(parser.$mode, parser.parse(innerContext), processResult);
160
161
  },
161
162
  complete: (state) => {
162
163
  if (isEnvBindState(state) && state.hasCliValue) return parser.complete(state.cliState);
@@ -169,16 +170,6 @@ function bindEnv(parser, options) {
169
170
  }
170
171
  };
171
172
  }
172
- function wrapForMode(mode, value) {
173
- if (mode === "async") return Promise.resolve(value);
174
- if (value instanceof Promise) throw new TypeError("Synchronous mode cannot wrap Promise value.");
175
- return value;
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
- }
182
173
  function getEnvOrDefault(state, options, mode, innerParser, innerState) {
183
174
  const annotations = (0, __optique_core_annotations.getAnnotations)(state);
184
175
  const sourceData = annotations?.[options.context.id] ?? getActiveEnvSource(options.context.id);
@@ -186,19 +177,19 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState) {
186
177
  const rawValue = sourceData?.source(fullKey);
187
178
  if (rawValue !== void 0) {
188
179
  const parsed = options.parser.parse(rawValue);
189
- return wrapForMode(mode, parsed);
180
+ return (0, __optique_core_mode_dispatch.wrapForMode)(mode, parsed);
190
181
  }
191
- if (options.default !== void 0) return wrapForMode(mode, {
182
+ if (options.default !== void 0) return (0, __optique_core_mode_dispatch.wrapForMode)(mode, {
192
183
  success: true,
193
184
  value: options.default
194
185
  });
195
186
  if (innerParser != null) {
196
187
  const completeState = innerState ?? innerParser.initialState;
197
- return wrapForMode(mode, innerParser.complete(completeState));
188
+ return (0, __optique_core_mode_dispatch.wrapForMode)(mode, innerParser.complete(completeState));
198
189
  }
199
- return wrapForMode(mode, {
190
+ return (0, __optique_core_mode_dispatch.wrapForMode)(mode, {
200
191
  success: false,
201
- error: __optique_core_message.message`Missing required environment variable: ${fullKey}.`
192
+ error: __optique_core_message.message`Missing required environment variable: ${(0, __optique_core_message.envVar)(fullKey)}`
202
193
  });
203
194
  }
204
195
  const TRUE_LITERALS = [
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { annotationKey, getAnnotations } from "@optique/core/annotations";
2
- import { message, valueSet } from "@optique/core/message";
2
+ import { envVar, message, valueSet } from "@optique/core/message";
3
+ import { mapModeValue, wrapForMode } from "@optique/core/mode-dispatch";
3
4
  import { ensureNonEmptyString } from "@optique/core/valueparser";
4
5
 
5
6
  //#region src/index.ts
@@ -146,16 +147,6 @@ function bindEnv(parser, options) {
146
147
  }
147
148
  };
148
149
  }
149
- function wrapForMode(mode, value) {
150
- if (mode === "async") return Promise.resolve(value);
151
- if (value instanceof Promise) throw new TypeError("Synchronous mode cannot wrap Promise value.");
152
- return value;
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
- }
159
150
  function getEnvOrDefault(state, options, mode, innerParser, innerState) {
160
151
  const annotations = getAnnotations(state);
161
152
  const sourceData = annotations?.[options.context.id] ?? getActiveEnvSource(options.context.id);
@@ -175,7 +166,7 @@ function getEnvOrDefault(state, options, mode, innerParser, innerState) {
175
166
  }
176
167
  return wrapForMode(mode, {
177
168
  success: false,
178
- error: message`Missing required environment variable: ${fullKey}.`
169
+ error: message`Missing required environment variable: ${envVar(fullKey)}`
179
170
  });
180
171
  }
181
172
  const TRUE_LITERALS = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/env",
3
- "version": "1.0.0-dev.555+975ed8c5",
3
+ "version": "1.0.0-dev.556+f691dcba",
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.555+975ed8c5"
57
+ "@optique/core": "1.0.0-dev.556+f691dcba"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^20.19.9",