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