@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,1640 +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);
29
-
30
- // src/adapters/jsonc.ts
31
- var jsonc_exports = {};
32
- __export(jsonc_exports, {
33
- parseJsonc: () => parseJsonc,
34
- stripComments: () => stripComments
35
- });
36
- module.exports = __toCommonJS(jsonc_exports);
37
-
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
-
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
-
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
-
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
-
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
-
555
- // src/internal/strip-bom.ts
556
- function stripBom(input) {
557
- return input.charCodeAt(0) === 65279 ? input.slice(1) : input;
558
- }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
559
2
 
560
- // src/internal/depth.ts
561
- function guardStackDepth(fn, wrap) {
562
- try {
563
- return fn();
564
- } catch (e) {
565
- if (!isStackOverflow(e)) throw e;
566
- throw wrap(STACK_MESSAGE);
567
- }
568
- }
569
- var STACK_MESSAGE = "input is nested too deeply for this engine's stack, or contains a cycle (flatten the document, or break the cycle)";
570
- function isStackOverflow(e) {
571
- if (!(e instanceof RangeError)) return false;
572
- const m = e.message.toLowerCase();
573
- return m.includes("call stack") || // V8: "Maximum call stack size exceeded"
574
- m.includes("recursion") || // SpiderMonkey: "too much recursion"
575
- m.includes("stack overflow");
576
- }
577
- function depthError(message) {
578
- return new ConfigError(message, "");
579
- }
3
+ var _chunkGBNQADHTcjs = require('../chunk-GBNQADHT.cjs');
580
4
 
581
- // src/value/numeric-array.ts
582
- function numericObjectToArray(value) {
583
- if (value.kind !== "object") return null;
584
- if (value.fields.size === 0) return null;
585
- const canonicalInt = /^(0|[1-9][0-9]*)$/;
586
- const eligible = [];
587
- for (const [key, val] of value.fields) {
588
- if (!canonicalInt.test(key)) continue;
589
- const n = Number(key);
590
- if (!Number.isInteger(n) || n > 2147483647) continue;
591
- eligible.push({ n, v: val });
592
- }
593
- if (eligible.length === 0) return null;
594
- eligible.sort((a, b) => a.n - b.n);
595
- return eligible.map((e) => e.v);
596
- }
597
5
 
