@o3co/ts.hocon 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -5
- package/dist/adapters/env.cjs +1668 -0
- package/dist/adapters/env.d.cts +41 -0
- package/dist/adapters/env.d.ts +41 -0
- package/dist/adapters/env.js +1629 -0
- package/dist/adapters/jsonc.cjs +1613 -0
- package/dist/adapters/jsonc.d.cts +25 -0
- package/dist/adapters/jsonc.d.ts +25 -0
- package/dist/adapters/jsonc.js +1574 -0
- package/dist/adapters/properties.cjs +1681 -0
- package/dist/adapters/properties.d.cts +27 -0
- package/dist/adapters/properties.d.ts +27 -0
- package/dist/adapters/properties.js +1643 -0
- package/dist/adapters/toml.cjs +1570 -0
- package/dist/adapters/toml.d.cts +18 -0
- package/dist/adapters/toml.d.ts +18 -0
- package/dist/adapters/toml.js +1534 -0
- package/dist/adapters/yaml.cjs +1610 -0
- package/dist/adapters/yaml.d.cts +43 -0
- package/dist/adapters/yaml.d.ts +43 -0
- package/dist/adapters/yaml.js +1573 -0
- package/dist/index.cjs +139 -43
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +139 -43
- package/dist/zod.cjs +139 -43
- package/dist/zod.d.cts +1 -1
- package/dist/zod.d.ts +1 -1
- package/dist/zod.js +139 -43
- package/package.json +44 -9
- package/dist/{config-D27s3_aG.d.cts → config-PdhVgeLS.d.cts} +3 -3
- package/dist/{config-D27s3_aG.d.ts → config-PdhVgeLS.d.ts} +3 -3
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ A [Lightbend HOCON](https://github.com/lightbend/config/blob/main/HOCON.md) pars
|
|
|
14
14
|
|
|
15
15
|
> **Library stance:** ts.hocon is a HOCON config loader — its purpose is reading `.hocon` config files and providing typed access via the Config API (`getString`, `getNumber`, `getBoolean`, `getDuration`, `getBytes`, `toObject`). It is not a low-level parser API. Internal types like `HoconValue` may change between minor versions.
|
|
16
16
|
>
|
|
17
|
-
> **Cross-language conformance:** This implementation is tested against shared expected-JSON fixtures from [o3co/xx.hocon](https://github.com/o3co/xx.hocon) alongside [go.hocon](https://github.com/o3co/go.hocon)
|
|
17
|
+
> **Cross-language conformance:** This implementation is tested against shared expected-JSON fixtures from [o3co/xx.hocon](https://github.com/o3co/xx.hocon) alongside [go.hocon](https://github.com/o3co/go.hocon), [rs.hocon](https://github.com/o3co/rs.hocon), and [py.hocon](https://github.com/o3co/py.hocon) to ensure all four implementations meet the same Lightbend HOCON specification.
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -245,7 +245,7 @@ c.getBytes('max-size') // 536870912 (bytes)
|
|
|
245
245
|
c.getBytes('max-size', 'MiB') // 512
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
Supported duration units: `ns`, `us`, `ms`, `s`, `m`, `h`, `d` (and long forms like `seconds`, `minutes`).
|
|
248
|
+
Supported duration units: `ns`, `us`, `ms`, `s`, `m`, `h`, `d` (and long forms like `seconds`, `minutes`). Duration unit names are case-sensitive and must be lowercase (HOCON spec). Byte units are more case-tolerant: the canonical forms below plus lowercase aliases (`kb`, `kib`, …), any-case long forms (`megabytes`), and single-letter powers-of-two in both cases (`K`/`k`, per Lightbend).
|
|
249
249
|
Supported byte units: `B`, `KB`/`KiB`, `MB`/`MiB`, `GB`/`GiB`, `TB`/`TiB` (and long forms like `megabytes`, `mebibytes`).
|
|
250
250
|
|
|
251
251
|
## Spec Compliance
|
|
@@ -386,9 +386,43 @@ const config = parseWithSchema(hoconInput, schema) // fails fast on startup
|
|
|
386
386
|
|---------|----------|----------|-------------|
|
|
387
387
|
| [go.hocon](https://github.com/o3co/go.hocon) | Go | [pkg.go.dev](https://pkg.go.dev/github.com/o3co/go.hocon) | HOCON parser for Go |
|
|
388
388
|
| [rs.hocon](https://github.com/o3co/rs.hocon) | Rust | [crates.io](https://crates.io/crates/o3co-hocon) | HOCON parser for Rust |
|
|
389
|
+
| [py.hocon](https://github.com/o3co/py.hocon) | Python | [PyPI](https://pypi.org/project/hocon-parser/) | HOCON parser for Python |
|
|
389
390
|
| [hocon2](https://github.com/o3co/hocon2) | Go | [pkg.go.dev](https://pkg.go.dev/github.com/o3co/hocon2) | HOCON → JSON/YAML/TOML/Properties CLI |
|
|
390
391
|
|
|
391
|
-
The
|
|
392
|
+
The four parser implementations ([ts.hocon](https://github.com/o3co/ts.hocon), [rs.hocon](https://github.com/o3co/rs.hocon), [go.hocon](https://github.com/o3co/go.hocon), [py.hocon](https://github.com/o3co/py.hocon)) are all tracked against the same Lightbend HOCON spec — see the [cross-impl roll-up](https://github.com/o3co/xx.hocon/blob/main/docs/compliance-matrix.md) for per-impl conformance rates.
|
|
393
|
+
|
|
394
|
+
## Format adapters
|
|
395
|
+
|
|
396
|
+
Config files that belong to *other* programs can be mounted as HOCON, so a
|
|
397
|
+
`${...}` in your document can reach into them:
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
import { parseStringWithOptions } from '@o3co/ts.hocon'
|
|
401
|
+
import { loadEnv } from '@o3co/ts.hocon/adapters/env'
|
|
402
|
+
|
|
403
|
+
const base = loadEnv({ prefix: 'APP_' }) // APP_DB__HOST -> db.host
|
|
404
|
+
const cfg = parseStringWithOptions(src, { resolveSubstitutions: false })
|
|
405
|
+
const merged = cfg.withFallback(base).resolve()
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Deferring resolution matters: the plain `parse` resolves as it goes, so a
|
|
409
|
+
`${...}` aimed at the fallback would fail before the fallback is attached.
|
|
410
|
+
|
|
411
|
+
| Subpath | Needs | Notes |
|
|
412
|
+
| --- | --- | --- |
|
|
413
|
+
| `@o3co/ts.hocon/adapters/properties` | — | `java.util.Properties`, sharing the `include` syntax layer |
|
|
414
|
+
| `@o3co/ts.hocon/adapters/env` | — | Bulk-mounts a prefixed namespace; also reads `.env` |
|
|
415
|
+
| `@o3co/ts.hocon/adapters/jsonc` | — | JSON with comments and trailing commas |
|
|
416
|
+
| `@o3co/ts.hocon/adapters/toml` | `smol-toml` | Optional peer dependency |
|
|
417
|
+
| `@o3co/ts.hocon/adapters/yaml` | `yaml` | Optional peer dependency; YAML 1.2 core schema |
|
|
418
|
+
|
|
419
|
+
The TOML and YAML libraries are **optional peer dependencies**, so installing
|
|
420
|
+
this package still pulls in nothing — you add the one you actually use. Plain
|
|
421
|
+
JSON needs no adapter at all, HOCON being a JSON superset.
|
|
422
|
+
|
|
423
|
+
Foreign data stays data: a `${a.b}` in a mounted value is literal text, never a
|
|
424
|
+
reference, because the file belongs to a program that never agreed to HOCON's
|
|
425
|
+
syntax.
|
|
392
426
|
|
|
393
427
|
## Known Limitations
|
|
394
428
|
|
|
@@ -396,13 +430,12 @@ The three parser implementations ([ts.hocon](https://github.com/o3co/ts.hocon),
|
|
|
396
430
|
- **`include classpath(...)`** is not supported. This is a JVM-specific include form with no equivalent outside Java runtimes.
|
|
397
431
|
- **No watch/reload** — the library parses config at load time. For live-reloading, re-call `parse()` or `parseFile()` on change.
|
|
398
432
|
- **No streaming parser** — the entire input is loaded into memory. For very large configs, validate input size before parsing (see Security Considerations).
|
|
399
|
-
- **`.properties` include** — supports basic `key=value` / `key:value` syntax. Does not support multiline values (backslash continuation), Unicode escapes, or key escaping from the full Java .properties specification.
|
|
400
433
|
|
|
401
434
|
## Security Considerations
|
|
402
435
|
|
|
403
436
|
When parsing untrusted HOCON input, be aware of:
|
|
404
437
|
|
|
405
|
-
- **Path traversal in includes:** `include
|
|
438
|
+
- **Path traversal in includes:** a relative `include` path resolves against `baseDir` and can climb out of it with `..` segments to reach sensitive files such as `/etc/passwd`. Use a custom `readFileSync`/`readFile` that validates paths if parsing untrusted input.
|
|
406
439
|
- **Input size:** The parser has no built-in input size limit. For untrusted input, validate size before calling `parse()`.
|
|
407
440
|
- **Include depth:** Limited to 50 levels to prevent stack overflow from deep include chains.
|
|
408
441
|
|