@o3co/ts.hocon 1.7.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{config-DCSLXkNY.d.cts → config-D27s3_aG.d.cts} +68 -1
- package/dist/{config-DCSLXkNY.d.ts → config-D27s3_aG.d.ts} +68 -1
- package/dist/index.cjs +73 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +64 -0
- package/dist/zod.cjs +26 -0
- package/dist/zod.d.cts +1 -1
- package/dist/zod.d.ts +1 -1
- package/dist/zod.js +26 -0
- package/package.json +1 -1
|
@@ -13,6 +13,59 @@ type HoconValue = {
|
|
|
13
13
|
raw: string;
|
|
14
14
|
valueType: ScalarValueType;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Deeply-immutable view of a {@link HoconValue}. `Config.getValue` returns this
|
|
18
|
+
* so callers cannot mutate the parsed configuration tree (the live nodes are
|
|
19
|
+
* shared, not cloned). `Map`/array containers become `ReadonlyMap`/`readonly[]`
|
|
20
|
+
* recursively, so `.set` / `.push` / element assignment are compile errors.
|
|
21
|
+
*
|
|
22
|
+
* `HoconValue` is structurally assignable to `ReadonlyHoconValue`, so internal
|
|
23
|
+
* code holding a mutable node can return it here, and the accessor functions
|
|
24
|
+
* below accept both forms.
|
|
25
|
+
*/
|
|
26
|
+
type ReadonlyHoconValue = {
|
|
27
|
+
readonly kind: 'object';
|
|
28
|
+
readonly fields: ReadonlyMap<string, ReadonlyHoconValue>;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'array';
|
|
31
|
+
readonly items: readonly ReadonlyHoconValue[];
|
|
32
|
+
} | {
|
|
33
|
+
readonly kind: 'scalar';
|
|
34
|
+
readonly raw: string;
|
|
35
|
+
readonly valueType: ScalarValueType;
|
|
36
|
+
};
|
|
37
|
+
/** Scalar string only (strict): non-string scalars and containers → undefined. */
|
|
38
|
+
declare function asString(v: ReadonlyHoconValue): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Scalar coerced to a number via {@link coerceNumber} (lenient, matching the
|
|
41
|
+
* `getNumber` getter: a numeric-looking string scalar coerces too). TS has a
|
|
42
|
+
* single `number` type, so this unifies rs's `as_i64` + `as_f64`.
|
|
43
|
+
*/
|
|
44
|
+
declare function asNumber(v: ReadonlyHoconValue): number | undefined;
|
|
45
|
+
/** Scalar coerced to a boolean via {@link coerceBoolean} (true/yes/on, false/no/off). */
|
|
46
|
+
declare function asBoolean(v: ReadonlyHoconValue): boolean | undefined;
|
|
47
|
+
/** The object's fields, or undefined if not an object. */
|
|
48
|
+
declare function asObject(v: ReadonlyHoconValue): ReadonlyMap<string, ReadonlyHoconValue> | undefined;
|
|
49
|
+
/** The array's items, or undefined if not an array. */
|
|
50
|
+
declare function asArray(v: ReadonlyHoconValue): readonly ReadonlyHoconValue[] | undefined;
|
|
51
|
+
/** Type guard: narrows to the object variant. */
|
|
52
|
+
declare function isObject(v: ReadonlyHoconValue): v is {
|
|
53
|
+
readonly kind: 'object';
|
|
54
|
+
readonly fields: ReadonlyMap<string, ReadonlyHoconValue>;
|
|
55
|
+
};
|
|
56
|
+
/** Type guard: narrows to the array variant. */
|
|
57
|
+
declare function isArray(v: ReadonlyHoconValue): v is {
|
|
58
|
+
readonly kind: 'array';
|
|
59
|
+
readonly items: readonly ReadonlyHoconValue[];
|
|
60
|
+
};
|
|
61
|
+
/** Type guard: narrows to the scalar variant. */
|
|
62
|
+
declare function isScalar(v: ReadonlyHoconValue): v is {
|
|
63
|
+
readonly kind: 'scalar';
|
|
64
|
+
readonly raw: string;
|
|
65
|
+
readonly valueType: ScalarValueType;
|
|
66
|
+
};
|
|
67
|
+
/** True for a null scalar. */
|
|
68
|
+
declare function isNull(v: ReadonlyHoconValue): boolean;
|
|
16
69
|
|
|
17
70
|
interface Segment {
|
|
18
71
|
readonly text: string;
|
|
@@ -212,6 +265,20 @@ declare class Config {
|
|
|
212
265
|
resolveOpts: ResolveOptions$1;
|
|
213
266
|
}): Config;
|
|
214
267
|
get(path: string): unknown;
|
|
268
|
+
/**
|
|
269
|
+
* Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
|
|
270
|
+
* {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
|
|
271
|
+
* `get` (which decodes to a plain JS value), this exposes the value tree for
|
|
272
|
+
* structural introspection via the `value.ts` accessors (`asString`, `asObject`,
|
|
273
|
+
* `isScalar`, …).
|
|
274
|
+
*
|
|
275
|
+
* `getValue('')` returns the root object node.
|
|
276
|
+
*
|
|
277
|
+
* Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
|
|
278
|
+
* the `HoconValue` union has no placeholder variant, so an unresolved value
|
|
279
|
+
* cannot be represented. This matches `getConfig` / `getList`.
|
|
280
|
+
*/
|
|
281
|
+
getValue(path: string): ReadonlyHoconValue | undefined;
|
|
215
282
|
getString(path: string): string;
|
|
216
283
|
getNumber(path: string): number;
|
|
217
284
|
getBoolean(path: string): boolean;
|
|
@@ -273,4 +340,4 @@ declare class Config {
|
|
|
273
340
|
private requireScalar;
|
|
274
341
|
}
|
|
275
342
|
|
|
276
|
-
export { type ByteUnit as B, Config as C, type DurationUnit as D, type HoconValue as H, type PackageResolver as P, type
|
|
343
|
+
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 ResolveOptions as b, asArray as c, asBoolean as d, asNumber as e, asObject as f, asString as g, defaultParseOptions as h, defaultResolveOptions as i, isArray as j, isNull as k, isObject as l, isScalar as m, parseAsync as n, parseFile as o, parse as p, parseFileAsync as q, parseFileWithOptions as r, parseString as s, parseStringWithOptions as t };
|
|
@@ -13,6 +13,59 @@ type HoconValue = {
|
|
|
13
13
|
raw: string;
|
|
14
14
|
valueType: ScalarValueType;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Deeply-immutable view of a {@link HoconValue}. `Config.getValue` returns this
|
|
18
|
+
* so callers cannot mutate the parsed configuration tree (the live nodes are
|
|
19
|
+
* shared, not cloned). `Map`/array containers become `ReadonlyMap`/`readonly[]`
|
|
20
|
+
* recursively, so `.set` / `.push` / element assignment are compile errors.
|
|
21
|
+
*
|
|
22
|
+
* `HoconValue` is structurally assignable to `ReadonlyHoconValue`, so internal
|
|
23
|
+
* code holding a mutable node can return it here, and the accessor functions
|
|
24
|
+
* below accept both forms.
|
|
25
|
+
*/
|
|
26
|
+
type ReadonlyHoconValue = {
|
|
27
|
+
readonly kind: 'object';
|
|
28
|
+
readonly fields: ReadonlyMap<string, ReadonlyHoconValue>;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'array';
|
|
31
|
+
readonly items: readonly ReadonlyHoconValue[];
|
|
32
|
+
} | {
|
|
33
|
+
readonly kind: 'scalar';
|
|
34
|
+
readonly raw: string;
|
|
35
|
+
readonly valueType: ScalarValueType;
|
|
36
|
+
};
|
|
37
|
+
/** Scalar string only (strict): non-string scalars and containers → undefined. */
|
|
38
|
+
declare function asString(v: ReadonlyHoconValue): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Scalar coerced to a number via {@link coerceNumber} (lenient, matching the
|
|
41
|
+
* `getNumber` getter: a numeric-looking string scalar coerces too). TS has a
|
|
42
|
+
* single `number` type, so this unifies rs's `as_i64` + `as_f64`.
|
|
43
|
+
*/
|
|
44
|
+
declare function asNumber(v: ReadonlyHoconValue): number | undefined;
|
|
45
|
+
/** Scalar coerced to a boolean via {@link coerceBoolean} (true/yes/on, false/no/off). */
|
|
46
|
+
declare function asBoolean(v: ReadonlyHoconValue): boolean | undefined;
|
|
47
|
+
/** The object's fields, or undefined if not an object. */
|
|
48
|
+
declare function asObject(v: ReadonlyHoconValue): ReadonlyMap<string, ReadonlyHoconValue> | undefined;
|
|
49
|
+
/** The array's items, or undefined if not an array. */
|
|
50
|
+
declare function asArray(v: ReadonlyHoconValue): readonly ReadonlyHoconValue[] | undefined;
|
|
51
|
+
/** Type guard: narrows to the object variant. */
|
|
52
|
+
declare function isObject(v: ReadonlyHoconValue): v is {
|
|
53
|
+
readonly kind: 'object';
|
|
54
|
+
readonly fields: ReadonlyMap<string, ReadonlyHoconValue>;
|
|
55
|
+
};
|
|
56
|
+
/** Type guard: narrows to the array variant. */
|
|
57
|
+
declare function isArray(v: ReadonlyHoconValue): v is {
|
|
58
|
+
readonly kind: 'array';
|
|
59
|
+
readonly items: readonly ReadonlyHoconValue[];
|
|
60
|
+
};
|
|
61
|
+
/** Type guard: narrows to the scalar variant. */
|
|
62
|
+
declare function isScalar(v: ReadonlyHoconValue): v is {
|
|
63
|
+
readonly kind: 'scalar';
|
|
64
|
+
readonly raw: string;
|
|
65
|
+
readonly valueType: ScalarValueType;
|
|
66
|
+
};
|
|
67
|
+
/** True for a null scalar. */
|
|
68
|
+
declare function isNull(v: ReadonlyHoconValue): boolean;
|
|
16
69
|
|
|
17
70
|
interface Segment {
|
|
18
71
|
readonly text: string;
|
|
@@ -212,6 +265,20 @@ declare class Config {
|
|
|
212
265
|
resolveOpts: ResolveOptions$1;
|
|
213
266
|
}): Config;
|
|
214
267
|
get(path: string): unknown;
|
|
268
|
+
/**
|
|
269
|
+
* Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
|
|
270
|
+
* {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
|
|
271
|
+
* `get` (which decodes to a plain JS value), this exposes the value tree for
|
|
272
|
+
* structural introspection via the `value.ts` accessors (`asString`, `asObject`,
|
|
273
|
+
* `isScalar`, …).
|
|
274
|
+
*
|
|
275
|
+
* `getValue('')` returns the root object node.
|
|
276
|
+
*
|
|
277
|
+
* Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
|
|
278
|
+
* the `HoconValue` union has no placeholder variant, so an unresolved value
|
|
279
|
+
* cannot be represented. This matches `getConfig` / `getList`.
|
|
280
|
+
*/
|
|
281
|
+
getValue(path: string): ReadonlyHoconValue | undefined;
|
|
215
282
|
getString(path: string): string;
|
|
216
283
|
getNumber(path: string): number;
|
|
217
284
|
getBoolean(path: string): boolean;
|
|
@@ -273,4 +340,4 @@ declare class Config {
|
|
|
273
340
|
private requireScalar;
|
|
274
341
|
}
|
|
275
342
|
|
|
276
|
-
export { type ByteUnit as B, Config as C, type DurationUnit as D, type HoconValue as H, type PackageResolver as P, type
|
|
343
|
+
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 ResolveOptions as b, asArray as c, asBoolean as d, asNumber as e, asObject as f, asString as g, defaultParseOptions as h, defaultResolveOptions as i, isArray as j, isNull as k, isObject as l, isScalar as m, parseAsync as n, parseFile as o, parse as p, parseFileAsync as q, parseFileWithOptions as r, parseString as s, parseStringWithOptions as t };
|
package/dist/index.cjs
CHANGED
|
@@ -36,10 +36,19 @@ __export(src_exports, {
|
|
|
36
36
|
PackageLookupError: () => PackageLookupError,
|
|
37
37
|
ParseError: () => ParseError,
|
|
38
38
|
ResolveError: () => ResolveError,
|
|
39
|
+
asArray: () => asArray,
|
|
40
|
+
asBoolean: () => asBoolean,
|
|
41
|
+
asNumber: () => asNumber,
|
|
42
|
+
asObject: () => asObject,
|
|
43
|
+
asString: () => asString,
|
|
39
44
|
defaultParseOptions: () => defaultParseOptions,
|
|
40
45
|
defaultResolveOptions: () => defaultResolveOptions,
|
|
41
46
|
empty: () => empty,
|
|
42
47
|
fromMap: () => fromMap,
|
|
48
|
+
isArray: () => isArray,
|
|
49
|
+
isNull: () => isNull,
|
|
50
|
+
isObject: () => isObject,
|
|
51
|
+
isScalar: () => isScalar,
|
|
43
52
|
parse: () => parse,
|
|
44
53
|
parseAsync: () => parseAsync,
|
|
45
54
|
parseFile: () => parseFile,
|
|
@@ -2601,6 +2610,32 @@ var Config = class _Config {
|
|
|
2601
2610
|
if (v === void 0) return void 0;
|
|
2602
2611
|
return hoconToJs(v);
|
|
2603
2612
|
}
|
|
2613
|
+
/**
|
|
2614
|
+
* Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
|
|
2615
|
+
* {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
|
|
2616
|
+
* `get` (which decodes to a plain JS value), this exposes the value tree for
|
|
2617
|
+
* structural introspection via the `value.ts` accessors (`asString`, `asObject`,
|
|
2618
|
+
* `isScalar`, …).
|
|
2619
|
+
*
|
|
2620
|
+
* `getValue('')` returns the root object node.
|
|
2621
|
+
*
|
|
2622
|
+
* Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
|
|
2623
|
+
* the `HoconValue` union has no placeholder variant, so an unresolved value
|
|
2624
|
+
* cannot be represented. This matches `getConfig` / `getList`.
|
|
2625
|
+
*/
|
|
2626
|
+
getValue(path2) {
|
|
2627
|
+
const v = this.lookupNode(path2);
|
|
2628
|
+
if (v === void 0) {
|
|
2629
|
+
if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2630
|
+
throw new NotResolvedError(path2);
|
|
2631
|
+
}
|
|
2632
|
+
return void 0;
|
|
2633
|
+
}
|
|
2634
|
+
if (v.kind !== "scalar" && !this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2635
|
+
throw new NotResolvedError(path2);
|
|
2636
|
+
}
|
|
2637
|
+
return v;
|
|
2638
|
+
}
|
|
2604
2639
|
getString(path2) {
|
|
2605
2640
|
const v = this.requireScalar(path2);
|
|
2606
2641
|
if (v.valueType === "null") {
|
|
@@ -3108,6 +3143,35 @@ async function parseFileAsync(filePath, opts = {}) {
|
|
|
3108
3143
|
});
|
|
3109
3144
|
}
|
|
3110
3145
|
|
|
3146
|
+
// src/value.ts
|
|
3147
|
+
function asString(v) {
|
|
3148
|
+
return v.kind === "scalar" && v.valueType === "string" ? v.raw : void 0;
|
|
3149
|
+
}
|
|
3150
|
+
function asNumber(v) {
|
|
3151
|
+
return v.kind === "scalar" ? coerceNumber(v.raw) : void 0;
|
|
3152
|
+
}
|
|
3153
|
+
function asBoolean(v) {
|
|
3154
|
+
return v.kind === "scalar" ? coerceBoolean(v.raw) : void 0;
|
|
3155
|
+
}
|
|
3156
|
+
function asObject(v) {
|
|
3157
|
+
return v.kind === "object" ? v.fields : void 0;
|
|
3158
|
+
}
|
|
3159
|
+
function asArray(v) {
|
|
3160
|
+
return v.kind === "array" ? v.items : void 0;
|
|
3161
|
+
}
|
|
3162
|
+
function isObject(v) {
|
|
3163
|
+
return v.kind === "object";
|
|
3164
|
+
}
|
|
3165
|
+
function isArray(v) {
|
|
3166
|
+
return v.kind === "array";
|
|
3167
|
+
}
|
|
3168
|
+
function isScalar(v) {
|
|
3169
|
+
return v.kind === "scalar";
|
|
3170
|
+
}
|
|
3171
|
+
function isNull(v) {
|
|
3172
|
+
return v.kind === "scalar" && v.valueType === "null";
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3111
3175
|
// src/value-factory.ts
|
|
3112
3176
|
function fromMap(values, originDescription) {
|
|
3113
3177
|
const fields = coerceObject(values, "");
|
|
@@ -3182,10 +3246,19 @@ function coerceValue(v, atPath) {
|
|
|
3182
3246
|
PackageLookupError,
|
|
3183
3247
|
ParseError,
|
|
3184
3248
|
ResolveError,
|
|
3249
|
+
asArray,
|
|
3250
|
+
asBoolean,
|
|
3251
|
+
asNumber,
|
|
3252
|
+
asObject,
|
|
3253
|
+
asString,
|
|
3185
3254
|
defaultParseOptions,
|
|
3186
3255
|
defaultResolveOptions,
|
|
3187
3256
|
empty,
|
|
3188
3257
|
fromMap,
|
|
3258
|
+
isArray,
|
|
3259
|
+
isNull,
|
|
3260
|
+
isObject,
|
|
3261
|
+
isScalar,
|
|
3189
3262
|
parse,
|
|
3190
3263
|
parseAsync,
|
|
3191
3264
|
parseFile,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Config } from './config-
|
|
2
|
-
export { B as ByteUnit, D as DurationUnit, H as HoconValue, P as PackageResolver, a as ParseOptions, R as ResolveOptions, S as ScalarValueType, d as defaultParseOptions,
|
|
1
|
+
import { C as Config } from './config-D27s3_aG.cjs';
|
|
2
|
+
export { B as ByteUnit, D as DurationUnit, H as HoconValue, P as PackageResolver, a as ParseOptions, R as ReadonlyHoconValue, b as ResolveOptions, S as ScalarValueType, c as asArray, d as asBoolean, e as asNumber, f as asObject, g as asString, h as defaultParseOptions, i as defaultResolveOptions, j as isArray, k as isNull, l as isObject, m as isScalar, p as parse, n as parseAsync, o as parseFile, q as parseFileAsync, r as parseFileWithOptions, s as parseString, t as parseStringWithOptions } from './config-D27s3_aG.cjs';
|
|
3
3
|
|
|
4
4
|
declare class ParseError extends Error {
|
|
5
5
|
readonly line: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Config } from './config-
|
|
2
|
-
export { B as ByteUnit, D as DurationUnit, H as HoconValue, P as PackageResolver, a as ParseOptions, R as ResolveOptions, S as ScalarValueType, d as defaultParseOptions,
|
|
1
|
+
import { C as Config } from './config-D27s3_aG.js';
|
|
2
|
+
export { B as ByteUnit, D as DurationUnit, H as HoconValue, P as PackageResolver, a as ParseOptions, R as ReadonlyHoconValue, b as ResolveOptions, S as ScalarValueType, c as asArray, d as asBoolean, e as asNumber, f as asObject, g as asString, h as defaultParseOptions, i as defaultResolveOptions, j as isArray, k as isNull, l as isObject, m as isScalar, p as parse, n as parseAsync, o as parseFile, q as parseFileAsync, r as parseFileWithOptions, s as parseString, t as parseStringWithOptions } from './config-D27s3_aG.js';
|
|
3
3
|
|
|
4
4
|
declare class ParseError extends Error {
|
|
5
5
|
readonly line: number;
|
package/dist/index.js
CHANGED
|
@@ -2548,6 +2548,32 @@ var Config = class _Config {
|
|
|
2548
2548
|
if (v === void 0) return void 0;
|
|
2549
2549
|
return hoconToJs(v);
|
|
2550
2550
|
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
|
|
2553
|
+
* {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
|
|
2554
|
+
* `get` (which decodes to a plain JS value), this exposes the value tree for
|
|
2555
|
+
* structural introspection via the `value.ts` accessors (`asString`, `asObject`,
|
|
2556
|
+
* `isScalar`, …).
|
|
2557
|
+
*
|
|
2558
|
+
* `getValue('')` returns the root object node.
|
|
2559
|
+
*
|
|
2560
|
+
* Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
|
|
2561
|
+
* the `HoconValue` union has no placeholder variant, so an unresolved value
|
|
2562
|
+
* cannot be represented. This matches `getConfig` / `getList`.
|
|
2563
|
+
*/
|
|
2564
|
+
getValue(path2) {
|
|
2565
|
+
const v = this.lookupNode(path2);
|
|
2566
|
+
if (v === void 0) {
|
|
2567
|
+
if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2568
|
+
throw new NotResolvedError(path2);
|
|
2569
|
+
}
|
|
2570
|
+
return void 0;
|
|
2571
|
+
}
|
|
2572
|
+
if (v.kind !== "scalar" && !this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2573
|
+
throw new NotResolvedError(path2);
|
|
2574
|
+
}
|
|
2575
|
+
return v;
|
|
2576
|
+
}
|
|
2551
2577
|
getString(path2) {
|
|
2552
2578
|
const v = this.requireScalar(path2);
|
|
2553
2579
|
if (v.valueType === "null") {
|
|
@@ -3055,6 +3081,35 @@ async function parseFileAsync(filePath, opts = {}) {
|
|
|
3055
3081
|
});
|
|
3056
3082
|
}
|
|
3057
3083
|
|
|
3084
|
+
// src/value.ts
|
|
3085
|
+
function asString(v) {
|
|
3086
|
+
return v.kind === "scalar" && v.valueType === "string" ? v.raw : void 0;
|
|
3087
|
+
}
|
|
3088
|
+
function asNumber(v) {
|
|
3089
|
+
return v.kind === "scalar" ? coerceNumber(v.raw) : void 0;
|
|
3090
|
+
}
|
|
3091
|
+
function asBoolean(v) {
|
|
3092
|
+
return v.kind === "scalar" ? coerceBoolean(v.raw) : void 0;
|
|
3093
|
+
}
|
|
3094
|
+
function asObject(v) {
|
|
3095
|
+
return v.kind === "object" ? v.fields : void 0;
|
|
3096
|
+
}
|
|
3097
|
+
function asArray(v) {
|
|
3098
|
+
return v.kind === "array" ? v.items : void 0;
|
|
3099
|
+
}
|
|
3100
|
+
function isObject(v) {
|
|
3101
|
+
return v.kind === "object";
|
|
3102
|
+
}
|
|
3103
|
+
function isArray(v) {
|
|
3104
|
+
return v.kind === "array";
|
|
3105
|
+
}
|
|
3106
|
+
function isScalar(v) {
|
|
3107
|
+
return v.kind === "scalar";
|
|
3108
|
+
}
|
|
3109
|
+
function isNull(v) {
|
|
3110
|
+
return v.kind === "scalar" && v.valueType === "null";
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3058
3113
|
// src/value-factory.ts
|
|
3059
3114
|
function fromMap(values, originDescription) {
|
|
3060
3115
|
const fields = coerceObject(values, "");
|
|
@@ -3128,10 +3183,19 @@ export {
|
|
|
3128
3183
|
PackageLookupError,
|
|
3129
3184
|
ParseError,
|
|
3130
3185
|
ResolveError,
|
|
3186
|
+
asArray,
|
|
3187
|
+
asBoolean,
|
|
3188
|
+
asNumber,
|
|
3189
|
+
asObject,
|
|
3190
|
+
asString,
|
|
3131
3191
|
defaultParseOptions,
|
|
3132
3192
|
defaultResolveOptions,
|
|
3133
3193
|
empty,
|
|
3134
3194
|
fromMap,
|
|
3195
|
+
isArray,
|
|
3196
|
+
isNull,
|
|
3197
|
+
isObject,
|
|
3198
|
+
isScalar,
|
|
3135
3199
|
parse,
|
|
3136
3200
|
parseAsync,
|
|
3137
3201
|
parseFile,
|
package/dist/zod.cjs
CHANGED
|
@@ -2588,6 +2588,32 @@ var Config = class _Config {
|
|
|
2588
2588
|
if (v === void 0) return void 0;
|
|
2589
2589
|
return hoconToJs(v);
|
|
2590
2590
|
}
|
|
2591
|
+
/**
|
|
2592
|
+
* Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
|
|
2593
|
+
* {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
|
|
2594
|
+
* `get` (which decodes to a plain JS value), this exposes the value tree for
|
|
2595
|
+
* structural introspection via the `value.ts` accessors (`asString`, `asObject`,
|
|
2596
|
+
* `isScalar`, …).
|
|
2597
|
+
*
|
|
2598
|
+
* `getValue('')` returns the root object node.
|
|
2599
|
+
*
|
|
2600
|
+
* Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
|
|
2601
|
+
* the `HoconValue` union has no placeholder variant, so an unresolved value
|
|
2602
|
+
* cannot be represented. This matches `getConfig` / `getList`.
|
|
2603
|
+
*/
|
|
2604
|
+
getValue(path2) {
|
|
2605
|
+
const v = this.lookupNode(path2);
|
|
2606
|
+
if (v === void 0) {
|
|
2607
|
+
if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2608
|
+
throw new NotResolvedError(path2);
|
|
2609
|
+
}
|
|
2610
|
+
return void 0;
|
|
2611
|
+
}
|
|
2612
|
+
if (v.kind !== "scalar" && !this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2613
|
+
throw new NotResolvedError(path2);
|
|
2614
|
+
}
|
|
2615
|
+
return v;
|
|
2616
|
+
}
|
|
2591
2617
|
getString(path2) {
|
|
2592
2618
|
const v = this.requireScalar(path2);
|
|
2593
2619
|
if (v.valueType === "null") {
|
package/dist/zod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
|
-
import { C as Config, a as ParseOptions } from './config-
|
|
2
|
+
import { C as Config, a as ParseOptions } from './config-D27s3_aG.cjs';
|
|
3
3
|
|
|
4
4
|
declare function validate<T>(config: Config, schema: ZodType<T>): T;
|
|
5
5
|
declare function getValidated<T>(config: Config, path: string, schema: ZodType<T>): T;
|
package/dist/zod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
|
-
import { C as Config, a as ParseOptions } from './config-
|
|
2
|
+
import { C as Config, a as ParseOptions } from './config-D27s3_aG.js';
|
|
3
3
|
|
|
4
4
|
declare function validate<T>(config: Config, schema: ZodType<T>): T;
|
|
5
5
|
declare function getValidated<T>(config: Config, path: string, schema: ZodType<T>): T;
|
package/dist/zod.js
CHANGED
|
@@ -2548,6 +2548,32 @@ var Config = class _Config {
|
|
|
2548
2548
|
if (v === void 0) return void 0;
|
|
2549
2549
|
return hoconToJs(v);
|
|
2550
2550
|
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Returns the raw {@link HoconValue} node at `path` as a deeply-immutable
|
|
2553
|
+
* {@link ReadonlyHoconValue} view, or `undefined` if the path is absent. Unlike
|
|
2554
|
+
* `get` (which decodes to a plain JS value), this exposes the value tree for
|
|
2555
|
+
* structural introspection via the `value.ts` accessors (`asString`, `asObject`,
|
|
2556
|
+
* `isScalar`, …).
|
|
2557
|
+
*
|
|
2558
|
+
* `getValue('')` returns the root object node.
|
|
2559
|
+
*
|
|
2560
|
+
* Throws {@link NotResolvedError} when the node (or its subtree) is unresolved:
|
|
2561
|
+
* the `HoconValue` union has no placeholder variant, so an unresolved value
|
|
2562
|
+
* cannot be represented. This matches `getConfig` / `getList`.
|
|
2563
|
+
*/
|
|
2564
|
+
getValue(path2) {
|
|
2565
|
+
const v = this.lookupNode(path2);
|
|
2566
|
+
if (v === void 0) {
|
|
2567
|
+
if (!this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2568
|
+
throw new NotResolvedError(path2);
|
|
2569
|
+
}
|
|
2570
|
+
return void 0;
|
|
2571
|
+
}
|
|
2572
|
+
if (v.kind !== "scalar" && !this._resolved && this._resObjRootSubtreeHasPlaceholders(path2)) {
|
|
2573
|
+
throw new NotResolvedError(path2);
|
|
2574
|
+
}
|
|
2575
|
+
return v;
|
|
2576
|
+
}
|
|
2551
2577
|
getString(path2) {
|
|
2552
2578
|
const v = this.requireScalar(path2);
|
|
2553
2579
|
if (v.valueType === "null") {
|