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