@o3co/ts.hocon 1.12.0 → 1.14.0

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.
Files changed (43) hide show
  1. package/README.ja.md +256 -32
  2. package/README.md +166 -32
  3. package/dist/adapters/env.cjs +26 -1678
  4. package/dist/adapters/env.d.cts +1 -1
  5. package/dist/adapters/env.d.ts +1 -1
  6. package/dist/adapters/env.js +11 -1625
  7. package/dist/adapters/json5.cjs +496 -0
  8. package/dist/adapters/json5.d.cts +47 -0
  9. package/dist/adapters/json5.d.ts +47 -0
  10. package/dist/adapters/json5.js +496 -0
  11. package/dist/adapters/jsonc.cjs +17 -1632
  12. package/dist/adapters/jsonc.d.cts +1 -1
  13. package/dist/adapters/jsonc.d.ts +1 -1
  14. package/dist/adapters/jsonc.js +9 -1586
  15. package/dist/adapters/properties.cjs +7 -1773
  16. package/dist/adapters/properties.d.cts +1 -1
  17. package/dist/adapters/properties.d.ts +1 -1
  18. package/dist/adapters/properties.js +6 -1735
  19. package/dist/adapters/toml.cjs +12 -1626
  20. package/dist/adapters/toml.d.cts +1 -1
  21. package/dist/adapters/toml.d.ts +1 -1
  22. package/dist/adapters/toml.js +10 -1589
  23. package/dist/adapters/yaml.cjs +20 -1635
  24. package/dist/adapters/yaml.d.cts +1 -1
  25. package/dist/adapters/yaml.d.ts +1 -1
  26. package/dist/adapters/yaml.js +10 -1589
  27. package/dist/chunk-GBNQADHT.cjs +83 -0
  28. package/dist/chunk-IMJ7QHIK.cjs +158 -0
  29. package/dist/chunk-QY7ECGS6.js +83 -0
  30. package/dist/chunk-RO4D6BH7.cjs +3792 -0
  31. package/dist/chunk-WTXULUZS.js +3792 -0
  32. package/dist/chunk-XWKO4JM3.js +158 -0
  33. package/dist/{config-Dlq6rF3w.d.cts → config-OccaKqXu.d.cts} +148 -4
  34. package/dist/{config-Dlq6rF3w.d.ts → config-OccaKqXu.d.ts} +148 -4
  35. package/dist/index.cjs +35 -3449
  36. package/dist/index.d.cts +2 -2
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +25 -3383
  39. package/dist/zod.cjs +107 -3291
  40. package/dist/zod.d.cts +83 -3
  41. package/dist/zod.d.ts +83 -3
  42. package/dist/zod.js +95 -3245
  43. package/package.json +12 -2
@@ -1,1677 +1,26 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
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; }
29
2
 
30
- // src/adapters/env.ts
31
- var env_exports = {};
32
- __export(env_exports, {
33
- loadEnv: () => loadEnv,
34
- parseDotEnv: () => parseDotEnv
35
- });
36
- module.exports = __toCommonJS(env_exports);
3
+ var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
37
4
 
38
- // src/coerce.ts
39
- var DECIMAL_NUMBER_RE = /^-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
40
- function isHoconWs(cp) {
41
- if (cp === 9 || cp === 10 || cp === 11 || cp === 12 || cp === 13) return true;
42
- if (cp >= 28 && cp <= 31) return true;
43
- if (cp === 32 || cp === 160 || cp === 65279) return true;
44
- if (cp === 5760) return true;
45
- if (cp >= 8192 && cp <= 8202) return true;
46
- if (cp === 8232 || cp === 8233 || cp === 8239 || cp === 8287) return true;
47
- if (cp === 12288) return true;
48
- return false;
49
- }
50
- function trimHoconWs(s) {
51
- let start = 0;
52
- let end = s.length;
53
- while (start < end && isHoconWs(s.charCodeAt(start))) {
54
- start++;
55
- }
56
- while (end > start && isHoconWs(s.charCodeAt(end - 1))) {
57
- end--;
58
- }
59
- return s.slice(start, end);
60
- }
61
- var TRUTHY = /* @__PURE__ */ new Set(["true", "yes", "on"]);
62
- var FALSY = /* @__PURE__ */ new Set(["false", "no", "off"]);
63
- function coerceBoolean(value) {
64
- const lower = value.toLowerCase();
65
- if (TRUTHY.has(lower)) return true;
66
- if (FALSY.has(lower)) return false;
67
- return void 0;
68
- }
69
- function coerceNumber(value) {
70
- if (!DECIMAL_NUMBER_RE.test(value)) return void 0;
71
- return Number(value);
72
- }
73
- var DURATION_UNITS = {
74
- ns: 1e-6,
75
- nanosecond: 1e-6,
76
- nanoseconds: 1e-6,
77
- us: 1e-3,
78
- microsecond: 1e-3,
79
- microseconds: 1e-3,
80
- ms: 1,
81
- millisecond: 1,
82
- milliseconds: 1,
83
- s: 1e3,
84
- second: 1e3,
85
- seconds: 1e3,
86
- m: 6e4,
87
- minute: 6e4,
88
- minutes: 6e4,
89
- h: 36e5,
90
- hour: 36e5,
91
- hours: 36e5,
92
- d: 864e5,
93
- day: 864e5,
94
- days: 864e5
95
- };
96
- var OUTPUT_DURATION_UNITS = {
97
- ns: 1e-6,
98
- us: 1e-3,
99
- ms: 1,
100
- s: 1e3,
101
- m: 6e4,
102
- h: 36e5,
103
- d: 864e5
104
- };
105
- function parseDuration(value, outputUnit = "ms") {
106
- const trimmed = trimHoconWs(value);
107
- let i = 0;
108
- while (i < trimmed.length) {
109
- const ch = trimmed[i];
110
- if (i === 0 && (ch === "-" || ch === "+")) {
111
- i++;
112
- continue;
113
- }
114
- if (ch !== "." && (ch < "0" || ch > "9")) break;
115
- i++;
116
- }
117
- if (i === 0) return NaN;
118
- const num = Number(trimmed.slice(0, i));
119
- if (Number.isNaN(num)) return NaN;
120
- const unit = trimHoconWs(trimmed.slice(i));
121
- const divisor = OUTPUT_DURATION_UNITS[outputUnit];
122
- if (divisor === void 0) return NaN;
123
- if (unit === "") {
124
- return num / divisor;
125
- }
126
- const mult = DURATION_UNITS[unit];
127
- if (mult === void 0) return NaN;
128
- const ms = num * mult;
129
- return ms / divisor;
130
- }
131
- var BYTE_UNITS = {
132
- B: 1,
133
- byte: 1,
134
- bytes: 1,
135
- KB: 1e3,
136
- kilobyte: 1e3,
137
- kilobytes: 1e3,
138
- KiB: 1024,
139
- kibibyte: 1024,
140
- kibibytes: 1024,
141
- MB: 1e6,
142
- megabyte: 1e6,
143
- megabytes: 1e6,
144
- MiB: 1048576,
145
- mebibyte: 1048576,
146
- mebibytes: 1048576,
147
- GB: 1e9,
148
- gigabyte: 1e9,
149
- gigabytes: 1e9,
150
- GiB: 1073741824,
151
- gibibyte: 1073741824,
152
- gibibytes: 1073741824,
153
- TB: 1e12,
154
- terabyte: 1e12,
155
- terabytes: 1e12,
156
- TiB: 1099511627776,
157
- tebibyte: 1099511627776,
158
- tebibytes: 1099511627776,
159
- // S21.4 — HOCON.md L1385: single-letter abbreviations → powers of two (java -Xmx convention).
160
- // Lightbend typesafe-config 1.4.3 verified: 1K=1024, 1M=1048576, etc.
161
- // Both upper- and lowercase accepted per Lightbend behaviour.
162
- // Z/Y (2^70/2^80) are deferred — they overflow MAX_SAFE_INTEGER and require BigInt accessor.
163
- K: 1024,
164
- k: 1024,
165
- M: 1024 ** 2,
166
- m: 1024 ** 2,
167
- G: 1024 ** 3,
168
- g: 1024 ** 3,
169
- T: 1024 ** 4,
170
- t: 1024 ** 4,
171
- P: 1024 ** 5,
172
- p: 1024 ** 5,
173
- E: 1024 ** 6,
174
- e: 1024 ** 6,
175
- // lowercase short-form aliases
176
- b: 1,
177
- kb: 1e3,
178
- kib: 1024,
179
- mb: 1e6,
180
- mib: 1048576,
181
- gb: 1e9,
182
- gib: 1073741824,
183
- tb: 1e12,
184
- tib: 1099511627776
185
- };
186
- var OUTPUT_BYTE_UNITS = {
187
- B: 1,
188
- KB: 1e3,
189
- KiB: 1024,
190
- MB: 1e6,
191
- MiB: 1048576,
192
- GB: 1e9,
193
- GiB: 1073741824,
194
- TB: 1e12,
195
- TiB: 1099511627776
196
- };
197
- function parseBytes(value, outputUnit = "B") {
198
- const trimmed = trimHoconWs(value);
199
- let i = 0;
200
- while (i < trimmed.length) {
201
- const ch = trimmed[i];
202
- if (i === 0 && (ch === "-" || ch === "+")) {
203
- i++;
204
- continue;
205
- }
206
- if (ch !== "." && (ch < "0" || ch > "9")) break;
207
- i++;
208
- }
209
- if (i === 0) return NaN;
210
- const num = Number(trimmed.slice(0, i));
211
- if (Number.isNaN(num)) return NaN;
212
- const unit = trimHoconWs(trimmed.slice(i));
213
- const divisor = OUTPUT_BYTE_UNITS[outputUnit];
214
- if (divisor === void 0) return NaN;
215
- if (unit === "") {
216
- const bytes2 = Math.trunc(num);
217
- if (Math.abs(bytes2) > Number.MAX_SAFE_INTEGER) {
218
- throw new RangeError("byte size overflows representable range (max 2^53-1 bytes)");
219
- }
220
- return bytes2 / divisor;
221
- }
222
- let mult = BYTE_UNITS[unit];
223
- if (mult === void 0) {
224
- mult = BYTE_UNITS[unit.toLowerCase()];
225
- }
226
- if (mult === void 0) return NaN;
227
- const bytes = num * mult;
228
- if (Math.abs(bytes) > Number.MAX_SAFE_INTEGER) {
229
- throw new RangeError("byte size overflows representable range (max 2^53-1 bytes)");
230
- }
231
- const result = bytes / divisor;
232
- return outputUnit === "B" ? Math.round(result) : result;
233
- }
234
5
 