598
- // src/internal/resolver/substitution-resolver.ts
599
- var SubstitutionResolver = class {
600
- constructor(root, opts) {
601
- this.root = root;
602
- this.opts = opts;
603
- this.resolving = /* @__PURE__ */ new Set();
604
- this.cache = /* @__PURE__ */ new Map();
605
- // Tracks ConcatPlaceholder nodes currently being iterated by resolveConcat.
606
- // Used by isSelfRef detection: fires only when found === a concat currently
607
- // mid-iteration (i.e. we are inside found's own resolution), preventing the
608
- // "foofoo" double-count without misfiring when an external field looks up the
609
- // same concat via a substitution (multi-reviewer convergence fix).
610
- //
611
- // Spec deviation: the S13a.13 spec ★1 decision #1 specified path-equality
612
- // preservation for self-ref detection. Round-2 multi-agent-review surfaced a
613
- // false-positive on external lookups (`a = ${?a}foo; b = ${a}`), so the
614
- // criterion was tightened to node-membership-in-iterating-set — strictly
615
- // narrower than path-equality. Spec amendment deferred to a follow-up
616
- // xx.hocon PR (see Phase 6 #3f close-out notes).
617
- this.resolvingConcats = /* @__PURE__ */ new WeakSet();
618
- // Path stack tracking the full dotted path of the field currently being
619
- // assigned in `resolveResObj`. Leaf keys are pushed on entry to each
620
- // `(key, val)` iteration and popped on exit, so nested objects build up
621
- // the full path (e.g. `["o", "history"]` while resolving `o.history`).
622
- //
623
- // Used to tighten self-ref detection at the L192 found-lookup site:
624
- // a substitution `${X}` whose looked-up value contains a Subst pointing
625
- // at `X` is only a true self-reference when the field currently being
626
- // assigned is `X` (or a descendant of `X`). Without this guard, an
627
- // external lookup like `b = ${o}` (where o has a self-referential
628
- // field) would mis-fire and short-circuit to o's prior, returning the
629
- // wrong value for b. The is_owner gate (rfp prefix-matches s.segments)
630
- // narrows the check to the owner case only.
631
- //
632
- // Cross-impl with rs.hocon v1.5.1's resolving_field_path (same purpose,
633
- // same prefix-match semantics).
634
- this.resolvingFieldPath = [];
635
- }
636
- /** Returns a prefix for error messages, including origin info when set. */
637
- originPrefix() {
638
- return this.opts.originDescription ? `${this.opts.originDescription}: ` : "";
639
- }
640
- resolve() {
641
- return this.resolveResObj(this.root);
642
- }
643
- resolveResObj(obj) {
644
- const result = /* @__PURE__ */ new Map();
645
- for (const [key, val] of obj.fields) {
646
- this.resolvingFieldPath.push(key);
647
- const fullCacheKey = stringSegmentsToKey(this.resolvingFieldPath);
648
- this.cache.delete(fullCacheKey);
649
- let resolved;
650
- try {
651
- resolved = this.resolveVal(val, obj);
652
- } finally {
653
- this.resolvingFieldPath.pop();
654
- }
655
- if (resolved !== void 0) {
656
- if (resolved.kind === "object") {
657
- const prior = obj.priorValues.get(key);
658
- if (prior !== void 0) {
659
- const priorResolved = this.resolveVal(prior, obj);
660
- if (priorResolved !== void 0 && priorResolved.kind === "object") {
661
- const finalValue = deepMergeHoconValues(
662
- priorResolved,
663
- resolved
664
- );
665
- result.set(key, finalValue);
666
- this.cache.set(fullCacheKey, finalValue);
667
- this.cacheDescendants(fullCacheKey, finalValue);
668
- continue;
669
- }
670
- }
671
- }
672
- result.set(key, resolved);
673
- this.cache.set(fullCacheKey, resolved);
674
- this.cacheDescendants(fullCacheKey, resolved);
675
- } else {
676
- const prior = obj.priorValues.get(key);
677
- if (prior !== void 0) {
678
- const priorResolved = this.resolveVal(prior, obj);
679
- if (priorResolved !== void 0) {
680
- result.set(key, priorResolved);
681
- this.cache.set(fullCacheKey, priorResolved);
682
- this.cacheDescendants(fullCacheKey, priorResolved);
683
- }
684
- }
685
- }
686
- }
687
- return { kind: "object", fields: result };
688
- }
689
- cacheDescendants(prefix, value) {
690
- if (value.kind !== "object") return;
691
- for (const [key, child] of value.fields) {
692
- const childKey = `${prefix}.${stringSegmentsToKey([key])}`;
693
- this.cache.set(childKey, child);
694
- this.cacheDescendants(childKey, child);
695
- }
696
- }
697
- resolveVal(v, scope) {
698
- if (isSubst(v)) return this.resolveSubst(v, scope);
699
- if (isConcat(v)) {
700
- this.resolvingConcats.add(v);
701
- try {
702
- const concatResult = this.resolveConcat(v.nodes, scope, v.line, v.col);
703
- return concatResult;
704
- } finally {
705
- this.resolvingConcats.delete(v);
706
- }
707
- }
708
- if (isResObj(v)) return this.resolveResObj(v);
709
- const hv = v;
710
- if (hv.kind === "array") {
711
- return {
712
- kind: "array",
713
- items: hv.items.map(
714
- (item) => this.resolveVal(item, scope) ?? { kind: "scalar", raw: "null", valueType: "null" }
715
- )
716
- };
717
- }
718
- return hv;
719
- }
720
- resolveSubst(s, scope) {
721
- if (s.knownAbsent) return void 0;
722
- const key = s.listSuffix ? `${segmentsToKey(s.segments)}[]` : segmentsToKey(s.segments);
723
- if (this.cache.has(key)) return this.cache.get(key);
724
- if (this.resolving.has(key)) {
725
- let prior;
726
- if (s.segments.length > 1) {
727
- const leafSeg = s.segments[s.segments.length - 1]?.text ?? "";
728
- const parentScope = lookupResObj(
729
- this.root,
730
- s.segments.slice(0, s.segments.length - 1)
731
- );
732
- prior = parentScope?.priorValues.get(leafSeg);
733
- } else {
734
- const rootSeg = s.segments[0]?.text ?? "";
735
- prior = scope.priorValues.get(rootSeg) ?? this.root.priorValues.get(rootSeg);
736
- }
737
- if (prior !== void 0) {
738
- const saved = this.resolving;
739
- this.resolving = new Set(saved);
740
- try {
741
- return this.resolveVal(prior, scope);
742
- } finally {
743
- this.resolving = saved;
744
- }
745
- }
746
- if (s.optional) return void 0;
747
- throw new ResolveError(
748
- this.originPrefix() + `circular substitution: ${key}`,
749
- key,
750
- s.line,
751
- s.col
752
- );
753
- }
754
- this.resolving.add(key);
755
- try {
756
- const found = lookupPath(this.root, s.segments);
757
- if (found !== void 0) {
758
- const rfp = this.resolvingFieldPath;
759
- const isOwner = rfp.length >= s.segments.length && s.segments.every((seg, i) => rfp[i] === seg.text);
760
- const isSelfRef = isConcat(found) && this.resolvingConcats.has(found) || isOwner && containsSubstByPath(found, s.segments);
761
- if (isSelfRef) {
762
- let prior;
763
- if (s.segments.length > 1) {
764
- const leafSeg = s.segments[s.segments.length - 1]?.text ?? "";
765
- const parentScope = lookupResObj(
766
- this.root,
767
- s.segments.slice(0, s.segments.length - 1)
768
- );
769
- prior = parentScope?.priorValues.get(leafSeg);
770
- } else {
771
- const rootSeg = s.segments[0]?.text ?? "";
772
- prior = scope.priorValues.get(rootSeg) ?? this.root.priorValues.get(rootSeg);
773
- }
774
- if (prior !== void 0) {
775
- const result2 = this.resolveVal(prior, scope);
776
- if (result2 !== void 0) this.cache.set(key, result2);
777
- return result2;
778
- }
779
- if (s.optional) return void 0;
780
- throw new ResolveError(
781
- `${this.originPrefix()}could not resolve substitution: \${${key}}`,
782
- key,
783
- s.line,
784
- s.col
785
- );
786
- }
787
- let result = this.resolveVal(found, scope);
788
- const effectiveLen = s.segments.length - s.prefixLen;
789
- if (effectiveLen === 1 && result !== void 0 && result.kind === "object") {
790
- const leafSeg = s.segments[s.segments.length - 1]?.text ?? "";
791
- let prior;
792
- if (s.prefixLen > 0) {
793
- const parentScope = lookupResObj(
794
- this.root,
795
- s.segments.slice(0, s.segments.length - 1)
796
- );
797
- prior = parentScope?.priorValues.get(leafSeg);
798
- } else {
799
- prior = scope.priorValues.get(leafSeg) ?? this.root.priorValues.get(leafSeg);
800
- }
801
- if (prior !== void 0) {
802
- const priorResolved = this.resolveVal(prior, scope);
803
- if (priorResolved !== void 0 && priorResolved.kind === "object") {
804
- result = deepMergeHoconValues(
805
- priorResolved,
806
- result
807
- );
808
- }
809
- }
810
- }
811
- if (result !== void 0) this.cache.set(key, result);
812
- return result;
813
- }
814
- if (s.prefixLen > 0 && s.segments.length > s.prefixLen) {
815
- const originalSegments = s.segments.slice(s.prefixLen);
816
- const fallbackFound = lookupPath(this.root, originalSegments);
817
- if (fallbackFound !== void 0) {
818
- let result = this.resolveVal(fallbackFound, scope);
819
- if (originalSegments.length === 1 && result !== void 0 && result.kind === "object") {
820
- const rootSeg = originalSegments[0]?.text ?? "";
821
- const prior = this.root.priorValues.get(rootSeg);
822
- if (prior !== void 0) {
823
- const priorResolved = this.resolveVal(prior, scope);
824
- if (priorResolved !== void 0 && priorResolved.kind === "object") {
825
- result = deepMergeHoconValues(
826
- priorResolved,
827
- result
828
- );
829
- }
830
- }
831
- }
832
- if (result !== void 0) this.cache.set(key, result);
833
- return result;
834
- }
835
- }
836
- if (s.listSuffix && this.opts.useSystemEnvironment !== false) {
837
- const result = this.resolveEnvList(s);
838
- if (result !== void 0) {
839
- this.cache.set(key, result);
840
- return result;
841
- }
842
- if (s.optional) return void 0;
843
- const envBase = s.segments.map((seg) => seg.text).join(".");
844
- throw new ResolveError(
845
- `${this.originPrefix()}could not resolve substitution: \${${key}} (no environment variables ${envBase}_0, ${envBase}_1, \u2026 set)`,
846
- key,
847
- s.line,
848
- s.col
849
- );
850
- } else if (s.listSuffix) {
851
- if (s.optional) return void 0;
852
- if (this.opts.allowUnresolved) return s;
853
- throw new ResolveError(
854
- `${this.originPrefix()}could not resolve substitution: \${${key}}`,
855
- key,
856
- s.line,
857
- s.col
858
- );
859
- }
860
- if (this.opts.useSystemEnvironment !== false) {
861
- const envKey = s.segments.map((seg) => seg.text).join(".");
862
- const envVal = this.opts.env[envKey] ?? (s.prefixLen > 0 ? this.opts.env[s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".")] : void 0);
863
- if (envVal !== void 0) {
864
- const result = { kind: "scalar", raw: envVal, valueType: "string" };
865
- this.cache.set(key, result);
866
- return result;
867
- }
868
- }
869
- if (s.optional) return void 0;
870
- if (this.opts.allowUnresolved) {
871
- return s;
872
- }
873
- throw new ResolveError(
874
- `${this.originPrefix()}could not resolve substitution: \${${key}}`,
875
- key,
876
- s.line,
877
- s.col
878
- );
879
- } finally {
880
- this.resolving.delete(key);
881
- }
882
- }
883
- /**
884
- * S13c: scan environment for NAME_0, NAME_1, … and return an Array<Scalar(String)>.
885
- *
886
- * Candidate bases follow the same fully-qualified→bare order used by the scalar
887
- * env fallback. The first base whose _0 key is present wins entirely — no
888
- * cross-base merging (spec §Relativized fallback precedence rules).
889
- *
890
- * Returns the HoconValue Array if any candidate base has _0, or undefined if
891
- * none do (caller applies optional/required handling).
892
- */
893
- resolveEnvList(s) {
894
- const bases = this.candidateBases(s);
895
- for (const base of bases) {
896
- const key0 = base + "_0";
897
- if (!(key0 in this.opts.env)) continue;
898
- const items = [];
899
- for (let i = 0; ; i++) {
900
- const k = base + "_" + i;
901
- if (!(k in this.opts.env)) break;
902
- items.push({ kind: "scalar", raw: this.opts.env[k], valueType: "string" });
903
- }
904
- return { kind: "array", items };
905
- }
906
- return void 0;
907
- }
908
- /**
909
- * Return the candidate base names for env-var-list lookup, in precedence order.
910
- * Mirrors the fully-qualified→bare fallback used by the scalar env path.
911
- */
912
- candidateBases(s) {
913
- const full = s.segments.map((seg) => seg.text).join(".");
914
- if (s.prefixLen === 0) return [full];
915
- const bare = s.segments.slice(s.prefixLen).map((seg) => seg.text).join(".");
916
- return [full, bare];
917
- }
918
- resolveConcat(nodes, scope, line = 0, col = 0) {
919
- const rawResolved = nodes.map((n) => this.resolveVal(n, scope));
920
- if (this.opts.allowUnresolved) {
921
- for (const v of rawResolved) {
922
- if (v !== void 0 && isSubst(v)) {
923
- return v;
924
- }
925
- }
926
- }
927
- const resolved = rawResolved.filter((v) => v !== void 0);
928
- if (resolved.length === 0) return void 0;
929
- if (resolved.length === 1) return resolved[0];
930
- const nonSep = resolved.filter((v) => !separatorValues.has(v));
931
- if (nonSep.length === 0) {
932
- const str = resolved.map((v) => v.kind === "scalar" ? v.raw : JSON.stringify(v)).join("");
933
- return { kind: "scalar", raw: str, valueType: "string" };
934
- }
935
- const joinPair = (left, right) => {
936
- if (left.kind === "object" && right.kind === "object") {
937
- return deepMergeHoconValues(left, right);
938
- }
939
- if (left.kind === "array" && right.kind === "object") {
940
- const converted = numericObjectToArray(right);
941
- if (converted !== null) {
942
- return { kind: "array", items: [...left.items, ...converted] };
943
- }
944
- throw new ResolveError(
945
- "cannot concatenate array with object: value concatenation requires same-kind operands (S10.4)",
946
- "",
947
- line,
948
- col
949
- );
950
- }
951
- if (left.kind === "object" && right.kind === "array") {
952
- const converted = numericObjectToArray(left);
953
- if (converted !== null) {
954
- return { kind: "array", items: [...converted, ...right.items] };
955
- }
956
- throw new ResolveError(
957
- "cannot concatenate object with array: value concatenation requires same-kind operands (S10.4)",
958
- "",
959
- line,
960
- col
961
- );
962
- }
963
- if (left.kind === "array" && right.kind === "array") {
964
- return { kind: "array", items: [...left.items, ...right.items] };
965
- }
966
- if (left.kind === "array" || right.kind === "array") {
967
- throw new ResolveError(
968
- `cannot concatenate ${left.kind} with ${right.kind}: arrays and objects may not appear in string value concatenation (S10.13)`,
969
- "",
970
- line,
971
- col
972
- );
973
- }
974
- if (left.kind === "object" || right.kind === "object") {
975
- throw new ResolveError(
976
- `cannot concatenate ${left.kind} with ${right.kind}: arrays and objects may not appear in string value concatenation (S10.13)`,
977
- "",
978
- line,
979
- col
980
- );
981
- }
982
- return { kind: "scalar", raw: left.raw + right.raw, valueType: "string" };
983
- };
984
- const [head, ...tail] = nonSep;
985
- const folded = tail.reduce(joinPair, head);
986
- if (folded.kind === "scalar") {
987
- const str = resolved.map((v) => v.kind === "scalar" ? v.raw : JSON.stringify(v)).join("");
988
- return { kind: "scalar", raw: str, valueType: "string" };
989
- }
990
- return folded;
991
- }
992
- };
993
6
 
