@o3co/ts.hocon 1.14.0 → 1.14.1

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/README.ja.md CHANGED
@@ -249,6 +249,8 @@ const app = validate(cfg, Schema)
249
249
  const port = getValidated(cfg, 'server.port', z.number().int())
250
250
  ```
251
251
 
252
+ スキーマが数値や真偽値を求める位置では文字列を変換するので、`PORT=8081` のとき `port = ${?PORT}` は `z.number()` を通ります。変換はスキーマに沿って、object・array・record(各値)・tuple・union・pipe(入力側のスキーマ)・lazy と、optional / nullable / default / prefault / nonoptional / catch / readonly の各ラッパーの中まで届きます。数値や真偽値の literal にも変換します(`z.literal(1)` に対する `"1"`)。object の `catchall` と intersection の中には届きません。`z.discriminatedUnion` は discriminator が選ぶ option に従って変換します。それ以外の union は、値をそのまま受け入れる option があれば変換せず(`z.union([z.number(), z.string()])` では `"5"` は文字列のまま)、なければ変換後の値を受け入れる最初の option に従って変換します(`z.union([z.number(), z.literal('auto')])` では `"8081"` は 8081)。その option を探すために option を順に試すので、深く再帰する通常の union は検証が遅くなります。そこでは `z.discriminatedUnion` を使ってください。
253
+
252
254
  HOCON の duration と byte size は文字列(`30m`、`64KiB`)なので、`z.number()` では通りません。`hocon.duration(unit?)` / `hocon.bytes(unit?)` マーカーは `getDuration()` / `getBytes()` と同じ規則で読み、指定した単位の数値を返します(既定は `ms` / `B`。単位のない数値は getter と同じ意味)。範囲や整数のチェックは、マーカーを数値スキーマに pipe して書きます:
253
255
 
254
256
  ```ts