235
- // src/errors.ts
236
- var ResolveError = class extends Error {
237
- constructor(message, path, line, col, file) {
238
- super(message);
239
- this.path = path;
240
- this.line = line;
241
- this.col = col;
242
- this.file = file;
243
- this.name = "ResolveError";
244
- }
245
- };
246
- var ConfigError = class extends Error {
247
- constructor(message, path) {
248
- super(message);
249
- this.path = path;
250
- this.name = "ConfigError";
251
- }
252
- };
253
- var NotResolvedError = class extends ConfigError {
254
- constructor(path) {
255
- super(`value at path "${path}" is not resolved (call resolve() first)`, path);
256
- this.name = "NotResolvedError";
257
- }
258
- };
259
6
 
260
- // src/internal/resolver/fold-self-ref.ts
261
- function substFullKey(s) {
262
- return stringSegmentsToKey(s.segments.map((seg) => seg.text));
263
- }
264
- function stringSegmentsToKey(segments) {
265
- return segments.map((t) => {
266
- if (t === "" || /[^a-zA-Z0-9\-_]/.test(t)) {
267
- return `"${t.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
268
- }
269
- return t;
270
- }).join(".");
271
- }
272
- function containsSelfRef(v, fullKey) {
273
- if (isSubst(v)) return !v.knownAbsent && substFullKey(v) === fullKey;
274
- if (isConcat(v)) return v.nodes.some((n) => containsSelfRef(n, fullKey));
275
- if (isResObj(v)) {
276
- for (const f of v.fields.values()) {
277
- if (containsSelfRef(f, fullKey)) return true;
278
- }
279
- return false;
280
- }
281
- const hv = v;
282
- if (hv.kind === "array") {
283
- return hv.items.some((item) => containsSelfRef(item, fullKey));
284
- }
285
- if (hv.kind === "object") {
286
- for (const f of hv.fields.values()) {
287
- if (containsSelfRef(f, fullKey)) return true;
288
- }
289
- return false;
290
- }
291
- return false;
292
- }
293
- function foldSelfRef(v, fullKey, replacement) {
294
- if (isSubst(v)) {
295
- return substFullKey(v) === fullKey ? replacement : v;
296
- }
297
- if (isConcat(v)) {
298
- return {
299
- _kind: "concat-placeholder",
300
- nodes: v.nodes.map((n) => foldSelfRef(n, fullKey, replacement)),
301
- line: v.line,
302
- col: v.col
303
- };
304
- }
305
- if (isResObj(v)) {
306
- const newFields = /* @__PURE__ */ new Map();
307
- for (const [k, val] of v.fields) {
308
- newFields.set(k, foldSelfRef(val, fullKey, replacement));
309
- }
310
- return { _kind: "res-obj", fields: newFields, priorValues: new Map(v.priorValues), resetKeys: new Set(v.resetKeys) };
311
- }
312
- const hv = v;
313
- if (hv.kind === "array") {
314
- return {
315
- kind: "array",
316
- items: hv.items.map((item) => foldSelfRef(item, fullKey, replacement))
317
- };
318
- }
319
- if (hv.kind === "object") {
320
- const newFields = /* @__PURE__ */ new Map();
321
- for (const [k, val] of hv.fields) {
322
- newFields.set(k, foldSelfRef(val, fullKey, replacement));
323
- }
324
- return { kind: "object", fields: newFields };
325
- }
326
- return v;
327
- }
328
- function foldOrSkipPrior(prior, fullKey, old) {
329
- if (!containsSelfRef(prior, fullKey)) return cloneResolverValue(prior);
330
- if (old === void 0) return foldOptionalSelfRefAbsent(prior, fullKey);
331
- return foldSelfRef(prior, fullKey, old);
332
- }
333
- function foldOptionalSelfRefAbsent(v, fullKey) {
334
- if (isSubst(v) && substFullKey(v) === fullKey) {
335
- if (!v.optional) return void 0;
336
- return {
337
- _kind: "subst-placeholder",
338
- segments: v.segments.map((seg) => ({ text: seg.text, line: seg.line, col: seg.col })),
339
- optional: v.optional,
340
- knownAbsent: true,
341
- listSuffix: v.listSuffix,
342
- line: v.line,
343
- col: v.col,
344
- prefixLen: v.prefixLen
345
- };
346
- }
347
- if (isConcat(v)) {
348
- const nodes = [];
349
- for (const node of v.nodes) {
350
- const folded = foldOptionalSelfRefAbsent(node, fullKey);
351
- if (folded === void 0) return void 0;
352
- nodes.push(folded);
353
- }
354
- return { _kind: "concat-placeholder", nodes, line: v.line, col: v.col };
355
- }
356
- if (isResObj(v)) {
357
- const fields = /* @__PURE__ */ new Map();
358
- for (const [key, value] of v.fields) {
359
- const folded = foldOptionalSelfRefAbsent(value, fullKey);
360
- if (folded === void 0) return void 0;
361
- fields.set(key, folded);
362
- }
363
- return { _kind: "res-obj", fields, priorValues: new Map(v.priorValues), resetKeys: new Set(v.resetKeys) };
364
- }
365
- const hv = v;
366
- if (hv.kind === "array") {
367
- const items = [];
368
- for (const item of hv.items) {
369
- const folded = foldOptionalSelfRefAbsent(item, fullKey);
370
- if (folded === void 0) return void 0;
371
- items.push(folded);
372
- }
373
- return { kind: "array", items };
374
- }
375
- if (hv.kind === "object") {
376
- const fields = /* @__PURE__ */ new Map();
377
- for (const [key, value] of hv.fields) {
378
- const folded = foldOptionalSelfRefAbsent(value, fullKey);
379
- if (folded === void 0) return void 0;
380
- fields.set(key, folded);
381
- }
382
- return { kind: "object", fields };
383
- }
384
- return cloneResolverValue(v);
385
- }
386
- function cloneResolverValue(v) {
387
- if (isSubst(v)) {
388
- return {
389
- _kind: "subst-placeholder",
390
- segments: v.segments.map((seg) => ({ text: seg.text, line: seg.line, col: seg.col })),
391
- optional: v.optional,
392
- knownAbsent: v.knownAbsent,
393
- listSuffix: v.listSuffix,
394
- line: v.line,
395
- col: v.col,
396
- prefixLen: v.prefixLen
397
- };
398
- }
399
- if (isConcat(v)) {
400
- return {
401
- _kind: "concat-placeholder",
402
- nodes: v.nodes.map((n) => cloneResolverValue(n)),
403
- line: v.line,
404
- col: v.col
405
- };
406
- }
407
- if (isResObj(v)) {
408
- const newFields = /* @__PURE__ */ new Map();
409
- for (const [k, val] of v.fields) newFields.set(k, cloneResolverValue(val));
410
- const newPriors = /* @__PURE__ */ new Map();
411
- for (const [k, val] of v.priorValues) newPriors.set(k, cloneResolverValue(val));
412
- return { _kind: "res-obj", fields: newFields, priorValues: newPriors, resetKeys: new Set(v.resetKeys) };
413
- }
414
- const hv = v;
415
- if (hv.kind === "array") {
416
- return {
417
- kind: "array",
418
- items: hv.items.map((item) => cloneResolverValue(item))
419
- };
420
- }
421
- if (hv.kind === "object") {
422
- const newFields = /* @__PURE__ */ new Map();
423
- for (const [k, val] of hv.fields) {
424
- newFields.set(k, cloneResolverValue(val));
425
- }
426
- return { kind: "object", fields: newFields };
427
- }
428
- return hv;
429
- }
430
- function containsSubstByPath(v, target) {
431
- if (isSubst(v)) return !v.knownAbsent && segmentsTextEqual(v.segments, target);
432
- if (isConcat(v)) return v.nodes.some((n) => containsSubstByPath(n, target));
433
- if (isResObj(v)) {
434
- for (const f of v.fields.values()) {
435
- if (containsSubstByPath(f, target)) return true;
436
- }
437
- return false;
438
- }
439
- const hv = v;
440
- if (hv.kind === "array") {
441
- return hv.items.some((item) => containsSubstByPath(item, target));
442
- }
443
- if (hv.kind === "object") {
444
- for (const f of hv.fields.values()) {
445
- if (containsSubstByPath(f, target)) return true;
446
- }
447
- return false;
448
- }
449
- return false;
450
- }
451
- function segmentsTextEqual(a, b) {
452
- if (a.length !== b.length) return false;
453
- for (let i = 0; i < a.length; i++) {
454
- const ai = a[i];
455
- const bi = b[i];
456
- if (ai === void 0 || bi === void 0 || ai.text !== bi.text) return false;
457
- }
458
- return true;
459
- }
460
-
461
- // src/internal/resolver/types.ts
462
- var separatorValues = /* @__PURE__ */ new WeakSet();
463
- function isSubst(v) {
464
- return v._kind === "subst-placeholder";
465
- }
466
- function isConcat(v) {
467
- return v._kind === "concat-placeholder";
468
- }
469
- function isResObj(v) {
470
- return v._kind === "res-obj";
471
- }
472
- function makeResObj() {
473
- return { _kind: "res-obj", fields: /* @__PURE__ */ new Map(), priorValues: /* @__PURE__ */ new Map(), resetKeys: /* @__PURE__ */ new Set() };
474
- }
475
- function mergeUnresolved(receiver, fallback) {
476
- const result = makeResObj();
477
- for (const [k, v] of fallback.fields) {
478
- result.fields.set(k, v);
479
- }
480
- for (const [k, v] of fallback.priorValues) {
481
- result.priorValues.set(k, v);
482
- }
483
- for (const [k, rv] of receiver.fields) {
484
- const existing = result.fields.get(k);
485
- if (existing !== void 0) {
486
- const recPrior = receiver.priorValues.get(k);
487
- if (recPrior !== void 0 && !isResObj(recPrior)) {
488
- result.fields.set(k, rv);
489
- continue;
490
- }
491
- if (isResObj(rv) && isResObj(existing)) {
492
- result.fields.set(k, mergeUnresolved(rv, existing));
493
- continue;
494
- }
495
- const foldedPrior = foldOrSkipPrior(existing, k, void 0);
496
- if (foldedPrior !== void 0) result.priorValues.set(k, foldedPrior);
497
- }
498
- result.fields.set(k, rv);
499
- }
500
- for (const [k, v] of receiver.priorValues) {
501
- if (receiver.fields.has(k)) {
502
- result.priorValues.set(k, v);
503
- }
504
- }
505
- return result;
506
- }
507
7
 
508
- // src/internal/resolver/utils.ts
509
- function segmentsToKey(segments) {
510
- return segments.map((s) => {
511
- const t = s.text;
512
- if (t === "" || /[^a-zA-Z0-9\-_]/.test(t)) {
513
- return `"${t.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
514
- }
515
- return t;
516
- }).join(".");
517
- }
518
- function lookupPath(root, segments) {
519
- const [head, ...tail] = segments;
520
- if (head === void 0) return void 0;
521
- const key = head.text;
522
- const val = root.fields.get(key);
523
- if (val === void 0) return void 0;
524
- if (tail.length === 0) return val;
525
- if (isResObj(val)) return lookupPath(val, tail);
526
- return void 0;
527
- }
528
- function lookupResObj(root, segments) {
529
- let cur = root;
530
- for (const seg of segments) {
531
- const val = cur.fields.get(seg.text);
532
- if (val === void 0 || !isResObj(val)) return void 0;
533
- cur = val;
534
- }
535
- return cur;
536
- }
537
- function deepMergeHoconValues(base, overlay) {
538
- const merged = new Map(base.fields);
539
- for (const [k, v] of overlay.fields) {
540
- const existing = merged.get(k);
541
- if (existing?.kind === "object" && v.kind === "object") {
542
- merged.set(k, deepMergeHoconValues(existing, v));
543
- } else {
544
- merged.set(k, v);
545
- }
546
- }
547
- return { kind: "object", fields: merged };
548
- }
549
8
 