994
- // src/internal/resolver/resolver.ts
995
- function resolveTree(tree, opts) {
996
- return new SubstitutionResolver(tree, opts).resolve();
997
- }
998
- function containsPlaceholders(tree) {
999
- for (const val of tree.fields.values()) {
1000
- if (valContainsPlaceholders(val)) return true;
1001
- }
1002
- return false;
1003
- }
1004
- function valContainsPlaceholders(v) {
1005
- const rv = v;
1006
- if (isSubst(rv) || isConcat(rv)) return true;
1007
- if (isResObj(rv)) return containsPlaceholders(rv);
1008
- const hv = v;
1009
- if (hv?.kind === "array") {
1010
- return hv.items.some((item) => valContainsPlaceholders(item));
1011
- }
1012
- return false;
1013
- }
1014
- function buildPartialHoconFromResObj(tree) {
1015
- const fields = /* @__PURE__ */ new Map();
1016
- for (const [k, v] of tree.fields) {
1017
- if (!isSubst(v) && !isConcat(v)) {
1018
- if (isResObj(v)) {
1019
- fields.set(k, buildPartialHoconFromResObj(v));
1020
- } else {
1021
- if (!valContainsPlaceholders(v)) {
1022
- fields.set(k, v);
1023
- }
1024
- }
1025
- }
1026
- }
1027
- return { kind: "object", fields };
1028
- }
1029
- function hoconValueToResObj2(value) {
1030
- const obj = makeResObj();
1031
- for (const [k, v] of value.fields) {
1032
- if (v.kind === "object") {
1033
- obj.fields.set(k, hoconValueToResObj2(v));
1034
- } else {
1035
- obj.fields.set(k, v);
1036
- }
1037
- }
1038
- return obj;
1039
- }
1040
7
 
