@o3co/ts.hocon 1.13.0 → 1.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +253 -29
- package/README.md +161 -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-GOXMKYWS.js +3801 -0
- package/dist/chunk-JVABBNF5.js +158 -0
- package/dist/chunk-L3D2RE2U.cjs +3801 -0
- package/dist/chunk-OUPKYWL3.cjs +158 -0
- package/dist/chunk-PCAMDXJ4.cjs +83 -0
- package/dist/chunk-YRNDXYGQ.js +83 -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 +195 -3636
- package/dist/zod.d.cts +86 -3
- package/dist/zod.d.ts +86 -3
- package/dist/zod.js +182 -3589
- package/package.json +5 -5
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkL3D2RE2Ucjs = require('./chunk-L3D2RE2U.cjs');
|
|
15
|
+
|
|
16
|
+
// src/parse.ts
|
|
17
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
18
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
19
|
+
function defaultParseOptions() {
|
|
20
|
+
return { resolveSubstitutions: true };
|
|
21
|
+
}
|
|
22
|
+
function defaultResolveOptions() {
|
|
23
|
+
return { useSystemEnvironment: true, allowUnresolved: false };
|
|
24
|
+
}
|
|
25
|
+
function getEnv(opts) {
|
|
26
|
+
if (opts.env !== void 0) return opts.env;
|
|
27
|
+
if (typeof process !== "undefined" && process.env) return process.env;
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
function defaultReadFileSync(filePath) {
|
|
31
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
32
|
+
}
|
|
33
|
+
async function defaultReadFile(filePath) {
|
|
34
|
+
return fs.promises.readFile(filePath, "utf-8");
|
|
35
|
+
}
|
|
36
|
+
function buildResolveContext(input, opts) {
|
|
37
|
+
const tokens = _chunkL3D2RE2Ucjs.tokenize.call(void 0, input);
|
|
38
|
+
const ast = _chunkL3D2RE2Ucjs.parseTokens.call(void 0, tokens);
|
|
39
|
+
if (ast.kind === "array") {
|
|
40
|
+
const origin = _nullishCoalesce(opts.originDescription, () => ( "input"));
|
|
41
|
+
throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
|
|
42
|
+
`${origin}: ${ast.pos.line}:${ast.pos.col}: document has type array rather than object at file root (HOCON.md L989-991); the Config API requires an object root`,
|
|
43
|
+
""
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
const resolveOpts = {
|
|
47
|
+
env: getEnv(opts),
|
|
48
|
+
baseDir: opts.baseDir,
|
|
49
|
+
readFileSync: _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync)),
|
|
50
|
+
readFile: opts.readFile,
|
|
51
|
+
originDescription: opts.originDescription,
|
|
52
|
+
resolveFrom: opts.resolveFrom,
|
|
53
|
+
packageResolver: opts.packageResolver
|
|
54
|
+
};
|
|
55
|
+
return { ast, resolveOpts };
|
|
56
|
+
}
|
|
57
|
+
function parse(input, opts = {}) {
|
|
58
|
+
return parseStringWithOptions(input, opts);
|
|
59
|
+
}
|
|
60
|
+
var parseString = parse;
|
|
61
|
+
function parseStringWithOptions(input, opts = {}) {
|
|
62
|
+
return _chunkL3D2RE2Ucjs.guardStackDepth.call(void 0,
|
|
63
|
+
() => parseStringInner(input, opts),
|
|
64
|
+
(msg) => new (0, _chunkL3D2RE2Ucjs.ParseError)(msg, 1, 1, opts.originDescription)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
function parseStringInner(input, opts) {
|
|
68
|
+
const resolveSubstitutions = _nullishCoalesce(opts.resolveSubstitutions, () => ( true));
|
|
69
|
+
const { ast, resolveOpts } = buildResolveContext(input, opts);
|
|
70
|
+
if (resolveSubstitutions) {
|
|
71
|
+
const value = _chunkL3D2RE2Ucjs.resolve.call(void 0, ast, resolveOpts);
|
|
72
|
+
if (value.kind !== "object") throw new Error("resolved value is not an object");
|
|
73
|
+
return new (0, _chunkL3D2RE2Ucjs.Config)(value, { resolved: true, originDescription: opts.originDescription });
|
|
74
|
+
}
|
|
75
|
+
const tree = _chunkL3D2RE2Ucjs.buildTree.call(void 0, ast, resolveOpts);
|
|
76
|
+
const hasPlaceholders = _chunkL3D2RE2Ucjs.containsPlaceholders.call(void 0, tree);
|
|
77
|
+
return _chunkL3D2RE2Ucjs.Config._fromUnresolvedResObj(tree, {
|
|
78
|
+
parseBaseDir: opts.baseDir,
|
|
79
|
+
originDescription: opts.originDescription,
|
|
80
|
+
resolved: !hasPlaceholders,
|
|
81
|
+
resolveOpts
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function parseFileWithOptions(filePath, opts = {}) {
|
|
85
|
+
if (typeof process === "undefined" && !opts.readFileSync) {
|
|
86
|
+
throw new Error("parseFileWithOptions is not supported in browser environments without opts.readFileSync.");
|
|
87
|
+
}
|
|
88
|
+
const resolvedPath = path.resolve(filePath);
|
|
89
|
+
const readFileSync2 = _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync));
|
|
90
|
+
const input = readFileSync2(resolvedPath);
|
|
91
|
+
return parseStringWithOptions(input, {
|
|
92
|
+
...opts,
|
|
93
|
+
baseDir: _nullishCoalesce(opts.baseDir, () => ( path.dirname(resolvedPath))),
|
|
94
|
+
readFileSync: readFileSync2
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async function parseAsync(input, opts = {}) {
|
|
98
|
+
return _chunkL3D2RE2Ucjs.guardStackDepthAsync.call(void 0,
|
|
99
|
+
() => parseStringInnerAsync(input, opts),
|
|
100
|
+
(msg) => new (0, _chunkL3D2RE2Ucjs.ParseError)(msg, 1, 1, opts.originDescription)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
async function parseStringInnerAsync(input, opts) {
|
|
104
|
+
const resolveSubstitutions = _nullishCoalesce(opts.resolveSubstitutions, () => ( true));
|
|
105
|
+
const { ast, resolveOpts } = buildResolveContext(input, opts);
|
|
106
|
+
if (resolveSubstitutions) {
|
|
107
|
+
const value = await _chunkL3D2RE2Ucjs.resolveAsync.call(void 0, ast, resolveOpts);
|
|
108
|
+
if (value.kind !== "object") throw new Error("resolved value is not an object");
|
|
109
|
+
return new (0, _chunkL3D2RE2Ucjs.Config)(value, { resolved: true, originDescription: opts.originDescription });
|
|
110
|
+
}
|
|
111
|
+
const tree = await _chunkL3D2RE2Ucjs.buildTreeAsync.call(void 0, ast, resolveOpts);
|
|
112
|
+
const hasPlaceholders = _chunkL3D2RE2Ucjs.containsPlaceholders.call(void 0, tree);
|
|
113
|
+
return _chunkL3D2RE2Ucjs.Config._fromUnresolvedResObj(tree, {
|
|
114
|
+
parseBaseDir: opts.baseDir,
|
|
115
|
+
originDescription: opts.originDescription,
|
|
116
|
+
resolved: !hasPlaceholders,
|
|
117
|
+
resolveOpts
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function parseFile(filePath, opts = {}) {
|
|
121
|
+
if (typeof process === "undefined" && !opts.readFileSync) {
|
|
122
|
+
throw new Error("parseFile is not supported in browser environments. Provide opts.readFileSync or use parse() instead.");
|
|
123
|
+
}
|
|
124
|
+
const resolvedPath = path.resolve(filePath);
|
|
125
|
+
const readFileSync2 = _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync));
|
|
126
|
+
const input = readFileSync2(resolvedPath);
|
|
127
|
+
return parse(input, {
|
|
128
|
+
...opts,
|
|
129
|
+
baseDir: _nullishCoalesce(opts.baseDir, () => ( path.dirname(resolvedPath))),
|
|
130
|
+
readFileSync: readFileSync2
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async function parseFileAsync(filePath, opts = {}) {
|
|
134
|
+
if (typeof process === "undefined" && !opts.readFile) {
|
|
135
|
+
throw new Error("parseFileAsync is not supported in browser environments. Provide opts.readFile or use parseAsync() instead.");
|
|
136
|
+
}
|
|
137
|
+
const resolvedPath = path.resolve(filePath);
|
|
138
|
+
const readFile = _nullishCoalesce(opts.readFile, () => ( defaultReadFile));
|
|
139
|
+
const input = await readFile(resolvedPath);
|
|
140
|
+
return parseAsync(input, {
|
|
141
|
+
...opts,
|
|
142
|
+
baseDir: _nullishCoalesce(opts.baseDir, () => ( path.dirname(resolvedPath))),
|
|
143
|
+
readFile,
|
|
144
|
+
readFileSync: _nullishCoalesce(opts.readFileSync, () => ( defaultReadFileSync))
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
exports.defaultParseOptions = defaultParseOptions; exports.defaultResolveOptions = defaultResolveOptions; exports.parse = parse; exports.parseString = parseString; exports.parseStringWithOptions = parseStringWithOptions; exports.parseFileWithOptions = parseFileWithOptions; exports.parseAsync = parseAsync; exports.parseFile = parseFile; exports.parseFileAsync = parseFileAsync;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkL3D2RE2Ucjs = require('./chunk-L3D2RE2U.cjs');
|
|
7
|
+
|
|
8
|
+
// src/value-factory.ts
|
|
9
|
+
function fromMap(values, originDescription) {
|
|
10
|
+
const fields = _chunkL3D2RE2Ucjs.guardStackDepth.call(void 0,
|
|
11
|
+
() => coerceObject(values, ""),
|
|
12
|
+
(msg) => _chunkL3D2RE2Ucjs.depthError.call(void 0, `fromMap: ${msg}`)
|
|
13
|
+
);
|
|
14
|
+
const root = { kind: "object", fields };
|
|
15
|
+
return _chunkL3D2RE2Ucjs.Config._fromResolvedValue(root, { originDescription });
|
|
16
|
+
}
|
|
17
|
+
function empty(originDescription) {
|
|
18
|
+
const root = { kind: "object", fields: /* @__PURE__ */ new Map() };
|
|
19
|
+
return _chunkL3D2RE2Ucjs.Config._fromResolvedValue(root, { originDescription });
|
|
20
|
+
}
|
|
21
|
+
var INT64_MAX = 9223372036854775807n;
|
|
22
|
+
var INT64_MIN = -9223372036854775808n;
|
|
23
|
+
function coerceObject(obj, atPath) {
|
|
24
|
+
const fields = /* @__PURE__ */ new Map();
|
|
25
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
26
|
+
const childPath = atPath ? `${atPath}.${k}` : k;
|
|
27
|
+
fields.set(k, coerceValue(v, childPath));
|
|
28
|
+
}
|
|
29
|
+
return fields;
|
|
30
|
+
}
|
|
31
|
+
function coerceValue(v, atPath) {
|
|
32
|
+
if (v === null) {
|
|
33
|
+
return { kind: "scalar", raw: "null", valueType: "null" };
|
|
34
|
+
}
|
|
35
|
+
if (v === void 0) {
|
|
36
|
+
throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
|
|
37
|
+
`fromMap: undefined is not a valid HOCON value at path "${atPath}"`,
|
|
38
|
+
atPath
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
switch (typeof v) {
|
|
42
|
+
case "string":
|
|
43
|
+
return { kind: "scalar", raw: v, valueType: "string" };
|
|
44
|
+
case "number": {
|
|
45
|
+
if (Number.isNaN(v) || !Number.isFinite(v)) {
|
|
46
|
+
throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
|
|
47
|
+
`fromMap: ${v} is not representable in HOCON (NaN/Infinity not allowed) at path "${atPath}"`,
|
|
48
|
+
atPath
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return { kind: "scalar", raw: Object.is(v, -0) ? "-0" : String(v), valueType: "number" };
|
|
52
|
+
}
|
|
53
|
+
case "boolean":
|
|
54
|
+
return { kind: "scalar", raw: v ? "true" : "false", valueType: "boolean" };
|
|
55
|
+
case "bigint": {
|
|
56
|
+
if (v > INT64_MAX || v < INT64_MIN) {
|
|
57
|
+
throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
|
|
58
|
+
`fromMap: integer ${v} is out of int64 range (HOCON integers are int64; spec F0.5) at path "${atPath}"`,
|
|
59
|
+
atPath
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return { kind: "scalar", raw: String(v), valueType: "number" };
|
|
63
|
+
}
|
|
64
|
+
case "object": {
|
|
65
|
+
if (Array.isArray(v)) {
|
|
66
|
+
const items = v.map((item, i) => coerceValue(item, `${atPath}[${i}]`));
|
|
67
|
+
return { kind: "array", items };
|
|
68
|
+
}
|
|
69
|
+
const fields = coerceObject(v, atPath);
|
|
70
|
+
return { kind: "object", fields };
|
|
71
|
+
}
|
|
72
|
+
default:
|
|
73
|
+
throw new (0, _chunkL3D2RE2Ucjs.ConfigError)(
|
|
74
|
+
`fromMap: unsupported value type "${typeof v}" at path "${atPath}"`,
|
|
75
|
+
atPath
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
exports.fromMap = fromMap; exports.empty = empty;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Config,
|
|
3
|
+
ConfigError,
|
|
4
|
+
depthError,
|
|
5
|
+
guardStackDepth
|
|
6
|
+
} from "./chunk-GOXMKYWS.js";
|
|
7
|
+
|
|
8
|
+
// src/value-factory.ts
|
|
9
|
+
function fromMap(values, originDescription) {
|
|
10
|
+
const fields = guardStackDepth(
|
|
11
|
+
() => coerceObject(values, ""),
|
|
12
|
+
(msg) => depthError(`fromMap: ${msg}`)
|
|
13
|
+
);
|
|
14
|
+
const root = { kind: "object", fields };
|
|
15
|
+
return Config._fromResolvedValue(root, { originDescription });
|
|
16
|
+
}
|
|
17
|
+
function empty(originDescription) {
|
|
18
|
+
const root = { kind: "object", fields: /* @__PURE__ */ new Map() };
|
|
19
|
+
return Config._fromResolvedValue(root, { originDescription });
|
|
20
|
+
}
|
|
21
|
+
var INT64_MAX = 9223372036854775807n;
|
|
22
|
+
var INT64_MIN = -9223372036854775808n;
|
|
23
|
+
function coerceObject(obj, atPath) {
|
|
24
|
+
const fields = /* @__PURE__ */ new Map();
|
|
25
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
26
|
+
const childPath = atPath ? `${atPath}.${k}` : k;
|
|
27
|
+
fields.set(k, coerceValue(v, childPath));
|
|
28
|
+
}
|
|
29
|
+
return fields;
|
|
30
|
+
}
|
|
31
|
+
function coerceValue(v, atPath) {
|
|
32
|
+
if (v === null) {
|
|
33
|
+
return { kind: "scalar", raw: "null", valueType: "null" };
|
|
34
|
+
}
|
|
35
|
+
if (v === void 0) {
|
|
36
|
+
throw new ConfigError(
|
|
37
|
+
`fromMap: undefined is not a valid HOCON value at path "${atPath}"`,
|
|
38
|
+
atPath
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
switch (typeof v) {
|
|
42
|
+
case "string":
|
|
43
|
+
return { kind: "scalar", raw: v, valueType: "string" };
|
|
44
|
+
case "number": {
|
|
45
|
+
if (Number.isNaN(v) || !Number.isFinite(v)) {
|
|
46
|
+
throw new ConfigError(
|
|
47
|
+
`fromMap: ${v} is not representable in HOCON (NaN/Infinity not allowed) at path "${atPath}"`,
|
|
48
|
+
atPath
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return { kind: "scalar", raw: Object.is(v, -0) ? "-0" : String(v), valueType: "number" };
|
|
52
|
+
}
|
|
53
|
+
case "boolean":
|
|
54
|
+
return { kind: "scalar", raw: v ? "true" : "false", valueType: "boolean" };
|
|
55
|
+
case "bigint": {
|
|
56
|
+
if (v > INT64_MAX || v < INT64_MIN) {
|
|
57
|
+
throw new ConfigError(
|
|
58
|
+
`fromMap: integer ${v} is out of int64 range (HOCON integers are int64; spec F0.5) at path "${atPath}"`,
|
|
59
|
+
atPath
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return { kind: "scalar", raw: String(v), valueType: "number" };
|
|
63
|
+
}
|
|
64
|
+
case "object": {
|
|
65
|
+
if (Array.isArray(v)) {
|
|
66
|
+
const items = v.map((item, i) => coerceValue(item, `${atPath}[${i}]`));
|
|
67
|
+
return { kind: "array", items };
|
|
68
|
+
}
|
|
69
|
+
const fields = coerceObject(v, atPath);
|
|
70
|
+
return { kind: "object", fields };
|
|
71
|
+
}
|
|
72
|
+
default:
|
|
73
|
+
throw new ConfigError(
|
|
74
|
+
`fromMap: unsupported value type "${typeof v}" at path "${atPath}"`,
|
|
75
|
+
atPath
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
fromMap,
|
|
82
|
+
empty
|
|
83
|
+
};
|
|
@@ -206,6 +206,19 @@ declare function defaultParseOptions(): Required<Pick<ParseOptions, 'resolveSubs
|
|
|
206
206
|
/** Returns a ResolveOptions object with Lightbend-aligned defaults:
|
|
207
207
|
* useSystemEnvironment=true, allowUnresolved=false. */
|
|
208
208
|
declare function defaultResolveOptions(): Required<ResolveOptions>;
|
|
209
|
+
/**
|
|
210
|
+
* Parse a HOCON string into a Config. Substitutions are resolved unless
|
|
211
|
+
* `opts.resolveSubstitutions` is false (then the Config is unresolved; finish
|
|
212
|
+
* it with `resolve()` / `resolveWith()`). Includes are read with
|
|
213
|
+
* `opts.readFileSync` (default: `fs`). A bare `include "x.conf"` resolves
|
|
214
|
+
* relative to `opts.baseDir` (default: the current directory); a relative
|
|
215
|
+
* `include file("x.conf")` always resolves from the current directory.
|
|
216
|
+
*
|
|
217
|
+
* @throws {@link ParseError} on a syntax error, or a document nested too deeply.
|
|
218
|
+
* @throws {@link ResolveError} on a substitution that cannot be resolved, a cycle,
|
|
219
|
+
* or a required include that cannot be found.
|
|
220
|
+
* @throws {@link ConfigError} when the document root is not an object.
|
|
221
|
+
*/
|
|
209
222
|
declare function parse(input: string, opts?: ParseOptions): Config;
|
|
210
223
|
/** Lightbend-aligned alias for parse(). Produces a fully resolved Config. */
|
|
211
224
|
declare const parseString: typeof parse;
|
|
@@ -220,11 +233,35 @@ declare function parseFileWithOptions(filePath: string, opts?: ParseOptions): Co
|
|
|
220
233
|
* asynchronously via `readFile` when provided.
|
|
221
234
|
*/
|
|
222
235
|
declare function parseAsync(input: string, opts?: ParseOptions): Promise<Config>;
|
|
236
|
+
/**
|
|
237
|
+
* Read and parse a HOCON file, as {@link parse} does with the file's text; a
|
|
238
|
+
* bare `include` resolves relative to the file's directory (unless
|
|
239
|
+
* `opts.baseDir` is set), a relative `include file(...)` from the current
|
|
240
|
+
* directory. Needs Node.js, or `opts.readFileSync` elsewhere.
|
|
241
|
+
*
|
|
242
|
+
* @throws as {@link parse}, plus whatever reading the file throws.
|
|
243
|
+
*/
|
|
223
244
|
declare function parseFile(filePath: string, opts?: ParseOptions): Config;
|
|
245
|
+
/**
|
|
246
|
+
* {@link parseFile} with the file and its includes read asynchronously
|
|
247
|
+
* (`opts.readFile`, default `fs.promises`). Needs Node.js, or `opts.readFile`
|
|
248
|
+
* elsewhere.
|
|
249
|
+
*
|
|
250
|
+
* @throws (rejects) as {@link parseFile}.
|
|
251
|
+
*/
|
|
224
252
|
declare function parseFileAsync(filePath: string, opts?: ParseOptions): Promise<Config>;
|
|
225
253
|
|
|
226
254
|
type DurationUnit = 'ns' | 'us' | 'ms' | 's' | 'm' | 'h' | 'd';
|
|
227
255
|
type ByteUnit = 'B' | 'KB' | 'KiB' | 'MB' | 'MiB' | 'GB' | 'GiB' | 'TB' | 'TiB';
|
|
256
|
+
/**
|
|
257
|
+
* A calendar period, as {@link Config.getPeriod} returns it. Weeks are folded
|
|
258
|
+
* into days (`2w` is 14 days). A component may be negative.
|
|
259
|
+
*/
|
|
260
|
+
interface Period {
|
|
261
|
+
readonly years: number;
|
|
262
|
+
readonly months: number;
|
|
263
|
+
readonly days: number;
|
|
264
|
+
}
|
|
228
265
|
|
|
229
266
|
declare class Config {
|
|
230
267
|
private readonly root;
|
|
@@ -236,6 +273,13 @@ declare class Config {
|
|
|
236
273
|
readonly _originDescription: string | undefined;
|
|
237
274
|
/** @internal ResObj tree for deferred-resolution path. Set when resolved=false. */
|
|
238
275
|
readonly _resObjRoot: ResObj | undefined;
|
|
276
|
+
/**
|
|
277
|
+
* @internal What is still unresolved after a partial resolve
|
|
278
|
+
* (`allowUnresolved: true`), with resolved values in place. The unresolved
|
|
279
|
+
* checks read this; `_resObjRoot` keeps the original tree for the next
|
|
280
|
+
* resolve. Unset when the two are the same (a deferred parse).
|
|
281
|
+
*/
|
|
282
|
+
private readonly _pendingRoot;
|
|
239
283
|
/** @internal ResolveOptions stored for the resolve() call. */
|
|
240
284
|
private readonly _resolveOpts;
|
|
241
285
|
constructor(root: HoconValue & {
|
|
@@ -245,6 +289,7 @@ declare class Config {
|
|
|
245
289
|
parseBaseDir?: string;
|
|
246
290
|
originDescription?: string;
|
|
247
291
|
resObjRoot?: ResObj;
|
|
292
|
+
pendingRoot?: ResObj;
|
|
248
293
|
resolveOpts?: ResolveOptions$1;
|
|
249
294
|
});
|
|
250
295
|
/** Returns true when the Config's value tree contains no unresolved
|
|
@@ -279,13 +324,87 @@ declare class Config {
|
|
|
279
324
|
* cannot be represented. This matches `getConfig` / `getList`.
|
|
280
325
|
*/
|
|
281
326
|
getValue(path: string): ReadonlyHoconValue | undefined;
|
|
327
|
+
/**
|
|
328
|
+
* The scalar at `path` as its text: a number or boolean comes back as written
|
|
329
|
+
* (`8080`, `true`).
|
|
330
|
+
*
|
|
331
|
+
* @throws {@link NotResolvedError} when the value is an unresolved substitution.
|
|
332
|
+
* @throws {@link ConfigError} when `path` is missing or is not a scalar, or the value is
|
|
333
|
+
* `null`.
|
|
334
|
+
*/
|
|
282
335
|
getString(path: string): string;
|
|
336
|
+
/**
|
|
337
|
+
* The scalar at `path` as a number. A string that reads as a decimal number
|
|
338
|
+
* (`"8080"`, `"1.5e3"`) is accepted.
|
|
339
|
+
*
|
|
340
|
+
* @throws {@link NotResolvedError} when the value is an unresolved substitution.
|
|
341
|
+
* @throws {@link ConfigError} when `path` is missing or is not a scalar, or the value is not a
|
|
342
|
+
* number.
|
|
343
|
+
*/
|
|
283
344
|
getNumber(path: string): number;
|
|
345
|
+
/**
|
|
346
|
+
* The scalar at `path` as a boolean: `true` / `yes` / `on` and `false` /
|
|
347
|
+
* `no` / `off`, in any case.
|
|
348
|
+
*
|
|
349
|
+
* @throws {@link NotResolvedError} when the value is an unresolved substitution.
|
|
350
|
+
* @throws {@link ConfigError} when `path` is missing or is not a scalar, or the value is not one
|
|
351
|
+
* of those words.
|
|
352
|
+
*/
|
|
284
353
|
getBoolean(path: string): boolean;
|
|
354
|
+
/**
|
|
355
|
+
* The duration at `path` in `unit` (default `ms`): a string with a unit
|
|
356
|
+
* (`"30s"`, `"1.5h"`), or a number or unit-less string, which is
|
|
357
|
+
* milliseconds. The number is read exactly and rounded once in `unit` (E20).
|
|
358
|
+
* Negative durations are allowed.
|
|
359
|
+
*
|
|
360
|
+
* @throws {@link NotResolvedError} when the value is an unresolved substitution.
|
|
361
|
+
* @throws {@link ConfigError} when `path` is missing or is not a string or number, the text is
|
|
362
|
+
* not a duration, or the result is not a finite number (E21).
|
|
363
|
+
*/
|
|
285
364
|
getDuration(path: string, unit?: DurationUnit): number;
|
|
365
|
+
/**
|
|
366
|
+
* The byte size at `path` in `unit` (default `B`): a string with a unit
|
|
367
|
+
* (`"64KiB"`, `"1.5MB"`), or a number or unit-less string, which is bytes.
|
|
368
|
+
* The exact size is truncated toward zero to whole bytes, then converted to
|
|
369
|
+
* `unit` (E20).
|
|
370
|
+
*
|
|
371
|
+
* @throws {@link NotResolvedError} when the value is an unresolved substitution.
|
|
372
|
+
* @throws {@link ConfigError} when `path` is missing or is not a string or number, the text is
|
|
373
|
+
* not a byte size, the size is negative, or it exceeds 2^53-1 bytes (the
|
|
374
|
+
* largest integer a JS number holds exactly).
|
|
375
|
+
*/
|
|
286
376
|
getBytes(path: string, unit?: ByteUnit): number;
|
|
377
|
+
/**
|
|
378
|
+
* The calendar period at `path` (`7d`, `2w`, `3m`, `1y`; a bare integer is
|
|
379
|
+
* days). Integer only, unlike {@link getDuration} / {@link getBytes}.
|
|
380
|
+
*
|
|
381
|
+
* @throws {@link NotResolvedError} when the value is an unresolved substitution.
|
|
382
|
+
* @throws {@link ConfigError} when `path` is missing or is not a string or number, or the text
|
|
383
|
+
* is not a period.
|
|
384
|
+
*/
|
|
385
|
+
getPeriod(path: string): Period;
|
|
386
|
+
/**
|
|
387
|
+
* The object at `path` as a Config of its own, with paths relative to it.
|
|
388
|
+
*
|
|
389
|
+
* @throws {@link NotResolvedError} when the object holds an unresolved substitution.
|
|
390
|
+
* @throws {@link ConfigError} when `path` is missing or is not an object.
|
|
391
|
+
*/
|
|
287
392
|
getConfig(path: string): Config;
|
|
393
|
+
/**
|
|
394
|
+
* The list at `path` as plain values (see {@link get}). An object with integer
|
|
395
|
+
* keys (`"0"`, `"1"`, …) is read as a list too, in key order with gaps closed
|
|
396
|
+
* up; its other keys are ignored (S15).
|
|
397
|
+
*
|
|
398
|
+
* @throws {@link NotResolvedError} when the list holds an unresolved substitution.
|
|
399
|
+
* @throws {@link ConfigError} when `path` is missing or is not a list.
|
|
400
|
+
*/
|
|
288
401
|
getList(path: string): unknown[];
|
|
402
|
+
/**
|
|
403
|
+
* Whether `path` is present. A path whose value is still an unresolved
|
|
404
|
+
* substitution is present too (`true`, no throw), as in go.hocon; reading it
|
|
405
|
+
* throws {@link NotResolvedError}. A path *under* such a value is not known
|
|
406
|
+
* yet and answers `false`.
|
|
407
|
+
*/
|
|
289
408
|
has(path: string): boolean;
|
|
290
409
|
keys(): string[];
|
|
291
410
|
withFallback(fallback: Config | undefined): Config;
|
|
@@ -394,9 +513,12 @@ declare class Config {
|
|
|
394
513
|
*/
|
|
395
514
|
_renderJSONForTest(): string;
|
|
396
515
|
private lookupNode;
|
|
516
|
+
/** Whether `path` names a field in the unresolved tree (a placeholder included). */
|
|
517
|
+
private _unresolvedTreeHas;
|
|
397
518
|
/**
|
|
398
|
-
*
|
|
399
|
-
*
|
|
519
|
+
* _subtreeHasPlaceholders — walk the unresolved tree (`_pendingRoot` after a
|
|
520
|
+
* partial resolve, else `_resObjRoot`) to the given path and return true if
|
|
521
|
+
* the subtree there contains any unresolved placeholder.
|
|
400
522
|
* Used by getConfig / getList (T2) to detect transitive unresolved placeholders
|
|
401
523
|
* in object / array subtrees that would otherwise appear to be "resolved" in the
|
|
402
524
|
* partial HoconValue root (because individual leaf fields are omitted rather than
|
|
@@ -404,8 +526,8 @@ declare class Config {
|
|
|
404
526
|
* sub-containers are retained in the partial root with the placeholder-keyed
|
|
405
527
|
* fields omitted from them — so the object appears "present but empty-ish").
|
|
406
528
|
*/
|
|
407
|
-
private
|
|
529
|
+
private _subtreeHasPlaceholders;
|
|
408
530
|
private requireScalar;
|
|
409
531
|
}
|
|
410
532
|
|
|
411
|
-
export { type ByteUnit as B, Config as C, type DurationUnit as D, type HoconValue as H, type PackageResolver as P, type ReadonlyHoconValue as R, type ScalarValueType as S, type ParseOptions as a, type
|
|
533
|
+
export { type ByteUnit as B, Config as C, type DurationUnit as D, type HoconValue as H, type PackageResolver as P, type ReadonlyHoconValue as R, type ScalarValueType as S, type ParseOptions as a, type Period as b, type ResolveOptions as c, asArray as d, asBoolean as e, asNumber as f, asObject as g, asString as h, defaultParseOptions as i, defaultResolveOptions as j, isArray as k, isNull as l, isObject as m, isScalar as n, parseAsync as o, parse as p, parseFile as q, parseFileAsync as r, parseFileWithOptions as s, parseString as t, parseStringWithOptions as u };
|