550
- // src/internal/resolver/include-loader.ts
551
- var import_node_module = require("module");
552
- var nodePath = __toESM(require("path"), 1);
553
- var import_node_url = require("url");
554
9
 
555
- // src/internal/strip-bom.ts
556
- function stripBom(input) {
557
- return input.charCodeAt(0) === 65279 ? input.slice(1) : input;
558
- }
559
10
 
560
- // src/internal/depth.ts
561
- var MAX_PATH_SEGMENTS = 64;
562
- function tooDeep(segments) {
563
- return segments > MAX_PATH_SEGMENTS;
564
- }
565
- function guardStackDepth(fn, wrap) {
566
- try {
567
- return fn();
568
- } catch (e) {
569
- if (!isStackOverflow(e)) throw e;
570
- throw wrap(STACK_MESSAGE);
571
- }
572
- }
573
- var STACK_MESSAGE = "input is nested too deeply for this engine's stack, or contains a cycle (flatten the document, or break the cycle)";
574
- function isStackOverflow(e) {
575
- if (!(e instanceof RangeError)) return false;
576
- const m = e.message.toLowerCase();
577
- return m.includes("call stack") || // V8: "Maximum call stack size exceeded"
578
- m.includes("recursion") || // SpiderMonkey: "too much recursion"
579
- m.includes("stack overflow");
580
- }
581
- function depthError(message) {
582
- return new ConfigError(message, "");
583
- }
584
-
585
- // src/internal/properties/properties.ts
586
- function nestPairs(pairs) {
587
- const root = /* @__PURE__ */ Object.create(null);
588
- const sorted = [...pairs].sort(([a], [b]) => compareSegments(a, b));
589
- for (const [segments, value] of sorted) {
590
- setNested(root, segments, value);
591
- }
592
- return root;
593
- }
594
- function compareSegments(a, b) {
595
- const n = Math.min(a.length, b.length);
596
- for (let i = 0; i < n; i++) {
597
- const x = a[i];
598
- const y = b[i];
599
- if (x !== y) return x < y ? -1 : 1;
600
- }
601
- return a.length - b.length;
602
- }
603
- function pathKey(segments) {
604
- return JSON.stringify(segments);
605
- }
606
- function setNested(obj, segments, value) {
607
- let current = obj;
608
- for (let i = 0; i < segments.length - 1; i++) {
609
- const seg = segments[i];
610
- if (!(seg in current) || typeof current[seg] !== "object" || current[seg] === null) {
611
- current[seg] = /* @__PURE__ */ Object.create(null);
612
- }
613
- current = current[seg];
614
- }
615
- const last = segments[segments.length - 1];
616
- if (typeof current[last] === "object" && current[last] !== null) return;
617
- current[last] = value;
618
- }
619
-
620
- // src/value/numeric-array.ts
621
- function numericObjectToArray(value) {
622
- if (value.kind !== "object") return null;
623
- if (value.fields.size === 0) return null;
624
- const canonicalInt = /^(0|[1-9][0-9]*)$/;
625
- const eligible = [];
626
- for (const [key, val] of value.fields) {
627
- if (!canonicalInt.test(key)) continue;
628
- const n = Number(key);
629
- if (!Number.isInteger(n) || n > 2147483647) continue;
630
- eligible.push({ n, v: val });
631
- }
632
- if (eligible.length === 0) return null;
633
- eligible.sort((a, b) => a.n - b.n);
634
- return eligible.map((e) => e.v);
635
- }
636
-
637
- // src/internal/resolver/substitution-resolver.ts
638
- var SubstitutionResolver = class {
639
- constructor(root, opts) {
640
- this.root = root;
641
- this.opts = opts;
642
- this.resolving = /* @__PURE__ */ new Set();
643
- this.cache = /* @__PURE__ */ new Map();
644
- // Tracks ConcatPlaceholder nodes currently being iterated by resolveConcat.
645
- // Used by isSelfRef detection: fires only when found === a concat currently
646
- // mid-iteration (i.e. we are inside found's own resolution), preventing the
647
- // "foofoo" double-count without misfiring when an external field looks up the
648
- // same concat via a substitution (multi-reviewer convergence fix).
649
- //
650
- // Spec deviation: the S13a.13 spec ★1 decision #1 specified path-equality
651
- // preservation for self-ref detection. Round-2 multi-agent-review surfaced a
652
- // false-positive on external lookups (`a = ${?a}foo; b = ${a}`), so the
653
- // criterion was tightened to node-membership-in-iterating-set — strictly
654
- // narrower than path-equality. Spec amendment deferred to a follow-up
655
- // xx.hocon PR (see Phase 6 #3f close-out notes).
656
- this.resolvingConcats = /* @__PURE__ */ new WeakSet();
657
- // Path stack tracking the full dotted path of the field currently being
658
- // assigned in `resolveResObj`. Leaf keys are pushed on entry to each
659
- // `(key, val)` iteration and popped on exit, so nested objects build up
660
- // the full path (e.g. `["o", "history"]` while resolving `o.history`).
661
- //
662
- // Used to tighten self-ref detection at the L192 found-lookup site:
663
- // a substitution `${X}` whose looked-up value contains a Subst pointing
664
- // at `X` is only a true self-reference when the field currently being
665
- // assigned is `X` (or a descendant of `X`). Without this guard, an
666
- // external lookup like `b = ${o}` (where o has a self-referential
667
- // field) would mis-fire and short-circuit to o's prior, returning the
668
- // wrong value for b. The is_owner gate (rfp prefix-matches s.segments)
669
- // narrows the check to the owner case only.
670
- //
671
- // Cross-impl with rs.hocon v1.5.1's resolving_field_path (same purpose,
672
- // same prefix-match semantics).
673
- this.resolvingFieldPath = [];
674
- }
675
- /** Returns a prefix for error messages, including origin info when set. */
676
- originPrefix() {
677
- return this.opts.originDescription ? `${this.opts.originDescription}: ` : "";
678
- }
679
- resolve() {
680
- return this.resolveResObj(this.root);
681
- }
682
- resolveResObj(obj) {
683
- const result = /* @__PURE__ */ new Map();
684
- for (const [key, val] of obj.fields) {
685
- this.resolvingFieldPath.push(key);
686
- const fullCacheKey = stringSegmentsToKey(this.resolvingFieldPath);
687
- this.cache.delete(fullCacheKey);
688
- let resolved;
689
- try {
690
- resolved = this.resolveVal(val, obj);
691
- } finally {
692
- this.resolvingFieldPath.pop();
693
- }
694
- if (resolved !== void 0) {
695
- if (resolved.kind === "object") {
696
- const prior = obj.priorValues.get(key);
697
- if (prior !== void 0) {
698
- const priorResolved = this.resolveVal(prior, obj);
699
- if (priorResolved !== void 0 && priorResolved.kind === "object") {
700
- const finalValue = deepMergeHoconValues(
701
- priorResolved,
702
- resolved
703
- );
704
- result.set(key, finalValue);
705
- this.cache.set(fullCacheKey, finalValue);
706
- this.cacheDescendants(fullCacheKey, finalValue);
707
- continue;
708
- }
709
- }
710
- }
711
- result.set(key, resolved);
712
- this.cache.set(fullCacheKey, resolved);
713
- this.cacheDescendants(fullCacheKey, resolved);
714
- } else {
715
- const prior = obj.priorValues.get(key);
716
- if (prior !== void 0) {
717
- const priorResolved = this.resolveVal(prior, obj);
718
- if (priorResolved !== void 0) {
719
- result.set(key, priorResolved);
720
- this.cache.set(fullCacheKey, priorResolved);
721
- this.cacheDescendants(fullCacheKey, priorResolved);
722
- }
723
- }
724
- }
725
- }
726
- return { kind: "object", fields: result };
727
- }
728
- cacheDescendants(prefix, value) {
729
- if (value.kind !== "object") return;
730
- for (const [key, child] of value.fields) {
731
- const childKey = `${prefix}.${stringSegmentsToKey([key])}`;
732
- this.cache.set(childKey, child);
733
- this.cacheDescendants(childKey, child);
734
- }
735
- }
736
- resolveVal(v, scope) {
737
- if (isSubst(v)) return this.resolveSubst(v, scope);
738
- if (isConcat(v)) {
739
- this.resolvingConcats.add(v);
740
- try {
741
- const concatResult = this.resolveConcat(v.nodes, scope, v.line, v.col);
742
- return concatResult;
743
- } finally {
744
- this.resolvingConcats.delete(v);
745
- }
746
- }
747
- if (isResObj(v)) return this.resolveResObj(v);
748
- const hv = v;
749
- if (hv.kind === "array") {
750
- return {
751
- kind: "array",
752
- items: hv.items.map(
753
- (item) => this.resolveVal(item, scope) ?? { kind: "scalar", raw: "null", valueType: "null" }
754
- )
755
- };
756
- }
757
- return hv;
758
- }
759
- resolveSubst(s, scope) {
760
- if (s.knownAbsent) return void 0;
761
- const key = s.listSuffix ? `${segmentsToKey(s.segments)}[]` : segmentsToKey(s.segments);
762
- if (this.cache.has(key)) return this.cache.get(key);
763
- if (this.resolving.has(key)) {
764
- let prior;
765
- if (s.segments.length > 1) {
766
- const leafSeg = s.segments[s.segments.length - 1]?.text ?? "";
767
- const parentScope = lookupResObj(
768
- this.root,
769
- s.segments.slice(0, s.segments.length - 1)
770
- );
771
- prior = parentScope?.priorValues.get(leafSeg);
772
- } else {
773
- const rootSeg = s.segments[0]?.text ?? "";
774
- prior = scope.priorValues.get(rootSeg) ?? this.root.priorValues.get(rootSeg);
775
- }
776
- if (prior !== void 0) {
777
- const saved = this.resolving;
778
- this.resolving = new Set(saved);
779
- try {
780
- return this.resolveVal(prior, scope);
781
- } finally {
782
- this.resolving = saved;
783
- }
784
- }
785
- if (s.optional) return void 0;
786
- throw new ResolveError(
787
- this.originPrefix() + `circular substitution: ${key}`,
788
- key,
789
- s.line,
790
- s.col
791
- );
792
- }
793
- this.resolving.add(key);
794
- try {
795
- const found = lookupPath(this.root, s.segments);
796
- if (found !== void 0) {
797
- const rfp = this.resolvingFieldPath;
798
- const isOwner = rfp.length >= s.segments.length && s.segments.every((seg, i) => rfp[i] === seg.text);
799
- const isSelfRef = isConcat(found) && this.resolvingConcats.has(found) || isOwner && containsSubstByPath(found, s.segments);
800
- if (isSelfRef) {
801
- let prior;
802
- if (s.segments.length > 1) {
803
- const leafSeg = s.segments[s.segments.length - 1]?.text ?? "";
804
- const parentScope = lookupResObj(
805
- this.root,
806
- s.segments.slice(0, s.segments.length - 1)
807
- );
808
- prior = parentScope?.priorValues.get(leafSeg);
809
- } else {
810
- const rootSeg = s.segments[0]?.text ?? "";
811
- prior = scope.priorValues.get(rootSeg) ?? this.root.priorValues.get(rootSeg);
812
- }
813
- if (prior !== void 0) {
814
- const result2 = this.resolveVal(prior, scope);
815
- if (result2 !== void 0) this.cache.set(key, result2);
816
- return result2;
817
- }
818
- if (s.optional) return void 0;
819
- throw new ResolveError(
820
- `${this.originPrefix()}could not resolve substitution: \${${key}}`,
821
- key,
822
- s.line,
823
- s.col
824
- );
825
- }
826
- let result = this.resolveVal(found, scope);
827
- const effectiveLen = s.segments.length - s.prefixLen;
828
- if (effectiveLen === 1 && result !== void 0 && result.kind === "object") {
829
- const leafSeg = s.segments[s.segments.length - 1]?.text ?? "";
830
- let prior;
831
- if (s.prefixLen > 0) {
832
- const parentScope = lookupResObj(
833
- this.root,
834
- s.segments.slice(0, s.segments.length - 1)
835
- );
836
- prior = parentScope?.priorValues.get(leafSeg);
837
- } else {
838
- prior = scope.priorValues.get(leafSeg) ?? this.root.priorValues.get(leafSeg);
839
- }
840
- if (prior !== void 0) {
841
- const priorResolved = this.resolveVal(prior, scope);
842
- if (priorResolved !== void 0 && priorResolved.kind === "object") {
843
- result = deepMergeHoconValues(
844
- priorResolved,
845
- result
846
- );
847
- }
848
- }
849
- }
850
- if (result !== void 0) this.cache.set(key, result);
851
- return result;
852
- }
853
- if (s.prefixLen > 0 && s.segments.length > s.prefixLen) {
854
- const originalSegments = s.segments.slice(s.prefixLen);
855
- const fallbackFound = lookupPath(this.root, originalSegments);
856
- if (fallbackFound !== void 0) {
857
- let result = this.resolveVal(fallbackFound, scope);
858
- if (originalSegments.length === 1 && result !== void 0 && result.kind === "object") {
859
- const rootSeg = originalSegments[0]?.text ?? "";
860
- const prior = this.root.priorValues.get(rootSeg);
861
- if (prior !== void 0) {
862
- const priorResolved = this.resolveVal(prior, scope);
863
- if (priorResolved !== void 0 && priorResolved.kind === "object") {
864
- result = deepMergeHoconValues(
865
- priorResolved,
866
- result
867
- );
868
- }
869
- }
870
- }
871
- if (result !== void 0) this.cache.set(key, result);
872
- return result;
873
- }
874
- }
875
- if (s.listSuffix && this.opts.useSystemEnvironment !== false) {
876
- const result = this.resolveEnvList(s);
877
- if (result !== void 0) {
878
- this.cache.set(key, result);
879
- return result;
880
- }
881
- if (s.optional) return void 0;
882
- const envBase = s.segments.map((seg) => seg.text).join(".");
883
- throw new ResolveError(
884
- `${this.originPrefix()}could not resolve substitution: \${${key}} (no environment variables ${envBase}_0, ${envBase}_1, \u2026 set)`,
885
- key,
886
- s.line,
887
- s.col
888
- );
889
- } else if (s.listSuffix) {
890
- if (s.optional) return void 0;
891
- if (this.opts.allowUnresolved) return s;
892
- throw new ResolveError(
893
- `${this.originPrefix()}could not resolve substitution: \${${key}}`,
894
- key,
895
- s.line,
896
- s.col
897
- );
898
- }
899
- if (this.opts.useSystemEnvironment !== false) {
900
- const envKey = s.segments.map((seg) => seg.text).join(".");
901
- const envVal = this.opts.env[envKey] ?? (s.prefixLen > 0 ? this.opts.env[s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".")] : void 0);
902
- if (envVal !== void 0) {
903
- const result = { kind: "scalar", raw: envVal, valueType: "string" };
904
- this.cache.set(key, result);
905
- return result;
906
- }
907
- }
908
- if (s.optional) return void 0;
909
- if (this.opts.allowUnresolved) {
910
- return s;
911
- }
912
- throw new ResolveError(
913
- `${this.originPrefix()}could not resolve substitution: \${${key}}`,
914
- key,
915
- s.line,
916
- s.col
917
- );
918
- } finally {
919
- this.resolving.delete(key);
920
- }
921
- }
922
- /**
923
- * S13c: scan environment for NAME_0, NAME_1, … and return an Array<Scalar(String)>.
924
- *
925
- * Candidate bases follow the same fully-qualified→bare order used by the scalar
926
- * env fallback. The first base whose _0 key is present wins entirely — no
927
- * cross-base merging (spec §Relativized fallback precedence rules).
928
- *
929
- * Returns the HoconValue Array if any candidate base has _0, or undefined if
930
- * none do (caller applies optional/required handling).
931
- */
932
- resolveEnvList(s) {
933
- const bases = this.candidateBases(s);
934
- for (const base of bases) {
935
- const key0 = base + "_0";
936
- if (!(key0 in this.opts.env)) continue;
937
- const items = [];
938
- for (let i = 0; ; i++) {
939
- const k = base + "_" + i;
940
- if (!(k in this.opts.env)) break;
941
- items.push({ kind: "scalar", raw: this.opts.env[k], valueType: "string" });
942
- }
943
- return { kind: "array", items };
944
- }
945
- return void 0;
946
- }
947
- /**
948
- * Return the candidate base names for env-var-list lookup, in precedence order.
949
- * Mirrors the fully-qualified→bare fallback used by the scalar env path.
950
- */
951
- candidateBases(s) {
952
- const full = s.segments.map((seg) => seg.text).join(".");
953
- if (s.prefixLen === 0) return [full];
954
- const bare = s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".");
955
- return [full, bare];
956
- }
957
- resolveConcat(nodes, scope, line = 0, col = 0) {
958
- const rawResolved = nodes.map((n) => this.resolveVal(n, scope));
959
- if (this.opts.allowUnresolved) {
960
- for (const v of rawResolved) {
961
- if (v !== void 0 && isSubst(v)) {
962
- return v;
963
- }
964
- }
965
- }
966
- const resolved = rawResolved.filter((v) => v !== void 0);
967
- if (resolved.length === 0) return void 0;
968
- if (resolved.length === 1) return resolved[0];
969
- const nonSep = resolved.filter((v) => !separatorValues.has(v));
970
- if (nonSep.length === 0) {
971
- const str = resolved.map((v) => v.kind === "scalar" ? v.raw : JSON.stringify(v)).join("");
972
- return { kind: "scalar", raw: str, valueType: "string" };
973
- }
974
- const joinPair = (left, right) => {
975
- if (left.kind === "object" && right.kind === "object") {
976
- return deepMergeHoconValues(left, right);
977
- }
978
- if (left.kind === "array" && right.kind === "object") {
979
- const converted = numericObjectToArray(right);
980
- if (converted !== null) {
981
- return { kind: "array", items: [...left.items, ...converted] };
982
- }
983
- throw new ResolveError(
984
- "cannot concatenate array with object: value concatenation requires same-kind operands (S10.4)",
985
- "",
986
- line,
987
- col
988
- );
989
- }
990
- if (left.kind === "object" && right.kind === "array") {
991
- const converted = numericObjectToArray(left);
992
- if (converted !== null) {
993
- return { kind: "array", items: [...converted, ...right.items] };
994
- }
995
- throw new ResolveError(
996
- "cannot concatenate object with array: value concatenation requires same-kind operands (S10.4)",
997
- "",
998
- line,
999
- col
1000
- );
1001
- }
1002
- if (left.kind === "array" && right.kind === "array") {
1003
- return { kind: "array", items: [...left.items, ...right.items] };
1004
- }
1005
- if (left.kind === "array" || right.kind === "array") {
1006
- throw new ResolveError(
1007
- `cannot concatenate ${left.kind} with ${right.kind}: arrays and objects may not appear in string value concatenation (S10.13)`,
1008
- "",
1009
- line,
1010
- col
1011
- );
1012
- }
1013
- if (left.kind === "object" || right.kind === "object") {
1014
- throw new ResolveError(
1015
- `cannot concatenate ${left.kind} with ${right.kind}: arrays and objects may not appear in string value concatenation (S10.13)`,
1016
- "",
1017
- line,
1018
- col
1019
- );
1020
- }
1021
- return { kind: "scalar", raw: left.raw + right.raw, valueType: "string" };
1022
- };
1023
- const [head, ...tail] = nonSep;
1024
- const folded = tail.reduce(joinPair, head);
1025
- if (folded.kind === "scalar") {
1026
- const str = resolved.map((v) => v.kind === "scalar" ? v.raw : JSON.stringify(v)).join("");
1027
- return { kind: "scalar", raw: str, valueType: "string" };
1028
- }
1029
- return folded;
1030
- }
1031
- };
1032
-
1033
- // src/internal/resolver/resolver.ts
1034
- function resolveTree(tree, opts) {
1035
- return new SubstitutionResolver(tree, opts).resolve();
1036
- }
1037
- function containsPlaceholders(tree) {
1038
- for (const val of tree.fields.values()) {
1039
- if (valContainsPlaceholders(val)) return true;
1040
- }
1041
- return false;
1042
- }
1043
- function valContainsPlaceholders(v) {
1044
- const rv = v;
1045
- if (isSubst(rv) || isConcat(rv)) return true;
1046
- if (isResObj(rv)) return containsPlaceholders(rv);
1047
- const hv = v;
1048
- if (hv?.kind === "array") {
1049
- return hv.items.some((item) => valContainsPlaceholders(item));
1050
- }
1051
- return false;
1052
- }
1053
- function buildPartialHoconFromResObj(tree) {
1054
- const fields = /* @__PURE__ */ new Map();
1055
- for (const [k, v] of tree.fields) {
1056
- if (!isSubst(v) && !isConcat(v)) {
1057
- if (isResObj(v)) {
1058
- fields.set(k, buildPartialHoconFromResObj(v));
1059
- } else {
1060
- if (!valContainsPlaceholders(v)) {
1061
- fields.set(k, v);
1062
- }
1063
- }
1064
- }
1065
- }
1066
- return { kind: "object", fields };
1067
- }
1068
- function hoconValueToResObj2(value) {
1069
- const obj = makeResObj();
1070
- for (const [k, v] of value.fields) {
1071
- if (v.kind === "object") {
1072
- obj.fields.set(k, hoconValueToResObj2(v));
1073
- } else {
1074
- obj.fields.set(k, v);
1075
- }
1076
- }
1077
- return obj;
1078
- }
1079
-
1080
- // src/config.ts
1081
- var Config = class _Config {
1082
- constructor(root, opts) {
1083
- this.root = root;
1084
- this._resolved = opts?.resolved ?? true;
1085
- this._parseBaseDir = opts?.parseBaseDir;
1086
- this._originDescription = opts?.originDescription;
1087
- this._resObjRoot = opts?.resObjRoot;
1088
- this._resolveOpts = opts?.resolveOpts;
1089
- }
1090
- /** Returns true when the Config's value tree contains no unresolved
1091
- * substitution placeholders. Whole-config granularity (E12 decision 11). */
1092
- isResolved() {
1093
- return this._resolved;
1094
- }
1095
- /** @internal Test-only: construct a resolved Config from a HoconValue. */
1096
- static _fromResolvedValue(root, opts) {
1097
- return new _Config(root, { resolved: true, originDescription: opts?.originDescription });
1098
- }
1099
- /** @internal Construct an unresolved Config carrying a ResObj tree.
1100
- * Used by parseStringWithOptions (deferred path) in T6. */
1101
- static _fromUnresolvedResObj(tree, opts) {
1102
- const partialRoot = buildPartialHoconFromResObj(tree);
1103
- return new _Config(partialRoot, {
1104
- resolved: opts.resolved,
1105
- parseBaseDir: opts.parseBaseDir,
1106
- originDescription: opts.originDescription,
1107
- resObjRoot: tree,
1108
- resolveOpts: opts.resolveOpts
1109
- });
1110
- }
1111
- get(path) {
1112
- const v = this.lookupNode(path);
1113
- if (v === void 0) return void 0;
1114
- return hoconToJs(v);
1115
- }
1116
- /**
1117
- * Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
1118
- * {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
1119
- * `get` (which decodes to a plain JS value), this exposes the value tree for
1120
- * structural introspection via the `value.ts` accessors (`asString`, `asObject`,
1121
- * `isScalar`, …).
1122
- *
1123
- * `getValue('')` returns the root object node.
1124
- *
1125
- * Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
1126
- * the `HoconValue` union has no placeholder variant, so an unresolved value
1127
- * cannot be represented. This matches `getConfig` / `getList`.
1128
- */
1129
- getValue(path) {
1130
- const v = this.lookupNode(path);
1131
- if (v === void 0) {
1132
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1133
- throw new NotResolvedError(path);
1134
- }
1135
- return void 0;
1136
- }
1137
- if (v.kind !== "scalar" && !this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1138
- throw new NotResolvedError(path);
1139
- }
1140
- return v;
1141
- }
1142
- getString(path) {
1143
- const v = this.requireScalar(path);
1144
- if (v.valueType === "null") {
1145
- throw new ConfigError(`expected string at ${path}, got ${v.valueType}`, path);
1146
- }
1147
- return v.raw;
1148
- }
1149
- getNumber(path) {
1150
- const v = this.requireScalar(path);
1151
- const coerced = coerceNumber(v.raw);
1152
- if (coerced !== void 0) return coerced;
1153
- throw new ConfigError(`expected number at ${path}, got ${v.valueType}`, path);
1154
- }
1155
- getBoolean(path) {
1156
- const v = this.requireScalar(path);
1157
- const coerced = coerceBoolean(v.raw);
1158
- if (coerced !== void 0) return coerced;
1159
- throw new ConfigError(`expected boolean at ${path}, got ${v.valueType}`, path);
1160
- }
1161
- getDuration(path, unit) {
1162
- const v = this.requireScalar(path);
1163
- if (v.valueType !== "string" && v.valueType !== "number") {
1164
- throw new ConfigError(`expected duration at ${path}, got ${v.valueType}`, path);
1165
- }
1166
- const result = parseDuration(v.raw, unit);
1167
- if (Number.isNaN(result)) throw new ConfigError(`invalid duration at ${path}: ${JSON.stringify(v.raw)}`, path);
1168
- return result;
1169
- }
1170
- getBytes(path, unit) {
1171
- const v = this.requireScalar(path);
1172
- if (v.valueType !== "string" && v.valueType !== "number") {
1173
- throw new ConfigError(`expected byte size at ${path}, got ${v.valueType}`, path);
1174
- }
1175
- const result = parseBytes(v.raw, unit);
1176
- if (Number.isNaN(result)) throw new ConfigError(`invalid byte size at ${path}: ${JSON.stringify(v.raw)}`, path);
1177
- if (result < 0) throw new ConfigError(`byte size must be non-negative at ${path}: ${JSON.stringify(v.raw)}`, path);
1178
- return result;
1179
- }
1180
- getConfig(path) {
1181
- const v = this.lookupNode(path);
1182
- if (v === void 0) {
1183
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1184
- throw new NotResolvedError(path);
1185
- }
1186
- throw new ConfigError(`path not found: ${path}`, path);
1187
- }
1188
- if (v.kind !== "object") throw new ConfigError(`expected object at ${path}`, path);
1189
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1190
- throw new NotResolvedError(path);
1191
- }
1192
- return new _Config(v, { resolved: this._resolved });
1193
- }
1194
- getList(path) {
1195
- const v = this.lookupNode(path);
1196
- if (v === void 0) {
1197
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1198
- throw new NotResolvedError(path);
1199
- }
1200
- throw new ConfigError(`path not found: ${path}`, path);
1201
- }
1202
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1203
- throw new NotResolvedError(path);
1204
- }
1205
- if (v.kind === "object") {
1206
- const converted = numericObjectToArray(v);
1207
- if (converted !== null) return converted.map((item) => hoconToJs(item));
1208
- }
1209
- if (v.kind !== "array") throw new ConfigError(`expected array at ${path}`, path);
1210
- return v.items.map((item) => hoconToJs(item));
1211
- }
1212
- has(path) {
1213
- return this.lookupNode(path) !== void 0;
1214
- }
1215
- keys() {
1216
- return [...this.root.fields.keys()];
1217
- }
1218
- withFallback(fallback) {
1219
- if (fallback == null) return this;
1220
- const selfTree = this._resObjRoot ?? hoconValueToResObj2(this.root);
1221
- const fbTree = fallback._resObjRoot ?? hoconValueToResObj2(fallback.root);
1222
- const merged = mergeUnresolved(selfTree, fbTree);
1223
- const hasPlaceholders = containsPlaceholders(merged);
1224
- const partialRoot = buildPartialHoconFromResObj(merged);
1225
- return new _Config(partialRoot, {
1226
- resolved: !hasPlaceholders,
1227
- parseBaseDir: this._parseBaseDir,
1228
- originDescription: this._originDescription,
1229
- resObjRoot: merged,
1230
- resolveOpts: this._resolveOpts ?? fallback._resolveOpts
1231
- });
1232
- }
1233
- /**
1234
- * Runs substitution resolution (phase 2) on the stored unresolved tree.
1235
- * Idempotent: calling resolve() on an already-resolved Config returns an
1236
- * equivalent resolved Config.
1237
- *
1238
- * opts.allowUnresolved (default false) — when true, leaves unresolved
1239
- * non-optional placeholders in place rather than throwing.
1240
- * opts.useSystemEnvironment (default true) — when false, env var lookups
1241
- * are suppressed (hermetic resolution).
1242
- *
1243
- * E12 decision 3.
1244
- */
1245
- resolve(opts = {}) {
1246
- if (this._resolved) {
1247
- return new _Config(this.root, {
1248
- resolved: true,
1249
- parseBaseDir: this._parseBaseDir,
1250
- originDescription: this._originDescription
1251
- });
1252
- }
1253
- const tree = this._resObjRoot;
1254
- if (!tree) {
1255
- return new _Config(this.root, { resolved: true });
1256
- }
1257
- const resolveOpts = {
1258
- ...this._resolveOpts ?? { env: {}, baseDir: void 0, readFileSync: () => {
1259
- throw new Error("no files");
1260
- } },
1261
- allowUnresolved: opts.allowUnresolved ?? false,
1262
- useSystemEnvironment: opts.useSystemEnvironment ?? true,
1263
- originDescription: this._originDescription
1264
- };
1265
- const resolved = resolveTree(tree, resolveOpts);
1266
- if (resolved.kind !== "object") throw new Error("resolve: expected object root");
1267
- if (opts.allowUnresolved) {
1268
- const { stripped, hadPlaceholders } = stripPlaceholderFields(resolved);
1269
- return new _Config(stripped, {
1270
- resolved: !hadPlaceholders,
1271
- parseBaseDir: this._parseBaseDir,
1272
- originDescription: this._originDescription,
1273
- resObjRoot: hadPlaceholders ? tree : void 0,
1274
- resolveOpts: hadPlaceholders ? resolveOpts : void 0
1275
- });
1276
- }
1277
- return new _Config(resolved, {
1278
- resolved: true,
1279
- parseBaseDir: this._parseBaseDir,
1280
- originDescription: this._originDescription
1281
- });
1282
- }
1283
- /**
1284
- * Resolves receiver substitutions using source as lookup context.
1285
- * Source's keys are NOT merged into the result — differs from
1286
- * `this.withFallback(source).resolve()` which includes source keys.
1287
- *
1288
- * Precondition (E12 decision 10): source must be resolved. If
1289
- * source.isResolved() is false, throws NotResolvedError.
1290
- *
1291
- * On an already-resolved receiver, resolveWith is a no-op (returns an
1292
- * equivalent resolved Config, source keys not included).
1293
- *
1294
- * E12 decisions 9, 10.
1295
- */
1296
- resolveWith(source, opts = {}) {
1297
- if (!source.isResolved()) {
1298
- throw new NotResolvedError("source");
1299
- }
1300
- if (this._resolved) {
1301
- return new _Config(this.root, {
1302
- resolved: true,
1303
- parseBaseDir: this._parseBaseDir,
1304
- originDescription: this._originDescription
1305
- });
1306
- }
1307
- const receiverTree = this._resObjRoot ?? hoconValueToResObj2(this.root);
1308
- const srcTree = hoconValueToResObj2(source.root);
1309
- const merged = mergeUnresolved(receiverTree, srcTree);
1310
- const resolveOpts = {
1311
- ...this._resolveOpts ?? { env: {}, baseDir: void 0, readFileSync: () => {
1312
- throw new Error("no files");
1313
- } },
1314
- allowUnresolved: opts.allowUnresolved ?? false,
1315
- useSystemEnvironment: opts.useSystemEnvironment ?? true,
1316
- originDescription: this._originDescription
1317
- };
1318
- const resolved = resolveTree(merged, resolveOpts);
1319
- if (resolved.kind !== "object") throw new Error("resolveWith: expected object root");
1320
- const receiverShapeForFilter = resObjToKeyShape(receiverTree);
1321
- const filtered = filterByReceiverShape(resolved, receiverShapeForFilter);
1322
- if (opts.allowUnresolved) {
1323
- const { stripped, hadPlaceholders } = stripPlaceholderFields(filtered);
1324
- return new _Config(stripped, {
1325
- resolved: !hadPlaceholders,
1326
- parseBaseDir: this._parseBaseDir,
1327
- originDescription: this._originDescription,
1328
- resObjRoot: hadPlaceholders ? receiverTree : void 0,
1329
- resolveOpts: hadPlaceholders ? resolveOpts : void 0
1330
- });
1331
- }
1332
- return new _Config(filtered, {
1333
- resolved: true,
1334
- parseBaseDir: this._parseBaseDir,
1335
- originDescription: this._originDescription
1336
- });
1337
- }
1338
- /**
1339
- * The whole config as plain JS data: objects, arrays, strings, numbers,
1340
- * booleans and `null`.
1341
- *
1342
- * Keys are reproduced exactly as the config carries them, `__proto__`,
1343
- * `constructor` and `prototype` included: each is defined as an **own data
1344
- * property**, so the returned object's prototype is always
1345
- * `Object.prototype`, and this call writes nothing to the global one.
1346
- *
1347
- * ### Passing the result to other code
1348
- *
1349
- * A config file — especially a `.properties` file or an env namespace you
1350
- * merged in — can therefore hand you an own `__proto__` key, and what happens
1351
- * next depends entirely on how the consumer copies it:
1352
- *
1353
- * ```ts
1354
- * const data = cfg.toObject()
1355
- * { ...data } // safe — own properties are copied as data
1356
- * structuredClone(data) // safe
1357
- * Object.assign({}, data) // NOT safe — [[Set]] on the {} target hits
1358
- * // Object.prototype's __proto__ setter: the key
1359
- * // vanishes and config data becomes the result's
1360
- * // prototype
1361
- * deepMerge({}, data) // NOT safe — a naive recursive merge reads
1362
- * // target['__proto__'], gets Object.prototype,
1363
- * // and writes to it: global pollution
1364
- * for (const k in data) … // prefer Object.entries / Object.keys
1365
- * ```
1366
- *
1367
- * Those two hazards come from the **destination** object's prototype, so no
1368
- * option here can disarm them — copy with spread or `structuredClone` instead.
1369
- *
1370
- * What `{ nullPrototype: true }` does give you is a result that inherits
1371
- * nothing: every object comes back with a `null` prototype, so reading
1372
- * `x.__proto__`, `x.constructor` or `x.toString` yields config data or
1373
- * `undefined` rather than something from `Object.prototype`, and code that
1374
- * merges *into* this object cannot climb out of it. Keys are all still
1375
- * present. The trade-off is the usual one for prototype-less objects: not
1376
- * `instanceof Object`, and no `hasOwnProperty` of their own.
1377
- *
1378
- * Numbers follow the JS number model, so an integer wider than 2^53 rounds
1379
- * here even when the config holds it exactly — read those with
1380
- * {@link Config.getString} instead.
1381
- */
1382
- toObject(opts) {
1383
- return hoconToJs(this.root, opts?.nullPrototype === true);
1384
- }
1385
- /**
1386
- * @internal Test-only: renders this resolved Config's value tree as canonical
1387
- * JSON (sorted keys, no whitespace). Used by Layer-2 fixture tests to compare
1388
- * against Lightbend ground truth. NOT part of the public API.
1389
- *
1390
- * Throws if the Config is unresolved (contains placeholders).
1391
- */
1392
- _renderJSONForTest() {
1393
- return renderHoconAsJSON(this.root);
1394
- }
1395
- lookupNode(path) {
1396
- const segments = splitConfigPath(path);
1397
- let current = this.root;
1398
- for (const seg of segments) {
1399
- if (current.kind !== "object") return void 0;
1400
- const next = current.fields.get(seg);
1401
- if (next === void 0) return void 0;
1402
- current = next;
1403
- }
1404
- return current;
1405
- }
1406
- /**
1407
- * _resObjRootSubtreeHasPlaceholders — walk _resObjRoot to the given path and
1408
- * return true if the subtree there contains any unresolved placeholder.
1409
- * Used by getConfig / getList (T2) to detect transitive unresolved placeholders
1410
- * in object / array subtrees that would otherwise appear to be "resolved" in the
1411
- * partial HoconValue root (because individual leaf fields are omitted rather than
1412
- * the whole subtree when their value is a direct placeholder scalar, but object
1413
- * sub-containers are retained in the partial root with the placeholder-keyed
1414
- * fields omitted from them — so the object appears "present but empty-ish").
1415
- */
1416
- _resObjRootSubtreeHasPlaceholders(path) {
1417
- const tree = this._resObjRoot;
1418
- if (!tree) return false;
1419
- const segments = splitConfigPath(path);
1420
- let cur = tree;
1421
- for (const seg of segments) {
1422
- const val = cur.fields.get(seg);
1423
- if (val === void 0) return false;
1424
- if (isResObj(val)) {
1425
- cur = val;
1426
- } else {
1427
- return valContainsPlaceholders(val);
1428
- }
1429
- }
1430
- return containsPlaceholders(cur);
1431
- }
1432
- requireScalar(path) {
1433
- const v = this.lookupNode(path);
1434
- if (v === void 0) {
1435
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1436
- throw new NotResolvedError(path);
1437
- }
1438
- throw new ConfigError(`path not found: ${path}`, path);
1439
- }
1440
- if (v.kind !== "scalar") throw new ConfigError(`expected scalar at ${path}, got ${v.kind}`, path);
1441
- return v;
1442
- }
1443
- };
1444
- function splitConfigPath(path) {
1445
- const segments = [];
1446
- let i = 0;
1447
- while (i < path.length) {
1448
- if (path[i] === '"') {
1449
- i++;
1450
- let segment = "";
1451
- let closed = false;
1452
- while (i < path.length) {
1453
- const ch = path[i];
1454
- if (ch === "\\" && i + 1 < path.length) {
1455
- const next = path[i + 1];
1456
- segment += next;
1457
- i += 2;
1458
- continue;
1459
- }
1460
- if (ch === '"') {
1461
- closed = true;
1462
- i++;
1463
- break;
1464
- }
1465
- segment += ch;
1466
- i++;
1467
- }
1468
- if (!closed) throw new ConfigError(`unterminated quoted path segment: ${path}`, path);
1469
- segments.push(segment);
1470
- if (i < path.length && path[i] === ".") i++;
1471
- } else {
1472
- const dot = path.indexOf(".", i);
1473
- if (dot === -1) {
1474
- segments.push(path.slice(i));
1475
- break;
1476
- }
1477
- segments.push(path.slice(i, dot));
1478
- i = dot + 1;
1479
- }
1480
- }
1481
- return segments;
1482
- }
1483
- function scalarToJs(raw, valueType) {
1484
- switch (valueType) {
1485
- case "null":
1486
- return null;
1487
- case "boolean":
1488
- return raw === "true";
1489
- case "number":
1490
- return Number(raw);
1491
- case "string":
1492
- return raw;
1493
- }
1494
- }
1495
- function hoconToJs(v, nullPrototype = false) {
1496
- switch (v.kind) {
1497
- case "scalar":
1498
- return scalarToJs(v.raw, v.valueType);
1499
- case "array":
1500
- return v.items.map((item) => hoconToJs(item, nullPrototype));
1501
- case "object": {
1502
- const entries = Array.from(v.fields, ([k, val]) => [k, hoconToJs(val, nullPrototype)]);
1503
- if (nullPrototype) {
1504
- const obj = /* @__PURE__ */ Object.create(null);
1505
- for (const [k, val] of entries) Object.defineProperty(obj, k, {
1506
- value: val,
1507
- writable: true,
1508
- enumerable: true,
1509
- configurable: true
1510
- });
1511
- return obj;
1512
- }
1513
- return Object.fromEntries(entries);
1514
- }
1515
- }
1516
- }
1517
- function resObjToKeyShape(tree) {
1518
- const fields = /* @__PURE__ */ new Map();
1519
- for (const [k, v] of tree.fields) {
1520
- if (isSubst(v) || isConcat(v)) {
1521
- fields.set(k, { kind: "scalar", raw: "", valueType: "null" });
1522
- } else if (isResObj(v)) {
1523
- fields.set(k, resObjToKeyShape(v));
1524
- } else {
1525
- fields.set(k, v);
1526
- }
1527
- }
1528
- return { kind: "object", fields };
1529
- }
1530
- function stripPlaceholderFields(v) {
1531
- const fields = /* @__PURE__ */ new Map();
1532
- let hadPlaceholders = false;
1533
- for (const [k, val] of v.fields) {
1534
- if (val._kind === "subst-placeholder" || val._kind === "concat-placeholder") {
1535
- hadPlaceholders = true;
1536
- } else if (val.kind === "object") {
1537
- const inner = stripPlaceholderFields(val);
1538
- if (inner.hadPlaceholders) hadPlaceholders = true;
1539
- fields.set(k, inner.stripped);
1540
- } else {
1541
- fields.set(k, val);
1542
- }
1543
- }
1544
- return { stripped: { kind: "object", fields }, hadPlaceholders };
1545
- }
1546
- function filterByReceiverShape(resolved, receiverShape) {
1547
- const fields = /* @__PURE__ */ new Map();
1548
- for (const [k, rv] of resolved.fields) {
1549
- if (!receiverShape.fields.has(k)) continue;
1550
- const receiverVal = receiverShape.fields.get(k);
1551
- if (rv.kind === "object" && receiverVal.kind === "object") {
1552
- fields.set(k, filterByReceiverShape(rv, receiverVal));
1553
- } else {
1554
- fields.set(k, rv);
1555
- }
1556
- }
1557
- return { kind: "object", fields };
1558
- }
1559
- function renderHoconAsJSON(v) {
1560
- switch (v.kind) {
1561
- case "scalar": {
1562
- switch (v.valueType) {
1563
- case "null":
1564
- return "null";
1565
- case "boolean":
1566
- return v.raw;
1567
- case "number": {
1568
- const norm = normalizeLeadingZeroNumber(v.raw);
1569
- return JSON_NUMBER_RE.test(norm) ? norm : JSON.stringify(v.raw);
1570
- }
1571
- case "string":
1572
- return JSON.stringify(v.raw);
1573
- }
1574
- break;
1575
- }
1576
- case "array": {
1577
- const items = v.items.map(renderHoconAsJSON);
1578
- return `[${items.join(",")}]`;
1579
- }
1580
- case "object": {
1581
- const keys = [...v.fields.keys()].sort();
1582
- const pairs = keys.map((k) => {
1583
- const val = v.fields.get(k);
1584
- return `${JSON.stringify(k)}:${renderHoconAsJSON(val)}`;
1585
- });
1586
- return `{${pairs.join(",")}}`;
1587
- }
1588
- }
1589
- throw new Error(`renderHoconAsJSON: unsupported value kind (unresolved placeholder?)`);
1590
- }
1591
- var JSON_NUMBER_RE = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
1592
- function normalizeLeadingZeroNumber(raw) {
1593
- return raw.replace(/^([+-]?)0+(\d)/, "$1$2");
1594
- }
1595
-
1596
- // src/value-factory.ts
1597
- function fromMap(values, originDescription) {
1598
- const fields = guardStackDepth(
1599
- () => coerceObject(values, ""),
1600
- (msg) => depthError(`fromMap: ${msg}`)
1601
- );
1602
- const root = { kind: "object", fields };
1603
- return Config._fromResolvedValue(root, { originDescription });
1604
- }
1605
- var INT64_MAX = 9223372036854775807n;
1606
- var INT64_MIN = -9223372036854775808n;
1607
- function coerceObject(obj, atPath) {
1608
- const fields = /* @__PURE__ */ new Map();
1609
- for (const [k, v] of Object.entries(obj)) {
1610
- const childPath = atPath ? `${atPath}.${k}` : k;
1611
- fields.set(k, coerceValue(v, childPath));
1612
- }
1613
- return fields;
1614
- }
1615
- function coerceValue(v, atPath) {
1616
- if (v === null) {
1617
- return { kind: "scalar", raw: "null", valueType: "null" };
1618
- }
1619
- if (v === void 0) {
1620
- throw new ConfigError(
1621
- `fromMap: undefined is not a valid HOCON value at path "${atPath}"`,
1622
- atPath
1623
- );
1624
- }
1625
- switch (typeof v) {
1626
- case "string":
1627
- return { kind: "scalar", raw: v, valueType: "string" };
1628
- case "number": {
1629
- if (Number.isNaN(v) || !Number.isFinite(v)) {
1630
- throw new ConfigError(
1631
- `fromMap: ${v} is not representable in HOCON (NaN/Infinity not allowed) at path "${atPath}"`,
1632
- atPath
1633
- );
1634
- }
1635
- return { kind: "scalar", raw: Object.is(v, -0) ? "-0" : String(v), valueType: "number" };
1636
- }
1637
- case "boolean":
1638
- return { kind: "scalar", raw: v ? "true" : "false", valueType: "boolean" };
1639
- case "bigint": {
1640
- if (v > INT64_MAX || v < INT64_MIN) {
1641
- throw new ConfigError(
1642
- `fromMap: integer ${v} is out of int64 range (HOCON integers are int64; spec F0.5) at path "${atPath}"`,
1643
- atPath
1644
- );
1645
- }
1646
- return { kind: "scalar", raw: String(v), valueType: "number" };
1647
- }
1648
- case "object": {
1649
- if (Array.isArray(v)) {
1650
- const items = v.map((item, i) => coerceValue(item, `${atPath}[${i}]`));
1651
- return { kind: "array", items };
1652
- }
1653
- const fields = coerceObject(v, atPath);
1654
- return { kind: "object", fields };
1655
- }
1656
- default:
1657
- throw new ConfigError(
1658
- `fromMap: unsupported value type "${typeof v}" at path "${atPath}"`,
1659
- atPath
1660
- );
1661
- }
1662
- }
11
+ var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
1663
12
 