1041
- // src/config.ts
1042
- var Config = class _Config {
1043
- constructor(root, opts) {
1044
- this.root = root;
1045
- this._resolved = opts?.resolved ?? true;
1046
- this._parseBaseDir = opts?.parseBaseDir;
1047
- this._originDescription = opts?.originDescription;
1048
- this._resObjRoot = opts?.resObjRoot;
1049
- this._resolveOpts = opts?.resolveOpts;
1050
- }
1051
- /** Returns true when the Config's value tree contains no unresolved
1052
- * substitution placeholders. Whole-config granularity (E12 decision 11). */
1053
- isResolved() {
1054
- return this._resolved;
1055
- }
1056
- /** @internal Test-only: construct a resolved Config from a HoconValue. */
1057
- static _fromResolvedValue(root, opts) {
1058
- return new _Config(root, { resolved: true, originDescription: opts?.originDescription });
1059
- }
1060
- /** @internal Construct an unresolved Config carrying a ResObj tree.
1061
- * Used by parseStringWithOptions (deferred path) in T6. */
1062
- static _fromUnresolvedResObj(tree, opts) {
1063
- const partialRoot = buildPartialHoconFromResObj(tree);
1064
- return new _Config(partialRoot, {
1065
- resolved: opts.resolved,
1066
- parseBaseDir: opts.parseBaseDir,
1067
- originDescription: opts.originDescription,
1068
- resObjRoot: tree,
1069
- resolveOpts: opts.resolveOpts
1070
- });
1071
- }
1072
- get(path) {
1073
- const v = this.lookupNode(path);
1074
- if (v === void 0) return void 0;
1075
- return hoconToJs(v);
1076
- }
1077
- /**
1078
- * Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
1079
- * {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
1080
- * `get` (which decodes to a plain JS value), this exposes the value tree for
1081
- * structural introspection via the `value.ts` accessors (`asString`, `asObject`,
1082
- * `isScalar`, …).
1083
- *
1084
- * `getValue('')` returns the root object node.
1085
- *
1086
- * Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
1087
- * the `HoconValue` union has no placeholder variant, so an unresolved value
1088
- * cannot be represented. This matches `getConfig` / `getList`.
1089
- */
1090
- getValue(path) {
1091
- const v = this.lookupNode(path);
1092
- if (v === void 0) {
1093
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1094
- throw new NotResolvedError(path);
1095
- }
1096
- return void 0;
1097
- }
1098
- if (v.kind !== "scalar" && !this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1099
- throw new NotResolvedError(path);
1100
- }
1101
- return v;
1102
- }
1103
- getString(path) {
1104
- const v = this.requireScalar(path);
1105
- if (v.valueType === "null") {
1106
- throw new ConfigError(`expected string at ${path}, got ${v.valueType}`, path);
1107
- }
1108
- return v.raw;
1109
- }
1110
- getNumber(path) {
1111
- const v = this.requireScalar(path);
1112
- const coerced = coerceNumber(v.raw);
1113
- if (coerced !== void 0) return coerced;
1114
- throw new ConfigError(`expected number at ${path}, got ${v.valueType}`, path);
1115
- }
1116
- getBoolean(path) {
1117
- const v = this.requireScalar(path);
1118
- const coerced = coerceBoolean(v.raw);
1119
- if (coerced !== void 0) return coerced;
1120
- throw new ConfigError(`expected boolean at ${path}, got ${v.valueType}`, path);
1121
- }
1122
- getDuration(path, unit) {
1123
- const v = this.requireScalar(path);
1124
- if (v.valueType !== "string" && v.valueType !== "number") {
1125
- throw new ConfigError(`expected duration at ${path}, got ${v.valueType}`, path);
1126
- }
1127
- const result = parseDuration(v.raw, unit);
1128
- if (Number.isNaN(result)) throw new ConfigError(`invalid duration at ${path}: ${JSON.stringify(v.raw)}`, path);
1129
- return result;
1130
- }
1131
- getBytes(path, unit) {
1132
- const v = this.requireScalar(path);
1133
- if (v.valueType !== "string" && v.valueType !== "number") {
1134
- throw new ConfigError(`expected byte size at ${path}, got ${v.valueType}`, path);
1135
- }
1136
- const result = parseBytes(v.raw, unit);
1137
- if (Number.isNaN(result)) throw new ConfigError(`invalid byte size at ${path}: ${JSON.stringify(v.raw)}`, path);
1138
- if (result < 0) throw new ConfigError(`byte size must be non-negative at ${path}: ${JSON.stringify(v.raw)}`, path);
1139
- return result;
1140
- }
1141
- getConfig(path) {
1142
- const v = this.lookupNode(path);
1143
- if (v === void 0) {
1144
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1145
- throw new NotResolvedError(path);
1146
- }
1147
- throw new ConfigError(`path not found: ${path}`, path);
1148
- }
1149
- if (v.kind !== "object") throw new ConfigError(`expected object at ${path}`, path);
1150
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1151
- throw new NotResolvedError(path);
1152
- }
1153
- return new _Config(v, { resolved: this._resolved });
1154
- }
1155
- getList(path) {
1156
- const v = this.lookupNode(path);
1157
- if (v === void 0) {
1158
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1159
- throw new NotResolvedError(path);
1160
- }
1161
- throw new ConfigError(`path not found: ${path}`, path);
1162
- }
1163
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1164
- throw new NotResolvedError(path);
1165
- }
1166
- if (v.kind === "object") {
1167
- const converted = numericObjectToArray(v);
1168
- if (converted !== null) return converted.map((item) => hoconToJs(item));
1169
- }
1170
- if (v.kind !== "array") throw new ConfigError(`expected array at ${path}`, path);
1171
- return v.items.map((item) => hoconToJs(item));
1172
- }
1173
- has(path) {
1174
- return this.lookupNode(path) !== void 0;
1175
- }
1176
- keys() {
1177
- return [...this.root.fields.keys()];
1178
- }
1179
- withFallback(fallback) {
1180
- if (fallback == null) return this;
1181
- const selfTree = this._resObjRoot ?? hoconValueToResObj2(this.root);
1182
- const fbTree = fallback._resObjRoot ?? hoconValueToResObj2(fallback.root);
1183
- const merged = mergeUnresolved(selfTree, fbTree);
1184
- const hasPlaceholders = containsPlaceholders(merged);
1185
- const partialRoot = buildPartialHoconFromResObj(merged);
1186
- return new _Config(partialRoot, {
1187
- resolved: !hasPlaceholders,
1188
- parseBaseDir: this._parseBaseDir,
1189
- originDescription: this._originDescription,
1190
- resObjRoot: merged,
1191
- resolveOpts: this._resolveOpts ?? fallback._resolveOpts
1192
- });
1193
- }
1194
- /**
1195
- * Runs substitution resolution (phase 2) on the stored unresolved tree.
1196
- * Idempotent: calling resolve() on an already-resolved Config returns an
1197
- * equivalent resolved Config.
1198
- *
1199
- * opts.allowUnresolved (default false) — when true, leaves unresolved
1200
- * non-optional placeholders in place rather than throwing.
1201
- * opts.useSystemEnvironment (default true) — when false, env var lookups
1202
- * are suppressed (hermetic resolution).
1203
- *
1204
- * E12 decision 3.
1205
- */
1206
- resolve(opts = {}) {
1207
- if (this._resolved) {
1208
- return new _Config(this.root, {
1209
- resolved: true,
1210
- parseBaseDir: this._parseBaseDir,
1211
- originDescription: this._originDescription
1212
- });
1213
- }
1214
- const tree = this._resObjRoot;
1215
- if (!tree) {
1216
- return new _Config(this.root, { resolved: true });
1217
- }
1218
- const resolveOpts = {
1219
- ...this._resolveOpts ?? { env: {}, baseDir: void 0, readFileSync: () => {
1220
- throw new Error("no files");
1221
- } },
1222
- allowUnresolved: opts.allowUnresolved ?? false,
1223
- useSystemEnvironment: opts.useSystemEnvironment ?? true,
1224
- originDescription: this._originDescription
1225
- };
1226
- const resolved = resolveTree(tree, resolveOpts);
1227
- if (resolved.kind !== "object") throw new Error("resolve: expected object root");
1228
- if (opts.allowUnresolved) {
1229
- const { stripped, hadPlaceholders } = stripPlaceholderFields(resolved);
1230
- return new _Config(stripped, {
1231
- resolved: !hadPlaceholders,
1232
- parseBaseDir: this._parseBaseDir,
1233
- originDescription: this._originDescription,
1234
- resObjRoot: hadPlaceholders ? tree : void 0,
1235
- resolveOpts: hadPlaceholders ? resolveOpts : void 0
1236
- });
1237
- }
1238
- return new _Config(resolved, {
1239
- resolved: true,
1240
- parseBaseDir: this._parseBaseDir,
1241
- originDescription: this._originDescription
1242
- });
1243
- }
1244
- /**
1245
- * Resolves receiver substitutions using source as lookup context.
1246
- * Source's keys are NOT merged into the result — differs from
1247
- * `this.withFallback(source).resolve()` which includes source keys.
1248
- *
1249
- * Precondition (E12 decision 10): source must be resolved. If
1250
- * source.isResolved() is false, throws NotResolvedError.
1251
- *
1252
- * On an already-resolved receiver, resolveWith is a no-op (returns an
1253
- * equivalent resolved Config, source keys not included).
1254
- *
1255
- * E12 decisions 9, 10.
1256
- */
1257
- resolveWith(source, opts = {}) {
1258
- if (!source.isResolved()) {
1259
- throw new NotResolvedError("source");
1260
- }
1261
- if (this._resolved) {
1262
- return new _Config(this.root, {
1263
- resolved: true,
1264
- parseBaseDir: this._parseBaseDir,
1265
- originDescription: this._originDescription
1266
- });
1267
- }
1268
- const receiverTree = this._resObjRoot ?? hoconValueToResObj2(this.root);
1269
- const srcTree = hoconValueToResObj2(source.root);
1270
- const merged = mergeUnresolved(receiverTree, srcTree);
1271
- const resolveOpts = {
1272
- ...this._resolveOpts ?? { env: {}, baseDir: void 0, readFileSync: () => {
1273
- throw new Error("no files");
1274
- } },
1275
- allowUnresolved: opts.allowUnresolved ?? false,
1276
- useSystemEnvironment: opts.useSystemEnvironment ?? true,
1277
- originDescription: this._originDescription
1278
- };
1279
- const resolved = resolveTree(merged, resolveOpts);
1280
- if (resolved.kind !== "object") throw new Error("resolveWith: expected object root");
1281
- const receiverShapeForFilter = resObjToKeyShape(receiverTree);
1282
- const filtered = filterByReceiverShape(resolved, receiverShapeForFilter);
1283
- if (opts.allowUnresolved) {
1284
- const { stripped, hadPlaceholders } = stripPlaceholderFields(filtered);
1285
- return new _Config(stripped, {
1286
- resolved: !hadPlaceholders,
1287
- parseBaseDir: this._parseBaseDir,
1288
- originDescription: this._originDescription,
1289
- resObjRoot: hadPlaceholders ? receiverTree : void 0,
1290
- resolveOpts: hadPlaceholders ? resolveOpts : void 0
1291
- });
1292
- }
1293
- return new _Config(filtered, {
1294
- resolved: true,
1295
- parseBaseDir: this._parseBaseDir,
1296
- originDescription: this._originDescription
1297
- });
1298
- }
1299
- /**
1300
- * The whole config as plain JS data: objects, arrays, strings, numbers,
1301
- * booleans and `null`.
1302
- *
1303
- * Keys are reproduced exactly as the config carries them, `__proto__`,
1304
- * `constructor` and `prototype` included: each is defined as an **own data
1305
- * property**, so the returned object's prototype is always
1306
- * `Object.prototype`, and this call writes nothing to the global one.
1307
- *
1308
- * ### Passing the result to other code
1309
- *
1310
- * A config file — especially a `.properties` file or an env namespace you
1311
- * merged in — can therefore hand you an own `__proto__` key, and what happens
1312
- * next depends entirely on how the consumer copies it:
1313
- *
1314
- * ```ts
1315
- * const data = cfg.toObject()
1316
- * { ...data } // safe — own properties are copied as data
1317
- * structuredClone(data) // safe
1318
- * Object.assign({}, data) // NOT safe — [[Set]] on the {} target hits
1319
- * // Object.prototype's __proto__ setter: the key
1320
- * // vanishes and config data becomes the result's
1321
- * // prototype
1322
- * deepMerge({}, data) // NOT safe — a naive recursive merge reads
1323
- * // target['__proto__'], gets Object.prototype,
1324
- * // and writes to it: global pollution
1325
- * for (const k in data) … // prefer Object.entries / Object.keys
1326
- * ```
1327
- *
1328
- * Those two hazards come from the **destination** object's prototype, so no
1329
- * option here can disarm them — copy with spread or `structuredClone` instead.
1330
- *
1331
- * What `{ nullPrototype: true }` does give you is a result that inherits
1332
- * nothing: every object comes back with a `null` prototype, so reading
1333
- * `x.__proto__`, `x.constructor` or `x.toString` yields config data or
1334
- * `undefined` rather than something from `Object.prototype`, and code that
1335
- * merges *into* this object cannot climb out of it. Keys are all still
1336
- * present. The trade-off is the usual one for prototype-less objects: not
1337
- * `instanceof Object`, and no `hasOwnProperty` of their own.
1338
- *
1339
- * Numbers follow the JS number model, so an integer wider than 2^53 rounds
1340
- * here even when the config holds it exactly — read those with
1341
- * {@link Config.getString} instead.
1342
- */
1343
- toObject(opts) {
1344
- return hoconToJs(this.root, opts?.nullPrototype === true);
1345
- }
1346
- /**
1347
- * @internal Test-only: renders this resolved Config's value tree as canonical
1348
- * JSON (sorted keys, no whitespace). Used by Layer-2 fixture tests to compare
1349
- * against Lightbend ground truth. NOT part of the public API.
1350
- *
1351
- * Throws if the Config is unresolved (contains placeholders).
1352
- */
1353
- _renderJSONForTest() {
1354
- return renderHoconAsJSON(this.root);
1355
- }
1356
- lookupNode(path) {
1357
- const segments = splitConfigPath(path);
1358
- let current = this.root;
1359
- for (const seg of segments) {
1360
- if (current.kind !== "object") return void 0;
1361
- const next = current.fields.get(seg);
1362
- if (next === void 0) return void 0;
1363
- current = next;
1364
- }
1365
- return current;
1366
- }
1367
- /**
1368
- * _resObjRootSubtreeHasPlaceholders — walk _resObjRoot to the given path and
1369
- * return true if the subtree there contains any unresolved placeholder.
1370
- * Used by getConfig / getList (T2) to detect transitive unresolved placeholders
1371
- * in object / array subtrees that would otherwise appear to be "resolved" in the
1372
- * partial HoconValue root (because individual leaf fields are omitted rather than
1373
- * the whole subtree when their value is a direct placeholder scalar, but object
1374
- * sub-containers are retained in the partial root with the placeholder-keyed
1375
- * fields omitted from them — so the object appears "present but empty-ish").
1376
- */
1377
- _resObjRootSubtreeHasPlaceholders(path) {
1378
- const tree = this._resObjRoot;
1379
- if (!tree) return false;
1380
- const segments = splitConfigPath(path);
1381
- let cur = tree;
1382
- for (const seg of segments) {
1383
- const val = cur.fields.get(seg);
1384
- if (val === void 0) return false;
1385
- if (isResObj(val)) {
1386
- cur = val;
1387
- } else {
1388
- return valContainsPlaceholders(val);
1389
- }
1390
- }
1391
- return containsPlaceholders(cur);
1392
- }
1393
- requireScalar(path) {
1394
- const v = this.lookupNode(path);
1395
- if (v === void 0) {
1396
- if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path)) {
1397
- throw new NotResolvedError(path);
1398
- }
1399
- throw new ConfigError(`path not found: ${path}`, path);
1400
- }
1401
- if (v.kind !== "scalar") throw new ConfigError(`expected scalar at ${path}, got ${v.kind}`, path);
1402
- return v;
1403
- }
1404
- };
1405
- function splitConfigPath(path) {
1406
- const segments = [];
1407
- let i = 0;
1408
- while (i < path.length) {
1409
- if (path[i] === '"') {
1410
- i++;
1411
- let segment = "";
1412
- let closed = false;
1413
- while (i < path.length) {
1414
- const ch = path[i];
1415
- if (ch === "\\" && i + 1 < path.length) {
1416
- const next = path[i + 1];
1417
- segment += next;
1418
- i += 2;
1419
- continue;
1420
- }
1421
- if (ch === '"') {
1422
- closed = true;
1423
- i++;
1424
- break;
1425
- }
1426
- segment += ch;
1427
- i++;
1428
- }
1429
- if (!closed) throw new ConfigError(`unterminated quoted path segment: ${path}`, path);
1430
- segments.push(segment);
1431
- if (i < path.length && path[i] === ".") i++;
1432
- } else {
1433
- const dot = path.indexOf(".", i);
1434
- if (dot === -1) {
1435
- segments.push(path.slice(i));
1436
- break;
1437
- }
1438
- segments.push(path.slice(i, dot));
1439
- i = dot + 1;
1440
- }
1441
- }
1442
- return segments;
1443
- }
1444
- function scalarToJs(raw, valueType) {
1445
- switch (valueType) {
1446
- case "null":
1447
- return null;
1448
- case "boolean":
1449
- return raw === "true";
1450
- case "number":
1451
- return Number(raw);
1452
- case "string":
1453
- return raw;
1454
- }
1455
- }
1456
- function hoconToJs(v, nullPrototype = false) {
1457
- switch (v.kind) {
1458
- case "scalar":
1459
- return scalarToJs(v.raw, v.valueType);
1460
- case "array":
1461
- return v.items.map((item) => hoconToJs(item, nullPrototype));
1462
- case "object": {
1463
- const entries = Array.from(v.fields, ([k, val]) => [k, hoconToJs(val, nullPrototype)]);
1464
- if (nullPrototype) {
1465
- const obj = /* @__PURE__ */ Object.create(null);
1466
- for (const [k, val] of entries) Object.defineProperty(obj, k, {
1467
- value: val,
1468
- writable: true,
1469
- enumerable: true,
1470
- configurable: true
1471
- });
1472
- return obj;
1473
- }
1474
- return Object.fromEntries(entries);
1475
- }
1476
- }
1477
- }
1478
- function resObjToKeyShape(tree) {
1479
- const fields = /* @__PURE__ */ new Map();
1480
- for (const [k, v] of tree.fields) {
1481
- if (isSubst(v) || isConcat(v)) {
1482
- fields.set(k, { kind: "scalar", raw: "", valueType: "null" });
1483
- } else if (isResObj(v)) {
1484
- fields.set(k, resObjToKeyShape(v));
1485
- } else {
1486
- fields.set(k, v);
1487
- }
1488
- }
1489
- return { kind: "object", fields };
1490
- }
1491
- function stripPlaceholderFields(v) {
1492
- const fields = /* @__PURE__ */ new Map();
1493
- let hadPlaceholders = false;
1494
- for (const [k, val] of v.fields) {
1495
- if (val._kind === "subst-placeholder" || val._kind === "concat-placeholder") {
1496
- hadPlaceholders = true;
1497
- } else if (val.kind === "object") {
1498
- const inner = stripPlaceholderFields(val);
1499
- if (inner.hadPlaceholders) hadPlaceholders = true;
1500
- fields.set(k, inner.stripped);
1501
- } else {
1502
- fields.set(k, val);
1503
- }
1504
- }
1505
- return { stripped: { kind: "object", fields }, hadPlaceholders };
1506
- }
1507
- function filterByReceiverShape(resolved, receiverShape) {
1508
- const fields = /* @__PURE__ */ new Map();
1509
- for (const [k, rv] of resolved.fields) {
1510
- if (!receiverShape.fields.has(k)) continue;
1511
- const receiverVal = receiverShape.fields.get(k);
1512
- if (rv.kind === "object" && receiverVal.kind === "object") {
1513
- fields.set(k, filterByReceiverShape(rv, receiverVal));
1514
- } else {
1515
- fields.set(k, rv);
1516
- }
1517
- }
1518
- return { kind: "object", fields };
1519
- }
1520
- function renderHoconAsJSON(v) {
1521
- switch (v.kind) {
1522
- case "scalar": {
1523
- switch (v.valueType) {
1524
- case "null":
1525
- return "null";
1526
- case "boolean":
1527
- return v.raw;
1528
- case "number": {
1529
- const norm = normalizeLeadingZeroNumber(v.raw);
1530
- return JSON_NUMBER_RE.test(norm) ? norm : JSON.stringify(v.raw);
1531
- }
1532
- case "string":
1533
- return JSON.stringify(v.raw);
1534
- }
1535
- break;
1536
- }
1537
- case "array": {
1538
- const items = v.items.map(renderHoconAsJSON);
1539
- return `[${items.join(",")}]`;
1540
- }
1541
- case "object": {
1542
- const keys = [...v.fields.keys()].sort();
1543
- const pairs = keys.map((k) => {
1544
- const val = v.fields.get(k);
1545
- return `${JSON.stringify(k)}:${renderHoconAsJSON(val)}`;
1546
- });
1547
- return `{${pairs.join(",")}}`;
1548
- }
1549
- }
1550
- throw new Error(`renderHoconAsJSON: unsupported value kind (unresolved placeholder?)`);
1551
- }
1552
- var JSON_NUMBER_RE = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
1553
- function normalizeLeadingZeroNumber(raw) {
1554
- return raw.replace(/^([+-]?)0+(\d)/, "$1$2");
1555
- }
1556
8
 
