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