1664
13
  // src/adapters/env.ts
1665
14
  var SEPARATOR = "__";
1666
15
  function loadEnv(opts = {}) {
1667
- const prefix = opts.prefix ?? "";
16
+ const prefix = _nullishCoalesce(opts.prefix, () => ( ""));
1668
17
  if (prefix === "") {
1669
- throw new ConfigError(
18
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
1670
19
  "loadEnv: a prefix is required when mounting the environment (spec F1.1)",
1671
20
  ""
1672
21
  );
1673
22
  }
1674
- const source = opts.env ?? globalThis.process?.env ?? {};
23
+ const source = _nullishCoalesce(_nullishCoalesce(opts.env, () => ( _optionalChain([globalThis, 'access', _ => _.process, 'optionalAccess', _2 => _2.env]))), () => ( {}));
1675
24
  const names = Object.keys(source).sort();
1676
25
  const seen = /* @__PURE__ */ new Map();
1677
26
  const pairs = [];
@@ -1680,44 +29,44 @@ function loadEnv(opts = {}) {
1680
29
  const value = source[name];
1681
30
  if (value === void 0) continue;
1682
31
  const path = toPath(name.slice(prefix.length));
1683
- const key = pathKey(path);
32
+ const key = _chunkRO4D6BH7cjs.pathKey.call(void 0, path);
1684
33
  const prev = seen.get(key);
1685
34
  if (prev !== void 0) {
1686
- throw new ConfigError(`loadEnv: ${prev} and ${name} both map to "${path.join(".")}"`, path.join("."));
35
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`loadEnv: ${prev} and ${name} both map to "${path.join(".")}"`, path.join("."));
1687
36
  }
1688
37
  seen.set(key, name);
1689
38
  pairs.push([path, value]);
1690
39
  }