1557
- // src/value-factory.ts
1558
- function fromMap(values, originDescription) {
1559
- const fields = guardStackDepth(
1560
- () => coerceObject(values, ""),
1561
- (msg) => depthError(`fromMap: ${msg}`)
1562
- );
1563
- const root = { kind: "object", fields };
1564
- return Config._fromResolvedValue(root, { originDescription });
1565
- }
1566
- var INT64_MAX = 9223372036854775807n;
1567
- var INT64_MIN = -9223372036854775808n;
1568
- function coerceObject(obj, atPath) {
1569
- const fields = /* @__PURE__ */ new Map();
1570
- for (const [k, v] of Object.entries(obj)) {
1571
- const childPath = atPath ? `${atPath}.${k}` : k;
1572
- fields.set(k, coerceValue(v, childPath));
1573
- }
1574
- return fields;
1575
- }
1576
- function coerceValue(v, atPath) {
1577
- if (v === null) {
1578
- return { kind: "scalar", raw: "null", valueType: "null" };
1579
- }
1580
- if (v === void 0) {
1581
- throw new ConfigError(
1582
- `fromMap: undefined is not a valid HOCON value at path "${atPath}"`,
1583
- atPath
1584
- );
1585
- }
1586
- switch (typeof v) {
1587
- case "string":
1588
- return { kind: "scalar", raw: v, valueType: "string" };
1589
- case "number": {
1590
- if (Number.isNaN(v) || !Number.isFinite(v)) {
1591
- throw new ConfigError(
1592
- `fromMap: ${v} is not representable in HOCON (NaN/Infinity not allowed) at path "${atPath}"`,
1593
- atPath
1594
- );
1595
- }
1596
- return { kind: "scalar", raw: Object.is(v, -0) ? "-0" : String(v), valueType: "number" };
1597
- }
1598
- case "boolean":
1599
- return { kind: "scalar", raw: v ? "true" : "false", valueType: "boolean" };
1600
- case "bigint": {
1601
- if (v > INT64_MAX || v < INT64_MIN) {
1602
- throw new ConfigError(
1603
- `fromMap: integer ${v} is out of int64 range (HOCON integers are int64; spec F0.5) at path "${atPath}"`,
1604
- atPath
1605
- );
1606
- }
1607
- return { kind: "scalar", raw: String(v), valueType: "number" };
1608
- }
1609
- case "object": {
1610
- if (Array.isArray(v)) {
1611
- const items = v.map((item, i) => coerceValue(item, `${atPath}[${i}]`));
1612
- return { kind: "array", items };
1613
- }
1614
- const fields = coerceObject(v, atPath);
1615
- return { kind: "object", fields };
1616
- }
1617
- default:
1618
- throw new ConfigError(
1619
- `fromMap: unsupported value type "${typeof v}" at path "${atPath}"`,
1620
- atPath
1621
- );
1622
- }
1623
- }
9
+ var _chunkRO4D6BH7cjs = require('../chunk-RO4D6BH7.cjs');
1624
10
 
