@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
package/README.ja.md
CHANGED
|
@@ -249,7 +249,7 @@ const app = validate(cfg, Schema)
|
|
|
249
249
|
const port = getValidated(cfg, 'server.port', z.number().int())
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
-
スキーマが数値や真偽値を求める位置では文字列を変換するので、`PORT=8081` のとき `port = ${?PORT}` は `z.number()` を通ります。変換はスキーマに沿って、object・array・record(各値)・tuple・union・pipe(入力側のスキーマ)・lazy と、optional / nullable / default / prefault / nonoptional / catch / readonly の各ラッパーの中まで届きます。数値や真偽値の literal
|
|
252
|
+
スキーマが数値や真偽値を求める位置では文字列を変換するので、`PORT=8081` のとき `port = ${?PORT}` は `z.number()` を通ります。変換はスキーマに沿って、object・array・record(各値)・tuple・union・pipe(入力側のスキーマ)・lazy・intersection(両側が受け入れる最初の形。元の値、片側向けの変換、両側向けの変換の順)・object の `catchall` と、optional / nullable / default / prefault / nonoptional / success / catch / readonly の各ラッパーの中まで届きます。数値や真偽値の literal と、数値の enum の値にも変換します(`z.literal(1)` や `z.enum({ A: 1 })` に対する `"1"`)。`z.discriminatedUnion` は discriminator が選ぶ option に従って変換します。それ以外の union は、値をそのまま受け入れる option があれば変換せず(`z.union([z.number(), z.string()])` では `"5"` は文字列のまま)、なければ変換後の値を受け入れる最初の option に従って変換します(`z.union([z.number(), z.literal('auto')])` では `"8081"` は 8081)。その option を探すために option を順に試すので、深く再帰する通常の union は検証が遅くなります。そこでは `z.discriminatedUnion` を使ってください。
|
|
253
253
|
|
|
254
254
|
HOCON の duration と byte size は文字列(`30m`、`64KiB`)なので、`z.number()` では通りません。`hocon.duration(unit?)` / `hocon.bytes(unit?)` マーカーは `getDuration()` / `getBytes()` と同じ規則で読み、指定した単位の数値を返します(既定は `ms` / `B`。単位のない数値は getter と同じ意味)。範囲や整数のチェックは、マーカーを数値スキーマに pipe して書きます:
|
|
255
255
|
|
|
@@ -265,6 +265,16 @@ const Session = z.object({
|
|
|
265
265
|
getValidated(cfg, 'session', Session) // { lifetime: 1800, maxBody: 65536 }
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
+
単位のない数値は、getter と同じく既定の単位で読みます(`lifetime = 30` は 30 ms)。単位をスキーマの契約にするには `{ requireUnit: true }` を渡します。数値や、数値だけの文字列(環境変数が渡す `"30"`)はキーのパス付きで拒否され(`duration must name its unit`、`params.problem` は `missing-unit`)、`30s`・`"30 s"`・`64KiB` はこれまでどおり読みます。`hocon.period({ requireUnit: true })` も、単位のない日数を同じように拒否します。
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
const Token = z.object({
|
|
272
|
+
ttl: hocon.duration('s', { requireUnit: true }).pipe(z.number().int().min(1).max(3600)),
|
|
273
|
+
})
|
|
274
|
+
// token { ttl = 30 } を getValidated(cfg, 'token', Token): ttl で ZodError、duration must name its unit
|
|
275
|
+
// token { ttl = 30s } を getValidated(cfg, 'token', Token): { ttl: 30 }
|
|
276
|
+
```
|
|
277
|
+
|
|
268
278
|
`hocon.period()` は `getPeriod()` と同じ規則で period を読み、`Period`(`{ years, months, days }`)を返します。制約はスキーマ側で refine します:
|
|
269
279
|
|
|
270
280
|
```ts
|
|
@@ -276,7 +286,7 @@ const Backup = z.object({
|
|
|
276
286
|
getValidated(cfg, 'backup', Backup) // { keep: { years: 0, months: 0, days: 14 } }
|
|
277
287
|
```
|
|
278
288
|
|
|
279
|
-
不正な duration / byte size / period は、キーのパス付きのバリデーションエラーになります。issue の message は問題だけを示し、値は含めません(`not a duration`、`byte size must be non-negative`)。誤ったキーに置かれたシークレットがログに出ないようにするためです。`params.problem` は `invalid`・`negative`・`overflow`
|
|
289
|
+
不正な duration / byte size / period は、キーのパス付きのバリデーションエラーになります。issue の message は問題だけを示し、値は含めません(`not a duration`、`byte size must be non-negative`)。誤ったキーに置かれたシークレットがログに出ないようにするためです。`params.problem` は `invalid`・`negative`・`overflow`(`requireUnit` のときは `missing-unit` も)のいずれかで、値は Zod に input の報告を求めたときだけ issue の `input` に入ります。マーカーは普通の Zod スキーマなので、`validate`・`getValidated`・`parseWithSchema`・`parseFileWithSchema` をはじめ、Zod が実行するところならどこでも使えます。指数表記(`1e3`、`"1.5e2s"`)は getter もマーカーも読みます。ただしマーカーは数値を JavaScript の値として読むため、double の精度を超える桁数の数値リテラルは、リテラルの文字列を正確に読む getter と結果が異なることがあります(`1.99999999999999999` B は `getBytes()` では 1、マーカーでは 2)。period のマーカーは、小数点や指数を含むリテラル(`7.0`、`1e2`)も整数として読みます(`getPeriod()` は拒否します)。単位付きで書けば(`30s`、`7d`)どちらの差も出ません。
|
|
280
290
|
|
|
281
291
|
未解決の Config(`resolveSubstitutions: false` でパースしたもの、`resolve()` 前のフォールバックの重なり、または何かが残った `resolve({ allowUnresolved: true })` の結果)に対しては、`validate` は保留中の値が欠けたツリーを検証するのではなく、getter と同じく `NotResolvedError` を投げます。`getValidated` は、値が未解決のパスでは `NotResolvedError` を投げ、解決済みのパスなら検証します。先に `resolve()` を呼んでください。
|
|
282
292
|
|
package/README.md
CHANGED
|
@@ -250,7 +250,7 @@ const app = validate(cfg, Schema)
|
|
|
250
250
|
const port = getValidated(cfg, 'server.port', z.number().int())
|
|
251
251
|
```
|
|
252
252
|
|
|
253
|
-
A string is coerced where the schema expects a number or a boolean, so `port = ${?PORT}` with `PORT=8081` validates against `z.number()`. The coercion follows the schema through objects, arrays, records (each value), tuples, unions, pipes (by the input schema), lazy schemas and the optional / nullable / default / prefault / nonoptional / catch / readonly wrappers, and turns a string into a number or boolean literal (`"1"` for `z.literal(1)`
|
|
253
|
+
A string is coerced where the schema expects a number or a boolean, so `port = ${?PORT}` with `PORT=8081` validates against `z.number()`. The coercion follows the schema through objects, arrays, records (each value), tuples, unions, pipes (by the input schema), lazy schemas, intersections (the first form both sides accept: as it is, coerced for one side, or for both), an object's `catchall` and the optional / nullable / default / prefault / nonoptional / success / catch / readonly wrappers, and turns a string into a number or boolean literal or a numeric enum value (`"1"` for `z.literal(1)` or `z.enum({ A: 1 })`). A `z.discriminatedUnion` coerces by the option the discriminator picks. Any other union takes the value as it is when an option accepts it, so `z.union([z.number(), z.string()])` keeps `"5"` a string, and coerces it otherwise, by the first option that accepts the coerced value (`z.union([z.number(), z.literal('auto')])` reads `"8081"` as 8081). Finding that option tries the options in turn, so a deeply recursive plain union validates slowly; prefer `z.discriminatedUnion` there.
|
|
254
254
|
|
|
255
255
|
Durations and byte sizes are strings in HOCON (`30m`, `64KiB`), so `z.number()` refuses them. The `hocon.duration(unit?)` and `hocon.bytes(unit?)` markers read them with the same rules as `getDuration()` / `getBytes()` and give a number in the requested unit (default `ms` / `B`; a plain number keeps the getters' meaning). Pipe the marker into a number schema for range and integer checks:
|
|
256
256
|
|
|
@@ -266,6 +266,16 @@ const Session = z.object({
|
|
|
266
266
|
getValidated(cfg, 'session', Session) // { lifetime: 1800, maxBody: 65536 }
|
|
267
267
|
```
|
|
268
268
|
|
|
269
|
+
A bare number reads in the default unit (`lifetime = 30` is 30 ms), as the getters read it. To make the unit part of the schema's contract, pass `{ requireUnit: true }`: a number or a string of the number alone (`"30"`, what an environment variable gives) is then refused with the key's path (`duration must name its unit`, `params.problem` `missing-unit`), and `30s`, `"30 s"` or `64KiB` read as before. `hocon.period({ requireUnit: true })` refuses a bare number of days the same way.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
const Token = z.object({
|
|
273
|
+
ttl: hocon.duration('s', { requireUnit: true }).pipe(z.number().int().min(1).max(3600)),
|
|
274
|
+
})
|
|
275
|
+
// getValidated(cfg, 'token', Token) with token { ttl = 30 }: ZodError at ttl, duration must name its unit
|
|
276
|
+
// getValidated(cfg, 'token', Token) with token { ttl = 30s }: { ttl: 30 }
|
|
277
|
+
```
|
|
278
|
+
|
|
269
279
|
`hocon.period()` reads a period the way `getPeriod()` does and gives a `Period` (`{ years, months, days }`); refine it in the schema:
|
|
270
280
|
|
|
271
281
|
```ts
|
|
@@ -277,7 +287,7 @@ const Backup = z.object({
|
|
|
277
287
|
getValidated(cfg, 'backup', Backup) // { keep: { years: 0, months: 0, days: 14 } }
|
|
278
288
|
```
|
|
279
289
|
|
|
280
|
-
An invalid duration, size or period fails validation with the key's path. The issue message names the problem, not the value (`not a duration`, `byte size must be non-negative`), so a secret set under the wrong key does not reach the logs; `params.problem` is `invalid`, `negative` or `overflow
|
|
290
|
+
An invalid duration, size or period fails validation with the key's path. The issue message names the problem, not the value (`not a duration`, `byte size must be non-negative`), so a secret set under the wrong key does not reach the logs; `params.problem` is `invalid`, `negative` or `overflow` (or `missing-unit` with `requireUnit`), and the value is in the issue's `input` only when Zod is asked to report input. The markers are ordinary Zod schemas, so they work in `validate`, `getValidated`, `parseWithSchema`, `parseFileWithSchema` and anywhere else Zod runs them. Getters and markers both read exponent forms (`1e3`, `"1.5e2s"`). A marker reads a number through its JavaScript value, though, so a number literal with more significant digits than a double holds can read differently from the getters, which read the literal's text exactly (`1.99999999999999999` B is 1 through `getBytes()`, 2 through the marker); a period marker also reads a literal with a decimal point or an exponent (`7.0`, `1e2`) as an integer, which `getPeriod()` refuses. Write unit values with a unit (`30s`, `7d`) to avoid both.
|
|
281
291
|
|
|
282
292
|
On an unresolved Config (parsed with `resolveSubstitutions: false`, a fallback stack not yet `resolve()`d, or the result of `resolve({ allowUnresolved: true })` with something left), `validate` throws `NotResolvedError`, as the getters do, rather than validating a tree with the pending values missing; `getValidated` throws it for a path whose value is unresolved and validates a resolved one. Call `resolve()` first.
|
|
283
293
|
|
package/dist/adapters/env.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
-
var
|
|
3
|
+
var _chunkSDGXLF4Gcjs = require('../chunk-SDGXLF4G.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -8,14 +8,14 @@ var _chunkPCAMDXJ4cjs = require('../chunk-PCAMDXJ4.cjs');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkNHJJUTADcjs = require('../chunk-NHJJUTAD.cjs');
|
|
12
12
|
|
|
13
13
|
// src/adapters/env.ts
|
|
14
14
|
var SEPARATOR = "__";
|
|
15
15
|
function loadEnv(opts = {}) {
|
|
16
16
|
const prefix = _nullishCoalesce(opts.prefix, () => ( ""));
|
|
17
17
|
if (prefix === "") {
|
|
18
|
-
throw new (0,
|
|
18
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
19
19
|
"loadEnv: a prefix is required when mounting the environment (spec F1.1)",
|
|
20
20
|
""
|
|
21
21
|
);
|
|
@@ -29,44 +29,44 @@ function loadEnv(opts = {}) {
|
|
|
29
29
|
const value = source[name];
|
|
30
30
|
if (value === void 0) continue;
|
|
31
31
|
const path = toPath(name.slice(prefix.length));
|
|
32
|
-
const key =
|
|
32
|
+
const key = _chunkNHJJUTADcjs.pathKey.call(void 0, path);
|
|
33
33
|
const prev = seen.get(key);
|
|
34
34
|
if (prev !== void 0) {
|
|
35
|
-
throw new (0,
|
|
35
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(`loadEnv: ${prev} and ${name} both map to "${path.join(".")}"`, path.join("."));
|
|
36
36
|
}
|
|
37
37
|
seen.set(key, name);
|
|
38
38
|
pairs.push([path, value]);
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return _chunkSDGXLF4Gcjs.fromMap.call(void 0, _chunkNHJJUTADcjs.nestPairs.call(void 0, pairs), _nullishCoalesce(opts.originDescription, () => ( "environment variables")));
|
|
41
41
|
}
|
|
42
42
|
function parseDotEnv(input, opts = {}) {
|
|
43
43
|
const origin = _nullishCoalesce(opts.originDescription, () => ( ".env"));
|
|
44
44
|
const prefix = _nullishCoalesce(opts.prefix, () => ( ""));
|
|
45
45
|
const pairs = [];
|
|
46
|
-
const lines =
|
|
46
|
+
const lines = _chunkNHJJUTADcjs.stripBom.call(void 0, input).replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
|
|
47
47
|
for (let i = 0; i < lines.length; i++) {
|
|
48
48
|
const raw = (_nullishCoalesce(lines[i], () => ( ""))).trim();
|
|
49
49
|
if (raw === "" || raw.startsWith("#")) continue;
|
|
50
50
|
const line = stripExport(raw);
|
|
51
51
|
const eq = line.indexOf("=");
|
|
52
|
-
if (eq === -1) throw new (0,
|
|
52
|
+
if (eq === -1) throw new (0, _chunkNHJJUTADcjs.ConfigError)(`${origin}:${i + 1}: expected NAME=value`, "");
|
|
53
53
|
const name = line.slice(0, eq).trim();
|
|
54
|
-
if (name === "") throw new (0,
|
|
54
|
+
if (name === "") throw new (0, _chunkNHJJUTADcjs.ConfigError)(`${origin}:${i + 1}: empty variable name`, "");
|
|
55
55
|
if (!name.startsWith(prefix)) continue;
|
|
56
56
|
checkName(name, origin, i + 1);
|
|
57
57
|
const value = dotEnvValue(line.slice(eq + 1).replace(/^[ \t]+/, ""), origin, i + 1, name);
|
|
58
58
|
pairs.push([toPath(name.slice(prefix.length)), value]);
|
|
59
59
|
}
|
|
60
|
-
return
|
|
60
|
+
return _chunkSDGXLF4Gcjs.fromMap.call(void 0, _chunkNHJJUTADcjs.nestPairs.call(void 0, pairs), origin);
|
|
61
61
|
}
|
|
62
62
|
function toPath(name) {
|
|
63
63
|
const segs = name.split(SEPARATOR).map(asciiLower);
|
|
64
64
|
if (segs.some((s) => s === "")) {
|
|
65
|
-
throw new (0,
|
|
65
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(`env: "${name}" produces an empty path segment`, name);
|
|
66
66
|
}
|
|
67
|
-
if (
|
|
68
|
-
throw new (0,
|
|
69
|
-
`env: "${name}" maps to a path ${segs.length} segments deep, over the limit of ${
|
|
67
|
+
if (_chunkNHJJUTADcjs.tooDeep.call(void 0, segs.length)) {
|
|
68
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
69
|
+
`env: "${name}" maps to a path ${segs.length} segments deep, over the limit of ${_chunkNHJJUTADcjs.MAX_PATH_SEGMENTS}`,
|
|
70
70
|
name
|
|
71
71
|
);
|
|
72
72
|
}
|
|
@@ -77,7 +77,7 @@ function asciiLower(s) {
|
|
|
77
77
|
}
|
|
78
78
|
function dotEnvValue(v, origin, line, name) {
|
|
79
79
|
const fail = (msg) => {
|
|
80
|
-
throw new (0,
|
|
80
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(`${origin}:${line}: ${name}: ${msg}`, name);
|
|
81
81
|
};
|
|
82
82
|
if (v.startsWith("'")) {
|
|
83
83
|
const end = v.indexOf("'", 1);
|
|
@@ -123,7 +123,7 @@ function checkName(name, origin, line) {
|
|
|
123
123
|
const bad = /\p{White_Space}|#/u.exec(name);
|
|
124
124
|
if (bad) {
|
|
125
125
|
const what = bad[0] === "#" ? "'#'" : "whitespace";
|
|
126
|
-
throw new (0,
|
|
126
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
127
127
|
`${origin}:${line}: variable name "${name}" contains ${what}; the line is not NAME=value (spec F1.7)`,
|
|
128
128
|
name
|
|
129
129
|
);
|
package/dist/adapters/env.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fromMap
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SZ7MDLYZ.js";
|
|
4
4
|
import {
|
|
5
5
|
ConfigError,
|
|
6
6
|
MAX_PATH_SEGMENTS,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
pathKey,
|
|
9
9
|
stripBom,
|
|
10
10
|
tooDeep
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-5PV3HO2V.js";
|
|
12
12
|
|
|
13
13
|
// src/adapters/env.ts
|
|
14
14
|
var SEPARATOR = "__";
|
package/dist/adapters/json5.cjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSDGXLF4Gcjs = require('../chunk-SDGXLF4G.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkNHJJUTADcjs = require('../chunk-NHJJUTAD.cjs');
|
|
10
10
|
|
|
11
11
|
// src/adapters/json5.ts
|
|
12
12
|
function parseJson5(input, originDescription) {
|
|
13
|
-
const p = new Parser(
|
|
14
|
-
const doc =
|
|
13
|
+
const p = new Parser(_chunkNHJJUTADcjs.stripBom.call(void 0, input), originDescription);
|
|
14
|
+
const doc = _chunkNHJJUTADcjs.guardStackDepth.call(void 0,
|
|
15
15
|
() => p.parseDocument(),
|
|
16
|
-
(msg) =>
|
|
16
|
+
(msg) => _chunkNHJJUTADcjs.depthError.call(void 0, `json5: ${describe(originDescription)}: ${msg}`)
|
|
17
17
|
);
|
|
18
18
|
if (doc === null || typeof doc !== "object" || Array.isArray(doc)) {
|
|
19
|
-
throw new (0,
|
|
19
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
20
20
|
`json5: ${describe(originDescription)}: document root is ${rootKind(doc)}, but a config root must be an object (spec F0.3)`,
|
|
21
21
|
""
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return _chunkSDGXLF4Gcjs.fromMap.call(void 0, doc, originDescription);
|
|
25
25
|
}
|
|
26
26
|
function describe(origin) {
|
|
27
27
|
return origin === void 0 || origin === "" ? "document" : origin;
|
|
@@ -95,7 +95,7 @@ var Parser = class {
|
|
|
95
95
|
}
|
|
96
96
|
errf(msg) {
|
|
97
97
|
const col = [...this.src.slice(this.lineAt, this.pos)].length + 1;
|
|
98
|
-
return new (0,
|
|
98
|
+
return new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
99
99
|
`json5: ${describe(this.origin)}: line ${this.line + 1} col ${col}: ${msg}`,
|
|
100
100
|
""
|
|
101
101
|
);
|
package/dist/adapters/json5.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fromMap
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SZ7MDLYZ.js";
|
|
4
4
|
import {
|
|
5
5
|
ConfigError,
|
|
6
6
|
depthError,
|
|
7
7
|
guardStackDepth,
|
|
8
8
|
stripBom
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-5PV3HO2V.js";
|
|
10
10
|
|
|
11
11
|
// src/adapters/json5.ts
|
|
12
12
|
function parseJson5(input, originDescription) {
|
package/dist/adapters/jsonc.cjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSDGXLF4Gcjs = require('../chunk-SDGXLF4G.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkNHJJUTADcjs = require('../chunk-NHJJUTAD.cjs');
|
|
10
10
|
|
|
11
11
|
// src/adapters/jsonc.ts
|
|
12
12
|
function parseJsonc(input, originDescription) {
|
|
13
|
-
const doc =
|
|
14
|
-
() => JSON.parse(stripTrailingCommas(stripComments(
|
|
15
|
-
(msg) =>
|
|
13
|
+
const doc = _chunkNHJJUTADcjs.guardStackDepth.call(void 0,
|
|
14
|
+
() => JSON.parse(stripTrailingCommas(stripComments(_chunkNHJJUTADcjs.stripBom.call(void 0, input))), bigIntReviver),
|
|
15
|
+
(msg) => _chunkNHJJUTADcjs.depthError.call(void 0, `jsonc: ${msg}`)
|
|
16
16
|
);
|
|
17
17
|
if (doc === null || typeof doc !== "object" || Array.isArray(doc)) {
|
|
18
|
-
throw new (0,
|
|
18
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
19
19
|
`jsonc: document root is ${Array.isArray(doc) ? "an array" : typeof doc}, but a config root must be an object (spec F0.3)`,
|
|
20
20
|
""
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return _chunkSDGXLF4Gcjs.fromMap.call(void 0, doc, originDescription);
|
|
24
24
|
}
|
|
25
25
|
function isIntegerLiteral(source) {
|
|
26
26
|
return !/[.eE]/.test(source);
|
|
@@ -38,7 +38,7 @@ function bigIntReviver(key, value, context) {
|
|
|
38
38
|
const source = _optionalChain([context, 'optionalAccess', _2 => _2.source]);
|
|
39
39
|
if (source === void 0) {
|
|
40
40
|
if (!Number.isInteger(value)) return value;
|
|
41
|
-
throw new (0,
|
|
41
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
42
42
|
`jsonc: the integer at "${key || "<root>"}" needs more precision than a JS number holds, and this runtime does not expose JSON.parse source text (${HAS_SOURCE_TEXT_ACCESS ? "unexpected \u2014 the capability probe said otherwise" : "requires Node >= 22 or an engine with JSON.parse source access"}), so it cannot be read losslessly (spec F0.5)`,
|
|
43
43
|
key
|
|
44
44
|
);
|
|
@@ -82,7 +82,7 @@ function stripComments(src) {
|
|
|
82
82
|
}
|
|
83
83
|
if (c === "/" && src[i + 1] === "*") {
|
|
84
84
|
const end = src.indexOf("*/", i + 2);
|
|
85
|
-
if (end === -1) throw new (0,
|
|
85
|
+
if (end === -1) throw new (0, _chunkNHJJUTADcjs.ConfigError)("jsonc: unterminated block comment", "");
|
|
86
86
|
out += lineBreaksOf(src.slice(i, end + 2)) || " ";
|
|
87
87
|
i = end + 2;
|
|
88
88
|
continue;
|
|
@@ -97,7 +97,7 @@ function endOfString(src, i) {
|
|
|
97
97
|
if (src[j] === "\\") j++;
|
|
98
98
|
else if (src[j] === '"') return j + 1;
|
|
99
99
|
}
|
|
100
|
-
throw new (0,
|
|
100
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)("jsonc: unterminated string literal", "");
|
|
101
101
|
}
|
|
102
102
|
function stripTrailingCommas(src) {
|
|
103
103
|
let out = "";
|
package/dist/adapters/jsonc.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fromMap
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SZ7MDLYZ.js";
|
|
4
4
|
import {
|
|
5
5
|
ConfigError,
|
|
6
6
|
depthError,
|
|
7
7
|
guardStackDepth,
|
|
8
8
|
stripBom
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-5PV3HO2V.js";
|
|
10
10
|
|
|
11
11
|
// src/adapters/jsonc.ts
|
|
12
12
|
function parseJsonc(input, originDescription) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSDGXLF4Gcjs = require('../chunk-SDGXLF4G.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkNHJJUTADcjs = require('../chunk-NHJJUTAD.cjs');
|
|
7
7
|
|
|
8
8
|
// src/adapters/properties.ts
|
|
9
9
|
function parsePropertiesConfig(input, originDescription) {
|
|
10
|
-
return
|
|
10
|
+
return _chunkSDGXLF4Gcjs.fromMap.call(void 0, _chunkNHJJUTADcjs.parseProperties.call(void 0, input), originDescription);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fromMap
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SZ7MDLYZ.js";
|
|
4
4
|
import {
|
|
5
5
|
parseProperties
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-5PV3HO2V.js";
|
|
7
7
|
|
|
8
8
|
// src/adapters/properties.ts
|
|
9
9
|
function parsePropertiesConfig(input, originDescription) {
|
package/dist/adapters/toml.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSDGXLF4Gcjs = require('../chunk-SDGXLF4G.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkNHJJUTADcjs = require('../chunk-NHJJUTAD.cjs');
|
|
10
10
|
|
|
11
11
|
// src/adapters/toml.ts
|
|
12
12
|
var _smoltoml = require('smol-toml');
|
|
13
13
|
function parseTomlConfig(input, originDescription) {
|
|
14
|
-
const doc = _smoltoml.parse.call(void 0,
|
|
15
|
-
return
|
|
16
|
-
|
|
14
|
+
const doc = _smoltoml.parse.call(void 0, _chunkNHJJUTADcjs.stripBom.call(void 0, input));
|
|
15
|
+
return _chunkSDGXLF4Gcjs.fromMap.call(void 0,
|
|
16
|
+
_chunkNHJJUTADcjs.guardStackDepth.call(void 0,
|
|
17
17
|
() => convert(doc, ""),
|
|
18
|
-
(msg) =>
|
|
18
|
+
(msg) => _chunkNHJJUTADcjs.depthError.call(void 0, `toml: ${msg}`)
|
|
19
19
|
),
|
|
20
20
|
originDescription
|
|
21
21
|
);
|
|
@@ -33,7 +33,7 @@ function convert(v, atPath) {
|
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
if (typeof v === "number" && !Number.isFinite(v)) {
|
|
36
|
-
throw new (0,
|
|
36
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
37
37
|
`toml: ${v} at "${atPath}" is not representable in HOCON (spec F0.6)`,
|
|
38
38
|
atPath
|
|
39
39
|
);
|
package/dist/adapters/toml.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fromMap
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SZ7MDLYZ.js";
|
|
4
4
|
import {
|
|
5
5
|
ConfigError,
|
|
6
6
|
depthError,
|
|
7
7
|
guardStackDepth,
|
|
8
8
|
stripBom
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-5PV3HO2V.js";
|
|
10
10
|
|
|
11
11
|
// src/adapters/toml.ts
|
|
12
12
|
import { parse as parseToml } from "smol-toml";
|
package/dist/adapters/yaml.cjs
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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
|
-
var
|
|
3
|
+
var _chunkSDGXLF4Gcjs = require('../chunk-SDGXLF4G.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkNHJJUTADcjs = require('../chunk-NHJJUTAD.cjs');
|
|
10
10
|
|
|
11
11
|
// src/adapters/yaml.ts
|
|
12
12
|
var _yaml = require('yaml'); var _yaml2 = _interopRequireDefault(_yaml);
|
|
13
13
|
function parseYaml(input, originDescription) {
|
|
14
|
-
const docs = _yaml2.default.parseAllDocuments(
|
|
14
|
+
const docs = _yaml2.default.parseAllDocuments(_chunkNHJJUTADcjs.stripBom.call(void 0, input), { version: "1.2", merge: true, intAsBigInt: true });
|
|
15
15
|
if (docs.length > 1) {
|
|
16
|
-
throw new (0,
|
|
16
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
17
17
|
"yaml: multi-document streams are not supported (spec F5.7); a config is one document",
|
|
18
18
|
""
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
const doc = docs[0];
|
|
22
|
-
if (doc === void 0) return
|
|
22
|
+
if (doc === void 0) return _chunkSDGXLF4Gcjs.fromMap.call(void 0, {}, originDescription);
|
|
23
23
|
if (doc.errors.length > 0) {
|
|
24
|
-
throw new (0,
|
|
24
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(`yaml: ${_nullishCoalesce(_optionalChain([doc, 'access', _ => _.errors, 'access', _2 => _2[0], 'optionalAccess', _3 => _3.message]), () => ( "parse error"))}`, "");
|
|
25
25
|
}
|
|
26
26
|
return fromYamlValue(doc.toJS({ mapAsMap: true }), originDescription);
|
|
27
27
|
}
|
|
28
28
|
function fromYamlValue(value, originDescription) {
|
|
29
|
-
if (value === null || value === void 0) return
|
|
30
|
-
const normalized =
|
|
29
|
+
if (value === null || value === void 0) return _chunkSDGXLF4Gcjs.fromMap.call(void 0, {}, originDescription);
|
|
30
|
+
const normalized = _chunkNHJJUTADcjs.guardStackDepth.call(void 0,
|
|
31
31
|
() => convert(value, ""),
|
|
32
|
-
(msg) =>
|
|
32
|
+
(msg) => _chunkNHJJUTADcjs.depthError.call(void 0, `yaml: ${msg}`)
|
|
33
33
|
);
|
|
34
34
|
if (typeof normalized !== "object" || normalized === null || Array.isArray(normalized)) {
|
|
35
|
-
throw new (0,
|
|
35
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
36
36
|
`yaml: document root is ${Array.isArray(normalized) ? "an array" : typeof normalized}, but a config root must be an object (spec F0.3)`,
|
|
37
37
|
""
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return _chunkSDGXLF4Gcjs.fromMap.call(void 0, normalized, originDescription);
|
|
41
41
|
}
|
|
42
42
|
function convert(v, atPath) {
|
|
43
43
|
if (Array.isArray(v)) return v.map((e, i) => convert(e, `${atPath}[${i}]`));
|
|
@@ -49,14 +49,14 @@ function convert(v, atPath) {
|
|
|
49
49
|
const seen = /* @__PURE__ */ new Map();
|
|
50
50
|
for (const [k, e] of v) {
|
|
51
51
|
if (k !== null && typeof k === "object") {
|
|
52
|
-
throw new (0,
|
|
52
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
53
53
|
`yaml: a collection key at "${atPath}" is not usable as an object key (spec F5.3)`,
|
|
54
54
|
atPath
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
const key = String(k);
|
|
58
58
|
if (seen.has(key)) {
|
|
59
|
-
throw new (0,
|
|
59
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
60
60
|
`yaml: sibling mapping keys ${keyForm(seen.get(key))} and ${keyForm(k)} both give the key "${key}"${atPath === "" ? "" : ` at "${atPath}"`}; rename one of them, because one of the two values would otherwise be lost. Quoting a non-string key helps only where that changes the key text, as 0x10 does and 1 does not (spec F5.3)`,
|
|
61
61
|
atPath
|
|
62
62
|
);
|
|
@@ -77,7 +77,7 @@ function convert(v, atPath) {
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
if (typeof v === "number" && !Number.isFinite(v)) {
|
|
80
|
-
throw new (0,
|
|
80
|
+
throw new (0, _chunkNHJJUTADcjs.ConfigError)(
|
|
81
81
|
`yaml: ${v} at "${atPath}" is not representable in HOCON (spec F0.6)`,
|
|
82
82
|
atPath
|
|
83
83
|
);
|
package/dist/adapters/yaml.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fromMap
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SZ7MDLYZ.js";
|
|
4
4
|
import {
|
|
5
5
|
ConfigError,
|
|
6
6
|
depthError,
|
|
7
7
|
guardStackDepth,
|
|
8
8
|
stripBom
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-5PV3HO2V.js";
|
|
10
10
|
|
|
11
11
|
// src/adapters/yaml.ts
|
|
12
12
|
import YAML from "yaml";
|
|
@@ -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" };
|
|
@@ -3775,6 +3786,8 @@ export {
|
|
|
3775
3786
|
coerceNumber,
|
|
3776
3787
|
readDuration,
|
|
3777
3788
|
readBytes,
|
|
3789
|
+
namesMagnitudeUnit,
|
|
3790
|
+
namesPeriodUnit,
|
|
3778
3791
|
readPeriod,
|
|
3779
3792
|
ParseError,
|
|
3780
3793
|
ResolveError,
|