1691
- return fromMap(nestPairs(pairs), opts.originDescription ?? "environment variables");
40
+ return _chunkGBNQADHTcjs.fromMap.call(void 0, _chunkRO4D6BH7cjs.nestPairs.call(void 0, pairs), _nullishCoalesce(opts.originDescription, () => ( "environment variables")));
1692
41
  }
1693
42
  function parseDotEnv(input, opts = {}) {
1694
- const origin = opts.originDescription ?? ".env";
1695
- const prefix = opts.prefix ?? "";
43
+ const origin = _nullishCoalesce(opts.originDescription, () => ( ".env"));
44
+ const prefix = _nullishCoalesce(opts.prefix, () => ( ""));
1696
45
  const pairs = [];
1697
- const lines = stripBom(input).replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
46
+ const lines = _chunkRO4D6BH7cjs.stripBom.call(void 0, input).replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
1698
47
  for (let i = 0; i < lines.length; i++) {
1699
- const raw = (lines[i] ?? "").trim();
48
+ const raw = (_nullishCoalesce(lines[i], () => ( ""))).trim();
1700
49
  if (raw === "" || raw.startsWith("#")) continue;
1701
50
  const line = stripExport(raw);
1702
51
  const eq = line.indexOf("=");
1703
- if (eq === -1) throw new ConfigError(`${origin}:${i + 1}: expected NAME=value`, "");
52
+ if (eq === -1) throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`${origin}:${i + 1}: expected NAME=value`, "");
1704
53
  const name = line.slice(0, eq).trim();
1705
- if (name === "") throw new ConfigError(`${origin}:${i + 1}: empty variable name`, "");
54
+ if (name === "") throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`${origin}:${i + 1}: empty variable name`, "");
1706
55
  if (!name.startsWith(prefix)) continue;