1625
11
  // src/adapters/jsonc.ts
1626
12
  function parseJsonc(input, originDescription) {
1627
- const doc = guardStackDepth(
1628
- () => JSON.parse(stripTrailingCommas(stripComments(stripBom(input))), bigIntReviver),
1629
- (msg) => depthError(`jsonc: ${msg}`)
13
+ const doc = _chunkRO4D6BH7cjs.guardStackDepth.call(void 0,
14
+ () => JSON.parse(stripTrailingCommas(stripComments(_chunkRO4D6BH7cjs.stripBom.call(void 0, input))), bigIntReviver),
15
+ (msg) => _chunkRO4D6BH7cjs.depthError.call(void 0, `jsonc: ${msg}`)
1630
16
  );
1631
17
  if (doc === null || typeof doc !== "object" || Array.isArray(doc)) {
1632
- throw new ConfigError(
18
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
1633
19
  `jsonc: document root is ${Array.isArray(doc) ? "an array" : typeof doc}, but a config root must be an object (spec F0.3)`,
1634
20
  ""
1635
21
  );
1636
22
  }
1637
- return fromMap(doc, originDescription);
23
+ return _chunkGBNQADHTcjs.fromMap.call(void 0, doc, originDescription);
1638
24
  }
1639
25
  function isIntegerLiteral(source) {
1640
26
  return !/[.eE]/.test(source);
@@ -1642,17 +28,17 @@ function isIntegerLiteral(source) {
1642
28
  var HAS_SOURCE_TEXT_ACCESS = (() => {
1643
29
  let seen;
1644
30
  JSON.parse("1", function(_k, v, context) {
1645
- seen = context?.source;
31
+ seen = _optionalChain([context, 'optionalAccess', _ => _.source]);
1646
32
  return v;
1647
33
  });
1648
34
  return seen !== void 0;
1649
35
  })();
1650
36
  function bigIntReviver(key, value, context) {
1651
37
  if (typeof value !== "number" || Number.isSafeInteger(value)) return value;
1652
- const source = context?.source;
38
+ const source = _optionalChain([context, 'optionalAccess', _2 => _2.source]);
1653
39
  if (source === void 0) {
1654
40
  if (!Number.isInteger(value)) return value;
1655
- throw new ConfigError(
41
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)(
1656
42
  `jsonc: the integer at "${key || "<root>"}" needs more precision than a JS number holds, and this runtime does not expose JSON.parse source text (${HAS_SOURCE_TEXT_ACCESS ? "unexpected \u2014 the capability probe said otherwise" : "requires Node >= 22 or an engine with JSON.parse source access"}), so it cannot be read losslessly (spec F0.5)`,
1657
43
  key
1658
44
  );
@@ -1696,7 +82,7 @@ function stripComments(src) {
1696
82
  }
1697
83
  if (c === "/" && src[i + 1] === "*") {
1698
84
  const end = src.indexOf("*/", i + 2);
1699
- if (end === -1) throw new ConfigError("jsonc: unterminated block comment", "");
85
+ if (end === -1) throw new (0, _chunkRO4D6BH7cjs.ConfigError)("jsonc: unterminated block comment", "");
1700
86
  out += lineBreaksOf(src.slice(i, end + 2)) || " ";
1701
87
  i = end + 2;
1702
88
  continue;
@@ -1711,7 +97,7 @@ function endOfString(src, i) {
1711
97
  if (src[j] === "\\") j++;
1712
98
  else if (src[j] === '"') return j + 1;
1713
99
  }
1714
- throw new ConfigError("jsonc: unterminated string literal", "");
100
+ throw new (0, _chunkRO4D6BH7cjs.ConfigError)("jsonc: unterminated string literal", "");
1715
101
  }
1716
102
  function stripTrailingCommas(src) {
1717
103
  let out = "";
@@ -1736,8 +122,7 @@ function stripTrailingCommas(src) {
1736
122
  }
1737
123
  return out;
1738
124
  }
1739
- // Annotate the CommonJS export names for ESM import in node:
1740
- 0 && (module.exports = {
1741
- parseJsonc,
1742
- stripComments
1743
- });
125
+
126
+
127
+
128
+ exports.parseJsonc = parseJsonc; exports.stripComments = stripComments;