@@ -274,7 +276,7 @@ const Backup = z.object({
274
276
  getValidated(cfg, 'backup', Backup) // { keep: { years: 0, months: 0, days: 14 } }
275
277
  ```
276
278
 
277
- 不正な duration / byte size / period は、キーのパス付きのバリデーションエラーになります。マーカーは普通の Zod スキーマなので、`validate`・`getValidated`・`parseWithSchema`・`parseFileWithSchema` をはじめ、Zod が実行するところならどこでも使えます。指数表記(`1e3`、`"1.5e2s"`)は getter もマーカーも読みます。ただしマーカーは数値を JavaScript の値として読むため、double の精度を超える桁数の数値リテラルは、リテラルの文字列を正確に読む getter と結果が異なることがあります(`1.99999999999999999` B は `getBytes()` では 1、マーカーでは 2)。period のマーカーは、小数点や指数を含むリテラル(`7.0`、`1e2`)も整数として読みます(`getPeriod()` は拒否します)。単位付きで書けば(`30s`、`7d`)どちらの差も出ません。
279
+ 不正な duration / byte size / period は、キーのパス付きのバリデーションエラーになります。issue の message は問題だけを示し、値は含めません(`not a duration`、`byte size must be non-negative`)。誤ったキーに置かれたシークレットがログに出ないようにするためです。`params.problem` は `invalid`・`negative`・`overflow` のいずれかで、値は Zod に input の報告を求めたときだけ issue の `input` に入ります。マーカーは普通の Zod スキーマなので、`validate`・`getValidated`・`parseWithSchema`・`parseFileWithSchema` をはじめ、Zod が実行するところならどこでも使えます。指数表記(`1e3`、`"1.5e2s"`)は getter もマーカーも読みます。ただしマーカーは数値を JavaScript の値として読むため、double の精度を超える桁数の数値リテラルは、リテラルの文字列を正確に読む getter と結果が異なることがあります(`1.99999999999999999` B は `getBytes()` では 1、マーカーでは 2)。period のマーカーは、小数点や指数を含むリテラル(`7.0`、`1e2`)も整数として読みます(`getPeriod()` は拒否します)。単位付きで書けば(`30s`、`7d`)どちらの差も出ません。
278
280
 
279
281
  未解決の Config(`resolveSubstitutions: false` でパースしたもの、`resolve()` 前のフォールバックの重なり、または何かが残った `resolve({ allowUnresolved: true })` の結果)に対しては、`validate` は保留中の値が欠けたツリーを検証するのではなく、getter と同じく `NotResolvedError` を投げます。`getValidated` は、値が未解決のパスでは `NotResolvedError` を投げ、解決済みのパスなら検証します。先に `resolve()` を呼んでください。
280
282
 
@@ -283,7 +285,7 @@ Zod をピア依存としてインストール:
283
285
  npm install zod
284
286
  ```
285
287
 
286
- Zod の入口(`validate`・`getValidated`・`parseWithSchema`・`parseFileWithSchema`)は、値のどこかに `__proto__`・`constructor`・`prototype` という名前のキーがあると拒否します。Zod は record から `__proto__` キーをエラーなしで落とすため、また結果がスキーマによって変わらないように、3 つとも同じく拒否します。`ZodError` にはキーごとに 1 つの issue が入ります。issue はそのキーを持つオブジェクトの位置に付き、キー名は message と `params.key` に入ります(`key "__proto__" names an object's prototype → at limits`)。キー名を変えるか、影響を受けない通常の getter(`cfg.getNumber('limits."constructor"')`)で読んでください。
288
+ Zod の入口(`validate`・`getValidated`・`parseWithSchema`・`parseFileWithSchema`)は、値のどこかに `__proto__`・`constructor`・`prototype` という名前のキーがあると拒否します。Zod は record から `__proto__` キーをエラーなしで落とすため、また結果がスキーマによって変わらないように、3 つとも同じく拒否します。`ZodError` にはキーごとに 1 つの issue が入ります。issue はそのキーを持つオブジェクトの位置に付き、キー名は message と `params.key` に入ります(`key "__proto__" names an object's prototype → at limits`)。その後に、拒否したキーを除いた値に対するスキーマの issue が続くので、1 回の実行で問題がすべてわかります。キー名を変えるか、影響を受けない通常の getter(`cfg.getNumber('limits."constructor"')`)で読んでください。
287
289
 
288
290
  ### エラー型
289
291
 
@@ -566,7 +568,7 @@ const merged = cfg.withFallback(base).resolve()
566
568
  | `@o3co/ts.hocon/adapters/env` | — | プレフィックス付き名前空間の一括マウント。`.env` の読み込みも可能 |
567
569
  | `@o3co/ts.hocon/adapters/jsonc` | — | コメントと末尾カンマを許す JSON |
568
570
  | `@o3co/ts.hocon/adapters/json5` | — | JSON5 1.0.0。手書き scanner で依存ゼロ |
569
- | `@o3co/ts.hocon/adapters/toml` | `smol-toml`(>= 1.0) | オプショナルなピア依存 |
571
+ | `@o3co/ts.hocon/adapters/toml` | `smol-toml`(>= 1.0。1.9.0 以上を推奨、[SECURITY.md](SECURITY.md#the-toml-adapter) 参照) | オプショナルなピア依存 |
570
572
  | `@o3co/ts.hocon/adapters/yaml` | `yaml`(>= 2.0) | オプショナルなピア依存。スカラー解決はそのライブラリの答えで、`version: '1.2'` を明示してドリフトを防止 |
571
573
 
572
574
  TOML と YAML のライブラリは **オプショナルなピア依存** なので、本パッケージを入れても
package/README.md CHANGED
@@ -250,6 +250,8 @@ const app = validate(cfg, Schema)
250
250
  const port = getValidated(cfg, 'server.port', z.number().int())
251
251
  ```
252
252
 
253
+ A string is coerced where the schema expects a number or a boolean, so `port = ${?PORT}` with `PORT=8081` validates against `z.number()`. The coercion follows the schema through objects, arrays, records (each value), tuples, unions, pipes (by the input schema), lazy schemas and the optional / nullable / default / prefault / nonoptional / catch / readonly wrappers, and turns a string into a number or boolean literal (`"1"` for `z.literal(1)`). It does not walk an object's `catchall` or an intersection. A `z.discriminatedUnion` coerces by the option the discriminator picks. Any other union takes the value as it is when an option accepts it, so `z.union([z.number(), z.string()])` keeps `"5"` a string, and coerces it otherwise, by the first option that accepts the coerced value (`z.union([z.number(), z.literal('auto')])` reads `"8081"` as 8081). Finding that option tries the options in turn, so a deeply recursive plain union validates slowly; prefer `z.discriminatedUnion` there.
254
+
253
255
  Durations and byte sizes are strings in HOCON (`30m`, `64KiB`), so `z.number()` refuses them. The `hocon.duration(unit?)` and `hocon.bytes(unit?)` markers read them with the same rules as `getDuration()` / `getBytes()` and give a number in the requested unit (default `ms` / `B`; a plain number keeps the getters' meaning). Pipe the marker into a number schema for range and integer checks:
254
256
 
255
257
  ```ts
@@ -275,7 +277,7 @@ const Backup = z.object({
275
277
  getValidated(cfg, 'backup', Backup) // { keep: { years: 0, months: 0, days: 14 } }
276
278
  ```
277
279
 
278
- An invalid duration, size or period fails validation with the key's path. The markers are ordinary Zod schemas, so they work in `validate`, `getValidated`, `parseWithSchema`, `parseFileWithSchema` and anywhere else Zod runs them. Getters and markers both read exponent forms (`1e3`, `"1.5e2s"`). A marker reads a number through its JavaScript value, though, so a number literal with more significant digits than a double holds can read differently from the getters, which read the literal's text exactly (`1.99999999999999999` B is 1 through `getBytes()`, 2 through the marker); a period marker also reads a literal with a decimal point or an exponent (`7.0`, `1e2`) as an integer, which `getPeriod()` refuses. Write unit values with a unit (`30s`, `7d`) to avoid both.
280
+ An invalid duration, size or period fails validation with the key's path. The issue message names the problem, not the value (`not a duration`, `byte size must be non-negative`), so a secret set under the wrong key does not reach the logs; `params.problem` is `invalid`, `negative` or `overflow`, and the value is in the issue's `input` only when Zod is asked to report input. The markers are ordinary Zod schemas, so they work in `validate`, `getValidated`, `parseWithSchema`, `parseFileWithSchema` and anywhere else Zod runs them. Getters and markers both read exponent forms (`1e3`, `"1.5e2s"`). A marker reads a number through its JavaScript value, though, so a number literal with more significant digits than a double holds can read differently from the getters, which read the literal's text exactly (`1.99999999999999999` B is 1 through `getBytes()`, 2 through the marker); a period marker also reads a literal with a decimal point or an exponent (`7.0`, `1e2`) as an integer, which `getPeriod()` refuses. Write unit values with a unit (`30s`, `7d`) to avoid both.
279
281
 
280
282
  On an unresolved Config (parsed with `resolveSubstitutions: false`, a fallback stack not yet `resolve()`d, or the result of `resolve({ allowUnresolved: true })` with something left), `validate` throws `NotResolvedError`, as the getters do, rather than validating a tree with the pending values missing; `getValidated` throws it for a path whose value is unresolved and validates a resolved one. Call `resolve()` first.
281
283
 
@@ -284,7 +286,7 @@ Install Zod as a peer dependency:
284
286
  npm install zod
285
287
  ```
286
288
 
287
- The Zod entry points (`validate`, `getValidated`, `parseWithSchema`, `parseFileWithSchema`) refuse an object key named `__proto__`, `constructor` or `prototype` anywhere in the value: Zod drops a `__proto__` key from a record without an error, and the three are refused alike so the result does not depend on the schema. The `ZodError` has one issue per key, at the object that holds it, with the key in the message and in `params.key` (`key "__proto__" names an object's prototype → at limits`). Rename the key, or read it with the plain getters (`cfg.getNumber('limits."constructor"')`), which are unaffected.
289
+ The Zod entry points (`validate`, `getValidated`, `parseWithSchema`, `parseFileWithSchema`) refuse an object key named `__proto__`, `constructor` or `prototype` anywhere in the value: Zod drops a `__proto__` key from a record without an error, and the three are refused alike so the result does not depend on the schema. The `ZodError` has one issue per key, at the object that holds it, with the key in the message and in `params.key` (`key "__proto__" names an object's prototype → at limits`), followed by the schema's issues for the rest of the value: the schema validates the value without the refused keys, so one run lists everything wrong. Rename the key, or read it with the plain getters (`cfg.getNumber('limits."constructor"')`), which are unaffected.
288
290
 
289
291
  ### Error types
290
292
 
@@ -568,7 +570,7 @@ Deferring resolution matters: the plain `parse` resolves as it goes, so a
568
570
  | `@o3co/ts.hocon/adapters/env` | — | Bulk-mounts a prefixed namespace; also reads `.env` |
569
571
  | `@o3co/ts.hocon/adapters/jsonc` | — | JSON with comments and trailing commas |
570
572
  | `@o3co/ts.hocon/adapters/json5` | — | JSON5 1.0.0, hand-rolled scanner, zero dependencies |
571
- | `@o3co/ts.hocon/adapters/toml` | `smol-toml` (>= 1.0) | Optional peer dependency |
573
+ | `@o3co/ts.hocon/adapters/toml` | `smol-toml` (>= 1.0; >= 1.9.0 recommended, see [SECURITY.md](SECURITY.md#the-toml-adapter)) | Optional peer dependency |
572
574
  | `@o3co/ts.hocon/adapters/yaml` | `yaml` (>= 2.0) | Optional peer dependency; scalar resolution is that library's answer, with `version: '1.2'` declared so it cannot drift |
573
575
 
574
576
  The TOML and YAML libraries are **optional peer dependencies**, so installing
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
3
+ var _chunkPCAMDXJ4cjs = require('../chunk-PCAMDXJ4.cjs');
4
4
 
5
5
 
6
6
 
@@ -8,14 +8,14 @@ var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
8
8
 
9
9
 
10
10
 
11
- var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
11
+ var _chunkL3D2RE2Ucjs = require('../chunk-L3D2RE2U.cjs');
12
12
 
13
13
  // src/adapters/env.ts
14
14
  var SEPARATOR = "__";
15
15
  function loadEnv(opts = {}) {
16
16
  const prefix = _nullishCoalesce(opts.prefix, () => ( ""));
17
17
  if (prefix === "") {
18
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
18
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
19
19
  "loadEnv: a prefix is required when mounting the environment (spec F1.1)",
20
20
  ""
21
21
  );
@@ -29,44 +29,44 @@ function loadEnv(opts = {}) {
29
29
  const value = source[name];
30
30
  if (value === void 0) continue;
31
31
  const path = toPath(name.slice(prefix.length));
32
- const key = _chunkRO4D6BH7cjs.pathKey.call(void 0, path);
32
+ const key = _chunkL3D2RE2Ucjs.pathKey.call(void 0, path);
33
33
  const prev = seen.get(key);
34
34
  if (prev !== void 0) {
35
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`loadEnv: ${prev} and ${name} both map to "${path.join(".")}"`, path.join("."));
35
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(`loadEnv: ${prev} and ${name} both map to "${path.join(".")}"`, path.join("."));
36
36
  }
37
37
  seen.set(key, name);
38
38
  pairs.push([path, value]);
39
39
  }
40
- return _chunkGBNQADHTcjs.fromMap.call(void 0, _chunkRO4D6BH7cjs.nestPairs.call(void 0, pairs), _nullishCoalesce(opts.originDescription, () => ( "environment variables")));
40
+ return _chunkPCAMDXJ4cjs.fromMap.call(void 0, _chunkL3D2RE2Ucjs.nestPairs.call(void 0, pairs), _nullishCoalesce(opts.originDescription, () => ( "environment variables")));
41
41
  }
42
42
  function parseDotEnv(input, opts = {}) {
43
43
  const origin = _nullishCoalesce(opts.originDescription, () => ( ".env"));
44
44
  const prefix = _nullishCoalesce(opts.prefix, () => ( ""));
45
45
  const pairs = [];
46
- const lines = _chunkRO4D6BH7cjs.stripBom.call(void 0, input).replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
46
+ const lines = _chunkL3D2RE2Ucjs.stripBom.call(void 0, input).replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
47
47
  for (let i = 0; i < lines.length; i++) {
48
48
  const raw = (_nullishCoalesce(lines[i], () => ( ""))).trim();
49
49
  if (raw === "" || raw.startsWith("#")) continue;
50
50
  const line = stripExport(raw);
51
51
  const eq = line.indexOf("=");
52
- if (eq === -1) throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`${origin}:${i + 1}: expected NAME=value`, "");
52
+ if (eq === -1) throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(`${origin}:${i + 1}: expected NAME=value`, "");
53
53
  const name = line.slice(0, eq).trim();
54
- if (name === "") throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`${origin}:${i + 1}: empty variable name`, "");
54
+ if (name === "") throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(`${origin}:${i + 1}: empty variable name`, "");
55
55
  if (!name.startsWith(prefix)) continue;
56
56
  checkName(name, origin, i + 1);
57
57
  const value = dotEnvValue(line.slice(eq + 1).replace(/^[ \t]+/, ""), origin, i + 1, name);
58
58
  pairs.push([toPath(name.slice(prefix.length)), value]);
59
59
  }
60
- return _chunkGBNQADHTcjs.fromMap.call(void 0, _chunkRO4D6BH7cjs.nestPairs.call(void 0, pairs), origin);
60
+ return _chunkPCAMDXJ4cjs.fromMap.call(void 0, _chunkL3D2RE2Ucjs.nestPairs.call(void 0, pairs), origin);
61
61
  }
62
62
  function toPath(name) {
63
63
  const segs = name.split(SEPARATOR).map(asciiLower);
64
64
  if (segs.some((s) => s === "")) {
65
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`env: "${name}" produces an empty path segment`, name);
65
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(`env: "${name}" produces an empty path segment`, name);
66
66
  }
67
- if (_chunkRO4D6BH7cjs.tooDeep.call(void 0, segs.length)) {
68
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
69
- `env: "${name}" maps to a path ${segs.length} segments deep, over the limit of ${_chunkRO4D6BH7cjs.MAX_PATH_SEGMENTS}`,
67
+ if (_chunkL3D2RE2Ucjs.tooDeep.call(void 0, segs.length)) {
68
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
69
+ `env: "${name}" maps to a path ${segs.length} segments deep, over the limit of ${_chunkL3D2RE2Ucjs.MAX_PATH_SEGMENTS}`,
70
70
  name
71
71
  );
72
72
  }
@@ -77,7 +77,7 @@ function asciiLower(s) {
77
77
  }
78
78
  function dotEnvValue(v, origin, line, name) {
79
79
  const fail = (msg) => {
80
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`${origin}:${line}: ${name}: ${msg}`, name);
80
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(`${origin}:${line}: ${name}: ${msg}`, name);
81
81
  };
82
82
  if (v.startsWith("'")) {
83
83
  const end = v.indexOf("'", 1);
@@ -123,7 +123,7 @@ function checkName(name, origin, line) {
123
123
  const bad = /\p{White_Space}|#/u.exec(name);
124
124
  if (bad) {
125
125
  const what = bad[0] === "#" ? "'#'" : "whitespace";
126
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
126
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
127
127
  `${origin}:${line}: variable name "${name}" contains ${what}; the line is not NAME=value (spec F1.7)`,
128
128
  name
129
129
  );
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  fromMap
3
- } from "../chunk-QY7ECGS6.js";
3
+ } from "../chunk-YRNDXYGQ.js";
4
4
  import {
5
5
  ConfigError,
6
6
  MAX_PATH_SEGMENTS,
@@ -8,7 +8,7 @@ import {
8
8
  pathKey,
9
9
  stripBom,
10
10
  tooDeep
11
- } from "../chunk-WTXULUZS.js";
11
+ } from "../chunk-GOXMKYWS.js";
12
12
 
13
13
  // src/adapters/env.ts
14
14
  var SEPARATOR = "__";
@@ -1,27 +1,27 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
3
+ var _chunkPCAMDXJ4cjs = require('../chunk-PCAMDXJ4.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
- var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
9
+ var _chunkL3D2RE2Ucjs = require('../chunk-L3D2RE2U.cjs');
10
10
 
11
11
  // src/adapters/json5.ts
12
12
  function parseJson5(input, originDescription) {
13
- const p = new Parser(_chunkRO4D6BH7cjs.stripBom.call(void 0, input), originDescription);
14
- const doc = _chunkRO4D6BH7cjs.guardStackDepth.call(void 0,
13
+ const p = new Parser(_chunkL3D2RE2Ucjs.stripBom.call(void 0, input), originDescription);
14
+ const doc = _chunkL3D2RE2Ucjs.guardStackDepth.call(void 0,
15
15
  () => p.parseDocument(),
16
- (msg) => _chunkRO4D6BH7cjs.depthError.call(void 0, `json5: ${describe(originDescription)}: ${msg}`)
16
+ (msg) => _chunkL3D2RE2Ucjs.depthError.call(void 0, `json5: ${describe(originDescription)}: ${msg}`)
17
17
  );
18
18
  if (doc === null || typeof doc !== "object" || Array.isArray(doc)) {
19
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
19
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
20
20
  `json5: ${describe(originDescription)}: document root is ${rootKind(doc)}, but a config root must be an object (spec F0.3)`,
21
21
  ""
22
22
  );
23
23
  }
24
- return _chunkGBNQADHTcjs.fromMap.call(void 0, doc, originDescription);
24
+ return _chunkPCAMDXJ4cjs.fromMap.call(void 0, doc, originDescription);
25
25
  }
26
26
  function describe(origin) {
27
27
  return origin === void 0 || origin === "" ? "document" : origin;
@@ -95,7 +95,7 @@ var Parser = class {
95
95
  }
96
96
  errf(msg) {
97
97
  const col = [...this.src.slice(this.lineAt, this.pos)].length + 1;
98
- return new (0, _chunkRO4D6BH7cjs.ConfigError)(
98
+ return new (0, _chunkL3D2RE2Ucjs.ConfigError)(
99
99
  `json5: ${describe(this.origin)}: line ${this.line + 1} col ${col}: ${msg}`,
100
100
  ""
101
101
  );
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  fromMap
3
- } from "../chunk-QY7ECGS6.js";
3
+ } from "../chunk-YRNDXYGQ.js";
4
4
  import {
5
5
  ConfigError,
6
6
  depthError,
7
7
  guardStackDepth,
8
8
  stripBom
9
- } from "../chunk-WTXULUZS.js";
9
+ } from "../chunk-GOXMKYWS.js";
10
10
 
11
11
  // src/adapters/json5.ts
12
12
  function parseJson5(input, originDescription) {
@@ -1,26 +1,26 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
3
+ var _chunkPCAMDXJ4cjs = require('../chunk-PCAMDXJ4.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
- var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
9
+ var _chunkL3D2RE2Ucjs = require('../chunk-L3D2RE2U.cjs');
10
10
 
11
11
  // src/adapters/jsonc.ts
12
12
  function parseJsonc(input, originDescription) {
13
- const doc = _chunkRO4D6BH7cjs.guardStackDepth.call(void 0,
14
- () => JSON.parse(stripTrailingCommas(stripComments(_chunkRO4D6BH7cjs.stripBom.call(void 0, input))), bigIntReviver),
15
- (msg) => _chunkRO4D6BH7cjs.depthError.call(void 0, `jsonc: ${msg}`)
13
+ const doc = _chunkL3D2RE2Ucjs.guardStackDepth.call(void 0,
14
+ () => JSON.parse(stripTrailingCommas(stripComments(_chunkL3D2RE2Ucjs.stripBom.call(void 0, input))), bigIntReviver),
15
+ (msg) => _chunkL3D2RE2Ucjs.depthError.call(void 0, `jsonc: ${msg}`)
16
16
  );
17
17
  if (doc === null || typeof doc !== "object" || Array.isArray(doc)) {
18
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
18
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
19
19
  `jsonc: document root is ${Array.isArray(doc) ? "an array" : typeof doc}, but a config root must be an object (spec F0.3)`,
20
20
  ""
21
21
  );
22
22
  }
23
- return _chunkGBNQADHTcjs.fromMap.call(void 0, doc, originDescription);
23
+ return _chunkPCAMDXJ4cjs.fromMap.call(void 0, doc, originDescription);
24
24
  }
25
25
  function isIntegerLiteral(source) {
26
26
  return !/[.eE]/.test(source);
@@ -38,7 +38,7 @@ function bigIntReviver(key, value, context) {
38
38
  const source = _optionalChain([context, 'optionalAccess', _2 => _2.source]);
39
39
  if (source === void 0) {
40
40
  if (!Number.isInteger(value)) return value;
41
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
41
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
42
42
  `jsonc: the integer at "${key || "<root>"}" needs more precision than a JS number holds, and this runtime does not expose JSON.parse source text (${HAS_SOURCE_TEXT_ACCESS ? "unexpected \u2014 the capability probe said otherwise" : "requires Node >= 22 or an engine with JSON.parse source access"}), so it cannot be read losslessly (spec F0.5)`,
43
43
  key
44
44
  );
@@ -82,7 +82,7 @@ function stripComments(src) {
82
82
  }
83
83
  if (c === "/" && src[i + 1] === "*") {
84
84
  const end = src.indexOf("*/", i + 2);
85
- if (end === -1) throw new (0, _chunkRO4D6BH7cjs.ConfigError)("jsonc: unterminated block comment", "");
85
+ if (end === -1) throw new (0, _chunkL3D2RE2Ucjs.ConfigError)("jsonc: unterminated block comment", "");
86
86
  out += lineBreaksOf(src.slice(i, end + 2)) || " ";
87
87
  i = end + 2;
88
88
  continue;
@@ -97,7 +97,7 @@ function endOfString(src, i) {
97
97
  if (src[j] === "\\") j++;
98
98
  else if (src[j] === '"') return j + 1;
99
99
  }
100
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)("jsonc: unterminated string literal", "");
100
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)("jsonc: unterminated string literal", "");
101
101
  }
102
102
  function stripTrailingCommas(src) {
103
103
  let out = "";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  fromMap
3
- } from "../chunk-QY7ECGS6.js";
3
+ } from "../chunk-YRNDXYGQ.js";
4
4
  import {
5
5
  ConfigError,
6
6
  depthError,
7
7
  guardStackDepth,
8
8
  stripBom
9
- } from "../chunk-WTXULUZS.js";
9
+ } from "../chunk-GOXMKYWS.js";
10
10
 
11
11
  // src/adapters/jsonc.ts
12
12
  function parseJsonc(input, originDescription) {
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
3
+ var _chunkPCAMDXJ4cjs = require('../chunk-PCAMDXJ4.cjs');
4
4
 
5
5
 
6
- var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
6
+ var _chunkL3D2RE2Ucjs = require('../chunk-L3D2RE2U.cjs');
7
7
 
8
8
  // src/adapters/properties.ts
9
9
  function parsePropertiesConfig(input, originDescription) {
10
- return _chunkGBNQADHTcjs.fromMap.call(void 0, _chunkRO4D6BH7cjs.parseProperties.call(void 0, input), originDescription);
10
+ return _chunkPCAMDXJ4cjs.fromMap.call(void 0, _chunkL3D2RE2Ucjs.parseProperties.call(void 0, input), originDescription);
11
11
  }
12
12
 
13
13
 
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  fromMap
3
- } from "../chunk-QY7ECGS6.js";
3
+ } from "../chunk-YRNDXYGQ.js";
4
4
  import {
5
5
  parseProperties
6
- } from "../chunk-WTXULUZS.js";
6
+ } from "../chunk-GOXMKYWS.js";
7
7
 
8
8
  // src/adapters/properties.ts
9
9
  function parsePropertiesConfig(input, originDescription) {
@@ -1,21 +1,21 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
3
+ var _chunkPCAMDXJ4cjs = require('../chunk-PCAMDXJ4.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
- var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
9
+ var _chunkL3D2RE2Ucjs = require('../chunk-L3D2RE2U.cjs');
10
10
 
11
11
  // src/adapters/toml.ts
12
12
  var _smoltoml = require('smol-toml');
13
13
  function parseTomlConfig(input, originDescription) {
14
- const doc = _smoltoml.parse.call(void 0, _chunkRO4D6BH7cjs.stripBom.call(void 0, input));
15
- return _chunkGBNQADHTcjs.fromMap.call(void 0,
16
- _chunkRO4D6BH7cjs.guardStackDepth.call(void 0,
14
+ const doc = _smoltoml.parse.call(void 0, _chunkL3D2RE2Ucjs.stripBom.call(void 0, input));
15
+ return _chunkPCAMDXJ4cjs.fromMap.call(void 0,
16
+ _chunkL3D2RE2Ucjs.guardStackDepth.call(void 0,
17
17
  () => convert(doc, ""),
18
- (msg) => _chunkRO4D6BH7cjs.depthError.call(void 0, `toml: ${msg}`)
18
+ (msg) => _chunkL3D2RE2Ucjs.depthError.call(void 0, `toml: ${msg}`)
19
19
  ),
20
20
  originDescription
21
21
  );
@@ -33,7 +33,7 @@ function convert(v, atPath) {
33
33
  );
34
34
  }
35
35
  if (typeof v === "number" && !Number.isFinite(v)) {
36
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
36
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
37
37
  `toml: ${v} at "${atPath}" is not representable in HOCON (spec F0.6)`,
38
38
  atPath
39
39
  );
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  fromMap
3
- } from "../chunk-QY7ECGS6.js";
3
+ } from "../chunk-YRNDXYGQ.js";
4
4
  import {
5
5
  ConfigError,
6
6
  depthError,
7
7
  guardStackDepth,
8
8
  stripBom
9
- } from "../chunk-WTXULUZS.js";
9
+ } from "../chunk-GOXMKYWS.js";
10
10
 
11
11
  // src/adapters/toml.ts
12
12
  import { parse as parseToml } from "smol-toml";
@@ -1,43 +1,43 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
3
+ var _chunkPCAMDXJ4cjs = require('../chunk-PCAMDXJ4.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
- var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
9
+ var _chunkL3D2RE2Ucjs = require('../chunk-L3D2RE2U.cjs');
10
10
 
11
11
  // src/adapters/yaml.ts
12
12
  var _yaml = require('yaml'); var _yaml2 = _interopRequireDefault(_yaml);
13
13
  function parseYaml(input, originDescription) {
14
- const docs = _yaml2.default.parseAllDocuments(_chunkRO4D6BH7cjs.stripBom.call(void 0, input), { version: "1.2", merge: true, intAsBigInt: true });
14
+ const docs = _yaml2.default.parseAllDocuments(_chunkL3D2RE2Ucjs.stripBom.call(void 0, input), { version: "1.2", merge: true, intAsBigInt: true });
15
15
  if (docs.length > 1) {
16
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
16
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
17
17
  "yaml: multi-document streams are not supported (spec F5.7); a config is one document",
18
18
  ""
19
19
  );
20
20
  }
21
21
  const doc = docs[0];
22
- if (doc === void 0) return _chunkGBNQADHTcjs.fromMap.call(void 0, {}, originDescription);
22
+ if (doc === void 0) return _chunkPCAMDXJ4cjs.fromMap.call(void 0, {}, originDescription);
23
23
  if (doc.errors.length > 0) {
24
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`yaml: ${_nullishCoalesce(_optionalChain([doc, 'access', _ => _.errors, 'access', _2 => _2[0], 'optionalAccess', _3 => _3.message]), () => ( "parse error"))}`, "");
24
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(`yaml: ${_nullishCoalesce(_optionalChain([doc, 'access', _ => _.errors, 'access', _2 => _2[0], 'optionalAccess', _3 => _3.message]), () => ( "parse error"))}`, "");
25
25
  }
26
26
  return fromYamlValue(doc.toJS({ mapAsMap: true }), originDescription);
27
27
  }
28
28
  function fromYamlValue(value, originDescription) {
29
- if (value === null || value === void 0) return _chunkGBNQADHTcjs.fromMap.call(void 0, {}, originDescription);
30
- const normalized = _chunkRO4D6BH7cjs.guardStackDepth.call(void 0,
29
+ if (value === null || value === void 0) return _chunkPCAMDXJ4cjs.fromMap.call(void 0, {}, originDescription);
30
+ const normalized = _chunkL3D2RE2Ucjs.guardStackDepth.call(void 0,
31
31
  () => convert(value, ""),
32
- (msg) => _chunkRO4D6BH7cjs.depthError.call(void 0, `yaml: ${msg}`)
32
+ (msg) => _chunkL3D2RE2Ucjs.depthError.call(void 0, `yaml: ${msg}`)
33
33
  );
34
34
  if (typeof normalized !== "object" || normalized === null || Array.isArray(normalized)) {
35
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
35
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
36
36
  `yaml: document root is ${Array.isArray(normalized) ? "an array" : typeof normalized}, but a config root must be an object (spec F0.3)`,
37
37
  ""
38
38
  );
39
39
  }
40
- return _chunkGBNQADHTcjs.fromMap.call(void 0, normalized, originDescription);
40
+ return _chunkPCAMDXJ4cjs.fromMap.call(void 0, normalized, originDescription);
41
41
  }
42
42
  function convert(v, atPath) {
43
43
  if (Array.isArray(v)) return v.map((e, i) => convert(e, `${atPath}[${i}]`));
@@ -49,14 +49,14 @@ function convert(v, atPath) {
49
49
  const seen = /* @__PURE__ */ new Map();
50
50
  for (const [k, e] of v) {
51
51
  if (k !== null && typeof k === "object") {
52
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
52
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
53
53
  `yaml: a collection key at "${atPath}" is not usable as an object key (spec F5.3)`,
54
54
  atPath
55
55
  );
56
56
  }
57
57
  const key = String(k);
58
58
  if (seen.has(key)) {
59
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
59
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
60
60
  `yaml: sibling mapping keys ${keyForm(seen.get(key))} and ${keyForm(k)} both give the key "${key}"${atPath === "" ? "" : ` at "${atPath}"`}; rename one of them, because one of the two values would otherwise be lost. Quoting a non-string key helps only where that changes the key text, as 0x10 does and 1 does not (spec F5.3)`,
61
61
  atPath
62
62
  );
@@ -77,7 +77,7 @@ function convert(v, atPath) {
77
77
  );
78
78
  }
79
79
  if (typeof v === "number" && !Number.isFinite(v)) {
80
- throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
80
+ throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
81
81
  `yaml: ${v} at "${atPath}" is not representable in HOCON (spec F0.6)`,
82
82
  atPath
83
83
  );
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  fromMap
3
- } from "../chunk-QY7ECGS6.js";
3
+ } from "../chunk-YRNDXYGQ.js";
4
4
  import {
5
5
  ConfigError,
6
6
  depthError,
7
7
  guardStackDepth,
8
8
  stripBom
9
- } from "../chunk-WTXULUZS.js";
9
+ } from "../chunk-GOXMKYWS.js";
10
10
 
11
11
  // src/adapters/yaml.ts
12
12
  import YAML from "yaml";
@@ -2778,7 +2778,7 @@ var SubstitutionResolver = class {
2778
2778
  }
2779
2779
  if (this.opts.useSystemEnvironment !== false) {
2780
2780
  const envKey = s.segments.map((seg) => seg.text).join(".");
2781
- const envVal = this.opts.env[envKey] ?? (s.prefixLen > 0 ? this.opts.env[s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".")] : void 0);
2781
+ const envVal = this.envVar(envKey) ?? (s.prefixLen > 0 ? this.envVar(s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".")) : void 0);
2782
2782
  if (envVal !== void 0) {
2783
2783
  const result = { kind: "scalar", raw: envVal, valueType: "string" };
2784
2784
  this.cache.set(key, result);
@@ -2813,17 +2813,26 @@ var SubstitutionResolver = class {
2813
2813
  const bases = this.candidateBases(s);
2814
2814
  for (const base of bases) {
2815
2815
  const key0 = base + "_0";
2816
- if (!(key0 in this.opts.env)) continue;
2816
+ if (this.envVar(key0) === void 0) continue;
2817
2817
  const items = [];
2818
2818
  for (let i = 0; ; i++) {
2819
- const k = base + "_" + i;
2820
- if (!(k in this.opts.env)) break;
2821
- items.push({ kind: "scalar", raw: this.opts.env[k], valueType: "string" });
2819
+ const v = this.envVar(base + "_" + i);
2820
+ if (v === void 0) break;
2821
+ items.push({ kind: "scalar", raw: v, valueType: "string" });
2822
2822
  }
2823
2823
  return { kind: "array", items };
2824
2824
  }
2825
2825
  return void 0;
2826
2826
  }
2827
+ /**
2828
+ * The environment variable `name`, or undefined when it is not set. Own keys
2829
+ * only: the environment is a plain object (process.env, or the caller's
2830
+ * `env`), so `env[name]` would answer `${?constructor}` or `${?toString}`
2831
+ * from Object.prototype (#228).
2832
+ */
2833
+ envVar(name) {
2834
+ return Object.prototype.hasOwnProperty.call(this.opts.env, name) ? this.opts.env[name] : void 0;
2835
+ }
2827
2836
  /**
2828
2837
  * Return the candidate base names for env-var-list lookup, in precedence order.
2829
2838
  * Mirrors the fully-qualified→bare fallback used by the scalar env path.
@@ -11,7 +11,7 @@ import {
11
11
  resolve,
12
12
  resolveAsync,
13
13
  tokenize
14
- } from "./chunk-WTXULUZS.js";
14
+ } from "./chunk-GOXMKYWS.js";
15
15
 
16
16
  // src/parse.ts
17
17
  import * as fs from "fs";
@@ -2778,7 +2778,7 @@ var SubstitutionResolver = class {
2778
2778
  }
2779
2779
  if (this.opts.useSystemEnvironment !== false) {
2780
2780
  const envKey = s.segments.map((seg) => seg.text).join(".");
2781
- const envVal = _nullishCoalesce(this.opts.env[envKey], () => ( (s.prefixLen > 0 ? this.opts.env[s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".")] : void 0)));
2781
+ const envVal = _nullishCoalesce(this.envVar(envKey), () => ( (s.prefixLen > 0 ? this.envVar(s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".")) : void 0)));
2782
2782
  if (envVal !== void 0) {
2783
2783
  const result = { kind: "scalar", raw: envVal, valueType: "string" };
2784
2784
  this.cache.set(key, result);
@@ -2813,17 +2813,26 @@ var SubstitutionResolver = class {
2813
2813
  const bases = this.candidateBases(s);
2814
2814
  for (const base of bases) {
2815
2815
  const key0 = base + "_0";
2816
- if (!(key0 in this.opts.env)) continue;
2816
+ if (this.envVar(key0) === void 0) continue;
2817
2817
  const items = [];
2818
2818
  for (let i = 0; ; i++) {
2819
- const k = base + "_" + i;
2820
- if (!(k in this.opts.env)) break;
2821
- items.push({ kind: "scalar", raw: this.opts.env[k], valueType: "string" });
2819
+ const v = this.envVar(base + "_" + i);
2820
+ if (v === void 0) break;
2821
+ items.push({ kind: "scalar", raw: v, valueType: "string" });
2822
2822
  }
2823
2823
  return { kind: "array", items };
2824
2824
  }
2825
2825
  return void 0;
2826
2826
  }
2827
+ /**
2828
+ * The environment variable `name`, or undefined when it is not set. Own keys
2829
+ * only: the environment is a plain object (process.env, or the caller's
2830
+ * `env`), so `env[name]` would answer `${?constructor}` or `${?toString}`
2831
+ * from Object.prototype (#228).
2832
+ */
2833
+ envVar(name) {
2834
+ return Object.prototype.hasOwnProperty.call(this.opts.env, name) ? this.opts.env[name] : void 0;
2835
+ }
2827
2836
  /**
2828
2837
  * Return the candidate base names for env-var-list lookup, in precedence order.
2829
2838
  * Mirrors the fully-qualified→bare fallback used by the scalar env path.