@o3co/ts.hocon 1.14.1 → 1.14.3
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 +12 -2
- package/README.md +12 -2
- package/dist/adapters/env.cjs +16 -16
- package/dist/adapters/env.js +2 -2
- package/dist/adapters/json5.cjs +8 -8
- package/dist/adapters/json5.js +2 -2
- package/dist/adapters/jsonc.cjs +10 -10
- package/dist/adapters/jsonc.js +2 -2
- package/dist/adapters/properties.cjs +3 -3
- package/dist/adapters/properties.js +2 -2
- package/dist/adapters/toml.cjs +7 -7
- package/dist/adapters/toml.js +2 -2
- package/dist/adapters/yaml.cjs +14 -14
- package/dist/adapters/yaml.js +2 -2
- package/dist/{chunk-GOXMKYWS.js → chunk-5PV3HO2V.js} +18 -5
- package/dist/{chunk-OUPKYWL3.cjs → chunk-CPM55MMQ.cjs} +18 -18
- package/dist/{chunk-JVABBNF5.js → chunk-ITRXT66R.js} +1 -1
- package/dist/{chunk-L3D2RE2U.cjs → chunk-NHJJUTAD.cjs} +19 -6
- package/dist/{chunk-PCAMDXJ4.cjs → chunk-SDGXLF4G.cjs} +9 -9
- package/dist/{chunk-YRNDXYGQ.js → chunk-SZ7MDLYZ.js} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.js +3 -3
- package/dist/zod.cjs +76 -41
- package/dist/zod.d.cts +25 -8
- package/dist/zod.d.ts +25 -8
- package/dist/zod.js +52 -17
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkNHJJUTADcjs = require('./chunk-NHJJUTAD.cjs');
|
|
15
15
|
|
|
16
16
|
// src/parse.ts
|
|
17
17
|
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
@@ -34,11 +34,11 @@ async function defaultReadFile(filePath) {
|
|
|
34
34
|
return fs.promises.readFile(filePath, "utf-8");
|
|
35
35
|
}
|
|
36
36
|
function buildResolveContext(input, opts) {
|
|
37
|
-
const tokens =
|
|
38
|
-
const ast =
|
|
37
|
+
const tokens = _chunkNHJJUTADcjs.tokenize.call(void 0, input);
|
|
38
|
+
const ast = _chunkNHJJUTADcjs.parseTokens.call(void 0, tokens);
|
|
39
39
|
if (ast.kind === "array") {
|
|
40
40
|
const origin = _nullishCoalesce(opts.originDescription, () => ( "input"));
|
|
41
|
-
throw new (0,
|
|
41
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
42
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
43
|
""
|
|
44
44
|
);
|
|
@@ -59,22 +59,22 @@ function parse(input, opts = {}) {
|
|
|
59
59
|
}
|
|
60
60
|
var parseString = parse;
|
|
61
61
|
function parseStringWithOptions(input, opts = {}) {
|
|
62
|
-
return
|
|
62
|
+
return _chunkNHJJUTADcjs.guardStackDepth.call(void 0,
|
|
63
63
|
() => parseStringInner(input, opts),
|
|
64
|
-
(msg) => new (0,
|
|
64
|
+
(msg) => new (0, _chunkNHJJUTADcjs.ParseError)(msg, 1, 1, opts.originDescription)
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
function parseStringInner(input, opts) {
|
|
68
68
|
const resolveSubstitutions = _nullishCoalesce(opts.resolveSubstitutions, () => ( true));
|
|
69
69
|
const { ast, resolveOpts } = buildResolveContext(input, opts);
|
|
70
70
|
if (resolveSubstitutions) {
|
|
71
|
-
const value =
|
|
71
|
+
const value = _chunkNHJJUTADcjs.resolve.call(void 0, ast, resolveOpts);
|
|
72
72
|
if (value.kind !== "object") throw new Error("resolved value is not an object");
|
|
73
|
-
return new (0,
|
|
73
|
+
return new (0, _chunkNHJJUTADcjs.Config)(value, { resolved: true, originDescription: opts.originDescription });
|
|
74
74
|
}
|
|
75
|
-
const tree =
|
|
76
|
-
const hasPlaceholders =
|
|
77
|
-
return
|
|
75
|
+
const tree = _chunkNHJJUTADcjs.buildTree.call(void 0, ast, resolveOpts);
|
|
76
|
+
const hasPlaceholders = _chunkNHJJUTADcjs.containsPlaceholders.call(void 0, tree);
|
|
77
|
+
return _chunkNHJJUTADcjs.Config._fromUnresolvedResObj(tree, {
|
|
78
78
|
parseBaseDir: opts.baseDir,
|
|
79
79
|
originDescription: opts.originDescription,
|
|
80
80
|
resolved: !hasPlaceholders,
|
|
@@ -95,22 +95,22 @@ function parseFileWithOptions(filePath, opts = {}) {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
async function parseAsync(input, opts = {}) {
|
|
98
|
-
return
|
|
98
|
+
return _chunkNHJJUTADcjs.guardStackDepthAsync.call(void 0,
|
|
99
99
|
() => parseStringInnerAsync(input, opts),
|
|
100
|
-
(msg) => new (0,
|
|
100
|
+
(msg) => new (0, _chunkNHJJUTADcjs.ParseError)(msg, 1, 1, opts.originDescription)
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
async function parseStringInnerAsync(input, opts) {
|
|
104
104
|
const resolveSubstitutions = _nullishCoalesce(opts.resolveSubstitutions, () => ( true));
|
|
105
105
|
const { ast, resolveOpts } = buildResolveContext(input, opts);
|
|
106
106
|
if (resolveSubstitutions) {
|
|
107
|
-
const value = await
|
|
107
|
+
const value = await _chunkNHJJUTADcjs.resolveAsync.call(void 0, ast, resolveOpts);
|
|
108
108
|
if (value.kind !== "object") throw new Error("resolved value is not an object");
|
|
109
|
-
return new (0,
|
|
109
|
+
return new (0, _chunkNHJJUTADcjs.Config)(value, { resolved: true, originDescription: opts.originDescription });
|
|
110
110
|
}
|
|
111
|
-
const tree = await
|
|
112
|
-
const hasPlaceholders =
|
|
113
|
-
return
|
|
111
|
+
const tree = await _chunkNHJJUTADcjs.buildTreeAsync.call(void 0, ast, resolveOpts);
|
|
112
|
+
const hasPlaceholders = _chunkNHJJUTADcjs.containsPlaceholders.call(void 0, tree);
|
|
113
|
+
return _chunkNHJJUTADcjs.Config._fromUnresolvedResObj(tree, {
|
|
114
114
|
parseBaseDir: opts.baseDir,
|
|
115
115
|
originDescription: opts.originDescription,
|
|
116
116
|
resolved: !hasPlaceholders,
|
|
@@ -265,6 +265,19 @@ function readBytes(text, outputUnit) {
|
|
|
265
265
|
if (value < 0) return { ok: false, problem: "negative" };
|
|
266
266
|
return { ok: true, value };
|
|
267
267
|
}
|
|
268
|
+
function namesMagnitudeUnit(text) {
|
|
269
|
+
const split = splitUnitText(text);
|
|
270
|
+
return split !== void 0 && split.unit !== "";
|
|
271
|
+
}
|
|
272
|
+
function namesPeriodUnit(text) {
|
|
273
|
+
return splitPeriodText(text).unit !== "";
|
|
274
|
+
}
|
|
275
|
+
function splitPeriodText(text) {
|
|
276
|
+
const trimmed = trimHoconWs(text);
|
|
277
|
+
let i = 0;
|
|
278
|
+
while (i < trimmed.length && "+-0123456789".includes(trimmed[i])) i++;
|
|
279
|
+
return { digits: trimmed.slice(0, i), unit: trimHoconWs(trimmed.slice(i)) };
|
|
280
|
+
}
|
|
268
281
|
var PERIOD_UNITS = /* @__PURE__ */ new Map([
|
|
269
282
|
["", { field: "days", factor: 1 }],
|
|
270
283
|
["d", { field: "days", factor: 1 }],
|
|
@@ -284,11 +297,9 @@ var PERIOD_UNITS = /* @__PURE__ */ new Map([
|
|
|
284
297
|
var I32_MIN = -(2 ** 31);
|
|
285
298
|
var I32_MAX = 2 ** 31 - 1;
|
|
286
299
|
function readPeriod(text) {
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const digits = trimmed.slice(0, i);
|
|
291
|
-
const unit = PERIOD_UNITS.get(trimHoconWs(trimmed.slice(i)));
|
|
300
|
+
const split = splitPeriodText(text);
|
|
301
|
+
const digits = split.digits;
|
|
302
|
+
const unit = PERIOD_UNITS.get(split.unit);
|
|
292
303
|
if (!/^[+-]?\d+$/.test(digits) || unit === void 0) return { ok: false, problem: "invalid" };
|
|
293
304
|
const n = Number(digits) * unit.factor;
|
|
294
305
|
if (n < I32_MIN || n > I32_MAX) return { ok: false, problem: "invalid" };
|
|
@@ -3798,4 +3809,6 @@ function completeJsonNumber(raw) {
|
|
|
3798
3809
|
|
|
3799
3810
|
|
|
3800
3811
|
|
|
3801
|
-
|
|
3812
|
+
|
|
3813
|
+
|
|
3814
|
+
exports.coerceBoolean = coerceBoolean; exports.coerceNumber = coerceNumber; exports.readDuration = readDuration; exports.readBytes = readBytes; exports.namesMagnitudeUnit = namesMagnitudeUnit; exports.namesPeriodUnit = namesPeriodUnit; exports.readPeriod = readPeriod; exports.ParseError = ParseError; exports.ResolveError = ResolveError; exports.PackageLookupError = PackageLookupError; exports.ConfigError = ConfigError; exports.NotResolvedError = NotResolvedError; exports.tokenize = tokenize; exports.parseTokens = parseTokens; exports.stripBom = stripBom; exports.MAX_PATH_SEGMENTS = MAX_PATH_SEGMENTS; exports.tooDeep = tooDeep; exports.guardStackDepth = guardStackDepth; exports.depthError = depthError; exports.guardStackDepthAsync = guardStackDepthAsync; exports.parseProperties = parseProperties; exports.nestPairs = nestPairs; exports.pathKey = pathKey; exports.buildTree = buildTree; exports.buildTreeAsync = buildTreeAsync; exports.containsPlaceholders = containsPlaceholders; exports.resolve = resolve2; exports.resolveAsync = resolveAsync; exports.Config = Config;
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkNHJJUTADcjs = require('./chunk-NHJJUTAD.cjs');
|
|
7
7
|
|
|
8
8
|
// src/value-factory.ts
|
|
9
9
|
function fromMap(values, originDescription) {
|
|
10
|
-
const fields =
|
|
10
|
+
const fields = _chunkNHJJUTADcjs.guardStackDepth.call(void 0,
|
|
11
11
|
() => coerceObject(values, ""),
|
|
12
|
-
(msg) =>
|
|
12
|
+
(msg) => _chunkNHJJUTADcjs.depthError.call(void 0, `fromMap: ${msg}`)
|
|
13
13
|
);
|
|
14
14
|
const root = { kind: "object", fields };
|
|
15
|
-
return
|
|
15
|
+
return _chunkNHJJUTADcjs.Config._fromResolvedValue(root, { originDescription });
|
|
16
16
|
}
|
|
17
17
|
function empty(originDescription) {
|
|
18
18
|
const root = { kind: "object", fields: /* @__PURE__ */ new Map() };
|
|
19
|
-
return
|
|
19
|
+
return _chunkNHJJUTADcjs.Config._fromResolvedValue(root, { originDescription });
|
|
20
20
|
}
|
|
21
21
|
var INT64_MAX = 9223372036854775807n;
|
|
22
22
|
var INT64_MIN = -9223372036854775808n;
|
|
@@ -33,7 +33,7 @@ function coerceValue(v, atPath) {
|
|
|
33
33
|
return { kind: "scalar", raw: "null", valueType: "null" };
|
|
34
34
|
}
|
|
35
35
|
if (v === void 0) {
|
|
36
|
-
throw new (0,
|
|
36
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
37
37
|
`fromMap: undefined is not a valid HOCON value at path "${atPath}"`,
|
|
38
38
|
atPath
|
|
39
39
|
);
|
|
@@ -43,7 +43,7 @@ function coerceValue(v, atPath) {
|
|
|
43
43
|
return { kind: "scalar", raw: v, valueType: "string" };
|
|
44
44
|
case "number": {
|
|
45
45
|
if (Number.isNaN(v) || !Number.isFinite(v)) {
|
|
46
|
-
throw new (0,
|
|
46
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
47
47
|
`fromMap: ${v} is not representable in HOCON (NaN/Infinity not allowed) at path "${atPath}"`,
|
|
48
48
|
atPath
|
|
49
49
|
);
|
|
@@ -54,7 +54,7 @@ function coerceValue(v, atPath) {
|
|
|
54
54
|
return { kind: "scalar", raw: v ? "true" : "false", valueType: "boolean" };
|
|
55
55
|
case "bigint": {
|
|
56
56
|
if (v > INT64_MAX || v < INT64_MIN) {
|
|
57
|
-
throw new (0,
|
|
57
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
58
58
|
`fromMap: integer ${v} is out of int64 range (HOCON integers are int64; spec F0.5) at path "${atPath}"`,
|
|
59
59
|
atPath
|
|
60
60
|
);
|
|
@@ -70,7 +70,7 @@ function coerceValue(v, atPath) {
|
|
|
70
70
|
return { kind: "object", fields };
|
|
71
71
|
}
|
|
72
72
|
default:
|
|
73
|
-
throw new (0,
|
|
73
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
74
74
|
`fromMap: unsupported value type "${typeof v}" at path "${atPath}"`,
|
|
75
75
|
atPath
|
|
76
76
|
);
|
package/dist/index.cjs
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkCPM55MMQcjs = require('./chunk-CPM55MMQ.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkSDGXLF4Gcjs = require('./chunk-SDGXLF4G.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
@@ -22,17 +22,17 @@ var _chunkPCAMDXJ4cjs = require('./chunk-PCAMDXJ4.cjs');
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var _chunkNHJJUTADcjs = require('./chunk-NHJJUTAD.cjs');
|
|
26
26
|
|
|
27
27
|
// src/value.ts
|
|
28
28
|
function asString(v) {
|
|
29
29
|
return v.kind === "scalar" && v.valueType === "string" ? v.raw : void 0;
|
|
30
30
|
}
|
|
31
31
|
function asNumber(v) {
|
|
32
|
-
return v.kind === "scalar" ?
|
|
32
|
+
return v.kind === "scalar" ? _chunkNHJJUTADcjs.coerceNumber.call(void 0, v.raw) : void 0;
|
|
33
33
|
}
|
|
34
34
|
function asBoolean(v) {
|
|
35
|
-
return v.kind === "scalar" ?
|
|
35
|
+
return v.kind === "scalar" ? _chunkNHJJUTADcjs.coerceBoolean.call(void 0, v.raw) : void 0;
|
|
36
36
|
}
|
|
37
37
|
function asObject(v) {
|
|
38
38
|
return v.kind === "object" ? v.fields : void 0;
|
|
@@ -79,4 +79,4 @@ function isNull(v) {
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
exports.Config =
|
|
82
|
+
exports.Config = _chunkNHJJUTADcjs.Config; exports.ConfigError = _chunkNHJJUTADcjs.ConfigError; exports.NotResolvedError = _chunkNHJJUTADcjs.NotResolvedError; exports.PackageLookupError = _chunkNHJJUTADcjs.PackageLookupError; exports.ParseError = _chunkNHJJUTADcjs.ParseError; exports.ResolveError = _chunkNHJJUTADcjs.ResolveError; exports.asArray = asArray; exports.asBoolean = asBoolean; exports.asNumber = asNumber; exports.asObject = asObject; exports.asString = asString; exports.defaultParseOptions = _chunkCPM55MMQcjs.defaultParseOptions; exports.defaultResolveOptions = _chunkCPM55MMQcjs.defaultResolveOptions; exports.empty = _chunkSDGXLF4Gcjs.empty; exports.fromMap = _chunkSDGXLF4Gcjs.fromMap; exports.isArray = isArray; exports.isNull = isNull; exports.isObject = isObject; exports.isScalar = isScalar; exports.parse = _chunkCPM55MMQcjs.parse; exports.parseAsync = _chunkCPM55MMQcjs.parseAsync; exports.parseFile = _chunkCPM55MMQcjs.parseFile; exports.parseFileAsync = _chunkCPM55MMQcjs.parseFileAsync; exports.parseFileWithOptions = _chunkCPM55MMQcjs.parseFileWithOptions; exports.parseString = _chunkCPM55MMQcjs.parseString; exports.parseStringWithOptions = _chunkCPM55MMQcjs.parseStringWithOptions;
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
parseFileWithOptions,
|
|
9
9
|
parseString,
|
|
10
10
|
parseStringWithOptions
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-ITRXT66R.js";
|
|
12
12
|
import {
|
|
13
13
|
empty,
|
|
14
14
|
fromMap
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-SZ7MDLYZ.js";
|
|
16
16
|
import {
|
|
17
17
|
Config,
|
|
18
18
|
ConfigError,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
ResolveError,
|
|
23
23
|
coerceBoolean,
|
|
24
24
|
coerceNumber
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-5PV3HO2V.js";
|
|
26
26
|
|
|
27
27
|
// src/value.ts
|
|
28
28
|
function asString(v) {
|
package/dist/zod.cjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkCPM55MMQcjs = require('./chunk-CPM55MMQ.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkNHJJUTADcjs = require('./chunk-NHJJUTAD.cjs');
|
|
12
14
|
|
|
13
15
|
// src/zod.ts
|
|
14
16
|
var _zod2 = require('zod');
|
|
@@ -27,8 +29,11 @@ function parseValue(value, schema) {
|
|
|
27
29
|
let result;
|
|
28
30
|
try {
|
|
29
31
|
result = schema.safeParse(coerced);
|
|
30
|
-
} catch (
|
|
31
|
-
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err instanceof _zod2.z.core.$ZodAsyncError || _optionalChain([err, 'optionalAccess', _ => _.constructor, 'optionalAccess', _2 => _2.name]) === "$ZodAsyncError") {
|
|
34
|
+
throw new _zod2.z.ZodError(refused);
|
|
35
|
+
}
|
|
36
|
+
throw err;
|
|
32
37
|
}
|
|
33
38
|
if (result.success) throw new _zod2.z.ZodError(refused);
|
|
34
39
|
throw new _zod2.z.ZodError([...refused, ...withoutPrototypeKeyIssues(result.error.issues)]);
|
|
@@ -60,7 +65,7 @@ function dropPrototypeKeys(value, path, issues) {
|
|
|
60
65
|
}
|
|
61
66
|
return kept;
|
|
62
67
|
}
|
|
63
|
-
function unitMarker(what, read) {
|
|
68
|
+
function unitMarker(what, read, namesUnit) {
|
|
64
69
|
return _zod2.z.transform((input, ctx) => {
|
|
65
70
|
if (typeof input !== "string" && typeof input !== "number") {
|
|
66
71
|
ctx.issues.push({ code: "custom", message: `expected ${what}, got ${describeInput(input)}`, input });
|
|
@@ -68,16 +73,18 @@ function unitMarker(what, read) {
|
|
|
68
73
|
}
|
|
69
74
|
const text = typeof input === "string" ? input : String(input);
|
|
70
75
|
const reading = read(text);
|
|
76
|
+
if (reading.ok && namesUnit !== void 0 && (typeof input === "number" || !namesUnit(text))) {
|
|
77
|
+
pushProblem(ctx, what, "missing-unit", input);
|
|
78
|
+
return _zod2.z.NEVER;
|
|
79
|
+
}
|
|
71
80
|
if (reading.ok) return reading.value;
|
|
72
|
-
ctx.
|
|
73
|
-
code: "custom",
|
|
74
|
-
message: unitProblemMessage(what, reading.problem),
|
|
75
|
-
input,
|
|
76
|
-
params: { problem: reading.problem }
|
|
77
|
-
});
|
|
81
|
+
pushProblem(ctx, what, reading.problem, input);
|
|
78
82
|
return _zod2.z.NEVER;
|
|
79
83
|
});
|
|
80
84
|
}
|
|
85
|
+
function pushProblem(ctx, what, problem, input) {
|
|
86
|
+
ctx.issues.push({ code: "custom", message: unitProblemMessage(what, problem), input, params: { problem } });
|
|
87
|
+
}
|
|
81
88
|
function unitProblemMessage(what, problem) {
|
|
82
89
|
switch (problem) {
|
|
83
90
|
case "invalid":
|
|
@@ -86,6 +93,8 @@ function unitProblemMessage(what, problem) {
|
|
|
86
93
|
return `${what} must be non-negative`;
|
|
87
94
|
case "overflow":
|
|
88
95
|
return `${what} overflows the representable range`;
|
|
96
|
+
case "missing-unit":
|
|
97
|
+
return `${what} must name its unit`;
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
100
|
function describeInput(input) {
|
|
@@ -100,9 +109,10 @@ var hocon = {
|
|
|
100
109
|
* significant digits than a double holds can read differently: the getter
|
|
101
110
|
* reads its text, the marker its JS value (`1.0000000000000001` in `us`:
|
|
102
111
|
* 1000.0000000000001 through the getter, 1000 here).
|
|
112
|
+
* `options.requireUnit` refuses a value that does not name its unit (#233).
|
|
103
113
|
*/
|
|
104
|
-
duration(unit) {
|
|
105
|
-
return unitMarker("duration", (text) =>
|
|
114
|
+
duration(unit, options) {
|
|
115
|
+
return unitMarker("duration", (text) => _chunkNHJJUTADcjs.readDuration.call(void 0, text, unit), requireUnit(options, _chunkNHJJUTADcjs.namesMagnitudeUnit));
|
|
106
116
|
},
|
|
107
117
|
/**
|
|
108
118
|
* A byte size, read as {@link Config.getBytes} reads it (default unit `B`),
|
|
@@ -110,47 +120,52 @@ var hocon = {
|
|
|
110
120
|
* significant digits than a double holds can read differently: the getter
|
|
111
121
|
* reads its text, the marker its JS value (`1.99999999999999999`: 1 through
|
|
112
122
|
* the getter, 2 here).
|
|
123
|
+
* `options.requireUnit` refuses a value that does not name its unit (#233).
|
|
113
124
|
*/
|
|
114
|
-
bytes(unit) {
|
|
115
|
-
return unitMarker("byte size", (text) =>
|
|
125
|
+
bytes(unit, options) {
|
|
126
|
+
return unitMarker("byte size", (text) => _chunkNHJJUTADcjs.readBytes.call(void 0, text, unit), requireUnit(options, _chunkNHJJUTADcjs.namesMagnitudeUnit));
|
|
116
127
|
},
|
|
117
128
|
/**
|
|
118
129
|
* A calendar period, read as {@link Config.getPeriod} reads it (a bare
|
|
119
130
|
* integer is days), except that a number literal with a decimal point or in
|
|
120
131
|
* exponent form (`7.0`, `1e2`) can read differently: the getter refuses it,
|
|
121
132
|
* the marker reads the JS number.
|
|
133
|
+
* `options.requireUnit` refuses a value that does not name its unit (#233).
|
|
122
134
|
*/
|
|
123
|
-
period() {
|
|
124
|
-
return unitMarker("period",
|
|
135
|
+
period(options) {
|
|
136
|
+
return unitMarker("period", _chunkNHJJUTADcjs.readPeriod, requireUnit(options, _chunkNHJJUTADcjs.namesPeriodUnit));
|
|
125
137
|
}
|
|
126
138
|
};
|
|
139
|
+
function requireUnit(options, namesUnit) {
|
|
140
|
+
return _optionalChain([options, 'optionalAccess', _3 => _3.requireUnit]) === true ? namesUnit : void 0;
|
|
141
|
+
}
|
|
127
142
|
function getDefType(schema) {
|
|
128
143
|
const zod = schema._zod;
|
|
129
|
-
return _optionalChain([zod, 'optionalAccess',
|
|
144
|
+
return _optionalChain([zod, 'optionalAccess', _4 => _4.def, 'optionalAccess', _5 => _5.type]);
|
|
130
145
|
}
|
|
131
146
|
function getDef(schema) {
|
|
132
|
-
return _optionalChain([schema, 'access',
|
|
147
|
+
return _optionalChain([schema, 'access', _6 => _6._zod, 'optionalAccess', _7 => _7.def]);
|
|
133
148
|
}
|
|
134
149
|
function getInnerSchema(schema) {
|
|
135
|
-
const def = _optionalChain([schema, 'access',
|
|
136
|
-
return _nullishCoalesce(_optionalChain([def, 'optionalAccess',
|
|
150
|
+
const def = _optionalChain([schema, 'access', _8 => _8._zod, 'optionalAccess', _9 => _9.def]);
|
|
151
|
+
return _nullishCoalesce(_optionalChain([def, 'optionalAccess', _10 => _10.innerType]), () => ( _optionalChain([def, 'optionalAccess', _11 => _11.schema])));
|
|
137
152
|
}
|
|
138
153
|
function getObjectShape(schema) {
|
|
139
|
-
const shape = _optionalChain([schema, 'access',
|
|
154
|
+
const shape = _optionalChain([schema, 'access', _12 => _12._zod, 'optionalAccess', _13 => _13.def, 'optionalAccess', _14 => _14.shape]);
|
|
140
155
|
return typeof shape === "object" && shape !== null ? shape : void 0;
|
|
141
156
|
}
|
|
142
157
|
function getPropValues(schema) {
|
|
143
|
-
return _optionalChain([schema, 'access',
|
|
158
|
+
return _optionalChain([schema, 'access', _15 => _15._zod, 'optionalAccess', _16 => _16.propValues]);
|
|
144
159
|
}
|
|
145
160
|
function getArrayElement(schema) {
|
|
146
|
-
return _optionalChain([schema, 'access',
|
|
161
|
+
return _optionalChain([schema, 'access', _17 => _17._zod, 'optionalAccess', _18 => _18.def, 'optionalAccess', _19 => _19.element]);
|
|
147
162
|
}
|
|
148
163
|
function parseWithSchema(input, schema, opts) {
|
|
149
|
-
const config =
|
|
164
|
+
const config = _chunkCPM55MMQcjs.parse.call(void 0, input, opts);
|
|
150
165
|
return validate(config, schema);
|
|
151
166
|
}
|
|
152
167
|
function parseFileWithSchema(filePath, schema, opts) {
|
|
153
|
-
const config =
|
|
168
|
+
const config = _chunkCPM55MMQcjs.parseFile.call(void 0, filePath, opts);
|
|
154
169
|
return validate(config, schema);
|
|
155
170
|
}
|
|
156
171
|
function coerceValue(value, schema) {
|
|
@@ -160,18 +175,22 @@ function coerceValue(value, schema) {
|
|
|
160
175
|
switch (defType) {
|
|
161
176
|
case "boolean":
|
|
162
177
|
if (typeof value === "string") {
|
|
163
|
-
const coerced =
|
|
178
|
+
const coerced = _chunkNHJJUTADcjs.coerceBoolean.call(void 0, value);
|
|
164
179
|
return coerced !== void 0 ? coerced : value;
|
|
165
180
|
}
|
|
166
181
|
return value;
|
|
167
182
|
case "number":
|
|
168
183
|
if (typeof value === "string") {
|
|
169
|
-
const coerced =
|
|
184
|
+
const coerced = _chunkNHJJUTADcjs.coerceNumber.call(void 0, value);
|
|
170
185
|
return coerced !== void 0 ? coerced : value;
|
|
171
186
|
}
|
|
172
187
|
return value;
|
|
188
|
+
case "enum": {
|
|
189
|
+
const values = schema._zod.values;
|
|
190
|
+
return coerceToLiteral(value, values);
|
|
191
|
+
}
|
|
173
192
|
case "literal": {
|
|
174
|
-
const values = _optionalChain([getDef, 'call',
|
|
193
|
+
const values = _optionalChain([getDef, 'call', _20 => _20(schema), 'optionalAccess', _21 => _21.values]);
|
|
175
194
|
return values ? coerceToLiteral(value, new Set(values)) : value;
|
|
176
195
|
}
|
|
177
196
|
case "object": {
|
|
@@ -185,8 +204,23 @@ function coerceValue(value, schema) {
|
|
|
185
204
|
result[key] = coerceValue(obj[key], shape[key]);
|
|
186
205
|
}
|
|
187
206
|
}
|
|
207
|
+
const catchall = _optionalChain([getDef, 'call', _22 => _22(schema), 'optionalAccess', _23 => _23.catchall]);
|
|
208
|
+
if (catchall) {
|
|
209
|
+
for (const key of Object.keys(obj)) {
|
|
210
|
+
if (!Object.prototype.hasOwnProperty.call(shape, key)) result[key] = coerceValue(obj[key], catchall);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
188
213
|
return result;
|
|
189
214
|
}
|
|
215
|
+
case "intersection": {
|
|
216
|
+
if (accepts(schema, value)) return value;
|
|
217
|
+
const def = getDef(schema);
|
|
218
|
+
const forLeft = coerceValue(value, def.left);
|
|
219
|
+
if (accepts(schema, forLeft)) return forLeft;
|
|
220
|
+
const forRight = coerceValue(value, def.right);
|
|
221
|
+
if (accepts(schema, forRight)) return forRight;
|
|
222
|
+
return coerceValue(forLeft, def.right);
|
|
223
|
+
}
|
|
190
224
|
case "array": {
|
|
191
225
|
if (!Array.isArray(value)) return value;
|
|
192
226
|
const elementSchema = getArrayElement(schema);
|
|
@@ -195,7 +229,7 @@ function coerceValue(value, schema) {
|
|
|
195
229
|
}
|
|
196
230
|
case "record": {
|
|
197
231
|
if (typeof value !== "object" || Array.isArray(value)) return value;
|
|
198
|
-
const valueSchema = _optionalChain([getDef, 'call',
|
|
232
|
+
const valueSchema = _optionalChain([getDef, 'call', _24 => _24(schema), 'optionalAccess', _25 => _25.valueType]);
|
|
199
233
|
if (!valueSchema) return value;
|
|
200
234
|
const result = {};
|
|
201
235
|
for (const [key, item] of Object.entries(value)) result[key] = coerceValue(item, valueSchema);
|
|
@@ -204,8 +238,8 @@ function coerceValue(value, schema) {
|
|
|
204
238
|
case "tuple": {
|
|
205
239
|
if (!Array.isArray(value)) return value;
|
|
206
240
|
const def = getDef(schema);
|
|
207
|
-
const items = _nullishCoalesce(_optionalChain([def, 'optionalAccess',
|
|
208
|
-
const rest = _optionalChain([def, 'optionalAccess',
|
|
241
|
+
const items = _nullishCoalesce(_optionalChain([def, 'optionalAccess', _26 => _26.items]), () => ( []));
|
|
242
|
+
const rest = _optionalChain([def, 'optionalAccess', _27 => _27.rest]);
|
|
209
243
|
return value.map((item, i) => {
|
|
210
244
|
const itemSchema = i < items.length ? items[i] : rest;
|
|
211
245
|
return itemSchema ? coerceValue(item, itemSchema) : item;
|
|
@@ -214,11 +248,11 @@ function coerceValue(value, schema) {
|
|
|
214
248
|
case "union":
|
|
215
249
|
return coerceUnion(value, schema);
|
|
216
250
|
case "pipe": {
|
|
217
|
-
const input = _optionalChain([getDef, 'call',
|
|
251
|
+
const input = _optionalChain([getDef, 'call', _28 => _28(schema), 'optionalAccess', _29 => _29.in]);
|
|
218
252
|
return input ? coerceValue(value, input) : value;
|
|
219
253
|
}
|
|
220
254
|
case "lazy": {
|
|
221
|
-
const getter = _optionalChain([getDef, 'call',
|
|
255
|
+
const getter = _optionalChain([getDef, 'call', _30 => _30(schema), 'optionalAccess', _31 => _31.getter]);
|
|
222
256
|
return getter ? coerceValue(value, getter()) : value;
|
|
223
257
|
}
|
|
224
258
|
case "optional":
|
|
@@ -226,6 +260,7 @@ function coerceValue(value, schema) {
|
|
|
226
260
|
case "default":
|
|
227
261
|
case "prefault":
|
|
228
262
|
case "nonoptional":
|
|
263
|
+
case "success":
|
|
229
264
|
case "catch":
|
|
230
265
|
case "readonly": {
|
|
231
266
|
const inner = getInnerSchema(schema);
|
|
@@ -237,13 +272,13 @@ function coerceValue(value, schema) {
|
|
|
237
272
|
}
|
|
238
273
|
function coerceUnion(value, schema) {
|
|
239
274
|
const def = getDef(schema);
|
|
240
|
-
const options = _nullishCoalesce(_optionalChain([def, 'optionalAccess',
|
|
241
|
-
const discriminator = _optionalChain([def, 'optionalAccess',
|
|
275
|
+
const options = _nullishCoalesce(_optionalChain([def, 'optionalAccess', _32 => _32.options]), () => ( []));
|
|
276
|
+
const discriminator = _optionalChain([def, 'optionalAccess', _33 => _33.discriminator]);
|
|
242
277
|
if (discriminator !== void 0) {
|
|
243
278
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return value;
|
|
244
279
|
const tag = Object.prototype.hasOwnProperty.call(value, discriminator) ? value[discriminator] : void 0;
|
|
245
|
-
const tagsOf = (o) => _optionalChain([getPropValues, 'call',
|
|
246
|
-
const option = _nullishCoalesce(options.find((o) => _optionalChain([tagsOf, 'call',
|
|
280
|
+
const tagsOf = (o) => _optionalChain([getPropValues, 'call', _34 => _34(o), 'optionalAccess', _35 => _35[discriminator]]);
|
|
281
|
+
const option = _nullishCoalesce(options.find((o) => _optionalChain([tagsOf, 'call', _36 => _36(o), 'optionalAccess', _37 => _37.has, 'call', _38 => _38(tag)])), () => ( options.find((o) => {
|
|
247
282
|
const tags = tagsOf(o);
|
|
248
283
|
return tags !== void 0 && tags.has(coerceToLiteral(tag, tags));
|
|
249
284
|
})));
|
|
@@ -258,16 +293,16 @@ function coerceUnion(value, schema) {
|
|
|
258
293
|
}
|
|
259
294
|
function coerceToLiteral(value, literals) {
|
|
260
295
|
if (typeof value !== "string" || literals.has(value)) return value;
|
|
261
|
-
const n =
|
|
296
|
+
const n = _chunkNHJJUTADcjs.coerceNumber.call(void 0, value);
|
|
262
297
|
if (n !== void 0 && literals.has(n)) return n;
|
|
263
|
-
const b =
|
|
298
|
+
const b = _chunkNHJJUTADcjs.coerceBoolean.call(void 0, value);
|
|
264
299
|
if (b !== void 0 && literals.has(b)) return b;
|
|
265
300
|
return value;
|
|
266
301
|
}
|
|
267
302
|
function accepts(schema, value) {
|
|
268
303
|
try {
|
|
269
304
|
return schema.safeParse(value).success;
|
|
270
|
-
} catch (
|
|
305
|
+
} catch (e) {
|
|
271
306
|
return false;
|
|
272
307
|
}
|
|
273
308
|
}
|
package/dist/zod.d.cts
CHANGED
|
@@ -4,10 +4,12 @@ import { C as Config, D as DurationUnit, B as ByteUnit, b as Period, a as ParseO
|
|
|
4
4
|
/**
|
|
5
5
|
* The whole config, validated against `schema`. HOCON strings are coerced
|
|
6
6
|
* where the schema expects a number or a boolean (`"8080"` → 8080), through
|
|
7
|
-
* objects, arrays, records, tuples, unions,
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* objects (and their catchall), arrays, records, tuples, unions,
|
|
8
|
+
* intersections, pipes (by their input schema), lazy schemas, numeric literals
|
|
9
|
+
* and enums, and optional / nullable / default / prefault / nonoptional /
|
|
10
|
+
* success / catch / readonly wrappers; a union coerces by the option that
|
|
11
|
+
* takes the value (see the README). Unit values go through the {@link hocon}
|
|
12
|
+
* markers.
|
|
11
13
|
*
|
|
12
14
|
* An object key named `__proto__`, `constructor` or `prototype` anywhere in
|
|
13
15
|
* the value is refused with a `ZodError` issue at the object that holds it
|
|
@@ -34,6 +36,18 @@ declare function validate<T>(config: Config, schema: ZodType<T>): T;
|
|
|
34
36
|
* @throws `ZodError` when the value does not match the schema.
|
|
35
37
|
*/
|
|
36
38
|
declare function getValidated<T>(config: Config, path: string, schema: ZodType<T>): T;
|
|
39
|
+
/**
|
|
40
|
+
* Options for the {@link hocon} unit markers.
|
|
41
|
+
*/
|
|
42
|
+
interface UnitMarkerOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Refuse a value that does not name its unit: a number (`ttl = 30`) or a
|
|
45
|
+
* string of the number alone (`"30"`, what an environment variable gives),
|
|
46
|
+
* which would otherwise read in the default unit (milliseconds, bytes, days).
|
|
47
|
+
* `30s`, `"30 s"`, `64KiB`, `2w` read as before. Default `false` (#233).
|
|
48
|
+
*/
|
|
49
|
+
readonly requireUnit?: boolean;
|
|
50
|
+
}
|
|
37
51
|
/**
|
|
38
52
|
* Zod schema markers for HOCON unit values. Each reads the forms the matching
|
|
39
53
|
* Config getter reads and gives what the getter gives (a number in the
|
|
@@ -54,23 +68,26 @@ declare const hocon: {
|
|
|
54
68
|
* significant digits than a double holds can read differently: the getter
|
|
55
69
|
* reads its text, the marker its JS value (`1.0000000000000001` in `us`:
|
|
56
70
|
* 1000.0000000000001 through the getter, 1000 here).
|
|
71
|
+
* `options.requireUnit` refuses a value that does not name its unit (#233).
|
|
57
72
|
*/
|
|
58
|
-
duration(unit?: DurationUnit): ZodTransform<number, unknown>;
|
|
73
|
+
duration(unit?: DurationUnit, options?: UnitMarkerOptions): ZodTransform<number, unknown>;
|
|
59
74
|
/**
|
|
60
75
|
* A byte size, read as {@link Config.getBytes} reads it (default unit `B`),
|
|
61
76
|
* exponent forms included, except that a number literal with more
|
|
62
77
|
* significant digits than a double holds can read differently: the getter
|
|
63
78
|
* reads its text, the marker its JS value (`1.99999999999999999`: 1 through
|
|
64
79
|
* the getter, 2 here).
|
|
80
|
+
* `options.requireUnit` refuses a value that does not name its unit (#233).
|
|
65
81
|
*/
|
|
66
|
-
bytes(unit?: ByteUnit): ZodTransform<number, unknown>;
|
|
82
|
+
bytes(unit?: ByteUnit, options?: UnitMarkerOptions): ZodTransform<number, unknown>;
|
|
67
83
|
/**
|
|
68
84
|
* A calendar period, read as {@link Config.getPeriod} reads it (a bare
|
|
69
85
|
* integer is days), except that a number literal with a decimal point or in
|
|
70
86
|
* exponent form (`7.0`, `1e2`) can read differently: the getter refuses it,
|
|
71
87
|
* the marker reads the JS number.
|
|
88
|
+
* `options.requireUnit` refuses a value that does not name its unit (#233).
|
|
72
89
|
*/
|
|
73
|
-
period(): ZodTransform<Period, unknown>;
|
|
90
|
+
period(options?: UnitMarkerOptions): ZodTransform<Period, unknown>;
|
|
74
91
|
};
|
|
75
92
|
/**
|
|
76
93
|
* Parse a HOCON string and {@link validate} it.
|
|
@@ -89,4 +106,4 @@ declare function parseWithSchema<T>(input: string, schema: ZodType<T>, opts?: Pa
|
|
|
89
106
|
*/
|
|
90
107
|
declare function parseFileWithSchema<T>(filePath: string, schema: ZodType<T>, opts?: ParseOptions): T;
|
|
91
108
|
|
|
92
|
-
export { getValidated, hocon, parseFileWithSchema, parseWithSchema, validate };
|
|
109
|
+
export { type UnitMarkerOptions, getValidated, hocon, parseFileWithSchema, parseWithSchema, validate };
|