1707
56
  checkName(name, origin, i + 1);
1708
57
  const value = dotEnvValue(line.slice(eq + 1).replace(/^[ \t]+/, ""), origin, i + 1, name);
1709
58
  pairs.push([toPath(name.slice(prefix.length)), value]);
1710
59
  }
1711
- return fromMap(nestPairs(pairs), origin);
60
+ return _chunkGBNQADHTcjs.fromMap.call(void 0, _chunkRO4D6BH7cjs.nestPairs.call(void 0, pairs), origin);
1712
61
  }
1713
62
  function toPath(name) {
1714
63
  const segs = name.split(SEPARATOR).map(asciiLower);
1715
64
  if (segs.some((s) => s === "")) {
1716
- throw new ConfigError(`env: "${name}" produces an empty path segment`, name);
65
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`env: "${name}" produces an empty path segment`, name);
1717
66
  }
1718
- if (tooDeep(segs.length)) {
1719
- throw new ConfigError(
1720
- `env: "${name}" maps to a path ${segs.length} segments deep, over the limit of ${MAX_PATH_SEGMENTS}`,
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}`,
1721
70
  name
1722
71
  );
1723
72
  }
@@ -1728,7 +77,7 @@ function asciiLower(s) {
1728
77
  }
1729
78
  function dotEnvValue(v, origin, line, name) {
1730
79
  const fail = (msg) => {
1731
- throw new ConfigError(`${origin}:${line}: ${name}: ${msg}`, name);
80
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(`${origin}:${line}: ${name}: ${msg}`, name);
1732
81
  };
1733
82
  if (v.startsWith("'")) {
1734
83
  const end = v.indexOf("'", 1);
@@ -1774,14 +123,13 @@ function checkName(name, origin, line) {
1774
123
  const bad = /\p{White_Space}|#/u.exec(name);
1775
124
  if (bad) {
1776
125
  const what = bad[0] === "#" ? "'#'" : "whitespace";
1777
- throw new ConfigError(
126
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
1778
127
  `${origin}:${line}: variable name "${name}" contains ${what}; the line is not NAME=value (spec F1.7)`,
1779
128
  name
1780
129
  );
1781
130
  }
1782
131
  }
1783
- // Annotate the CommonJS export names for ESM import in node:
1784
- 0 && (module.exports = {
1785
- loadEnv,
1786
- parseDotEnv
1787
- });
132
+
133
+
134
+
135
+ exports.loadEnv = loadEnv; exports.parseDotEnv = parseDotEnv;