♻️ migrate to core json

This commit is contained in:
Nanaloveyuki
2026-07-17 21:19:11 +08:00
parent bcfb35d7ae
commit a58a0747bb
49 changed files with 533 additions and 601 deletions
@@ -13,14 +13,14 @@ key-word:
## Async-logger-build-config-to-json
Convert `AsyncLoggerBuildConfig` into a `JsonValue`. This helper exports both the base synchronous logger config and the async runtime config as one structured payload.
Convert `AsyncLoggerBuildConfig` into a `Json`. This helper exports both the base synchronous logger config and the async runtime config as one structured payload.
### Interface
```moonbit
pub fn async_logger_build_config_to_json(
config : AsyncLoggerBuildConfig,
) -> @json_parser.JsonValue {}
) -> Json {}
```
#### input
@@ -29,7 +29,7 @@ pub fn async_logger_build_config_to_json(
#### output
- `JsonValue` - Structured JSON representation of the full async build config.
- `Json` - Structured JSON representation of the full async build config.
### Explanation
+3 -3
View File
@@ -13,12 +13,12 @@ key-word:
## Async-logger-config-to-json
Convert a typed `AsyncLoggerConfig` into a `JsonValue`. This helper exports async queue capacity, overflow policy, batch sizing, linger timing, and flush behavior in a structured form.
Convert a typed `AsyncLoggerConfig` into a `Json`. This helper exports async queue capacity, overflow policy, batch sizing, linger timing, and flush behavior in a structured form.
### Interface
```moonbit
pub fn async_logger_config_to_json(config : AsyncLoggerConfig) -> @json_parser.JsonValue {}
pub fn async_logger_config_to_json(config : AsyncLoggerConfig) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn async_logger_config_to_json(config : AsyncLoggerConfig) -> @json_parser.J
#### output
- `JsonValue` - Structured JSON representation of the async config.
- `Json` - Structured JSON representation of the async config.
### Explanation
+4 -4
View File
@@ -13,12 +13,12 @@ key-word:
## Async-logger-state-to-json
Convert `AsyncLoggerState` into a `JsonValue`. This helper is the structured export path for async logger runtime snapshots or manually constructed state values when callers want machine-readable diagnostics instead of a plain string.
Convert `AsyncLoggerState` into a `Json`. This helper is the structured export path for async logger runtime snapshots or manually constructed state values when callers want machine-readable diagnostics instead of a plain string.
### Interface
```moonbit
pub fn async_logger_state_to_json(state : AsyncLoggerState) -> @json_parser.JsonValue {}
pub fn async_logger_state_to_json(state : AsyncLoggerState) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn async_logger_state_to_json(state : AsyncLoggerState) -> @json_parser.Json
#### output
- `JsonValue` - Structured JSON representation of the async logger snapshot.
- `Json` - Structured JSON representation of the async logger snapshot.
### Explanation
@@ -62,7 +62,7 @@ In this example, callers receive a structured value that can be composed into la
When another serializer or pipeline expects a JSON value:
```moonbit
let payload = async_logger_state_to_json(logger.state())
println(@json_parser.stringify(payload))
println(payload.stringify())
```
In this example, the helper stays useful even outside the built-in stringify wrapper.
+3 -3
View File
@@ -13,12 +13,12 @@ key-word:
## Async-runtime-state-to-json
Convert `AsyncRuntimeState` into a `JsonValue`. This helper exports the async runtime mode and background worker capability in a structured form.
Convert `AsyncRuntimeState` into a `Json`. This helper exports the async runtime mode and background worker capability in a structured form.
### Interface
```moonbit
pub fn async_runtime_state_to_json(state : AsyncRuntimeState) -> @json_parser.JsonValue {}
pub fn async_runtime_state_to_json(state : AsyncRuntimeState) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn async_runtime_state_to_json(state : AsyncRuntimeState) -> @json_parser.Js
#### output
- `JsonValue` - Structured JSON representation of the runtime state.
- `Json` - Structured JSON representation of the runtime state.
### Explanation
+4 -4
View File
@@ -13,12 +13,12 @@ key-word:
## File-rotation-config-to-json
Convert `FileRotation` into a `JsonValue`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
Convert `FileRotation` into a `Json`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
### Interface
```moonbit
pub fn file_rotation_config_to_json(config : FileRotation) -> @json_parser.JsonValue {}
pub fn file_rotation_config_to_json(config : FileRotation) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn file_rotation_config_to_json(config : FileRotation) -> @json_parser.JsonV
#### output
- `JsonValue` - Structured JSON representation of the rotation policy.
- `Json` - Structured JSON representation of the rotation policy.
### Explanation
@@ -82,7 +82,7 @@ e.g.:
### Notes
1. Use this helper when downstream code expects `JsonValue` rather than a typed `FileRotation` value.
1. Use this helper when downstream code expects `Json` rather than a typed `FileRotation` value.
2. Pair it with `file_rotation(...)` when building rotation policy in code before export.
+4 -4
View File
@@ -13,12 +13,12 @@ key-word:
## File-sink-policy-to-json
Convert `FileSinkPolicy` into a `JsonValue`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
Convert `FileSinkPolicy` into a `Json`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
### Interface
```moonbit
pub fn file_sink_policy_to_json(policy : FileSinkPolicy) -> @json_parser.JsonValue {}
pub fn file_sink_policy_to_json(policy : FileSinkPolicy) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn file_sink_policy_to_json(policy : FileSinkPolicy) -> @json_parser.JsonVal
#### output
- `JsonValue` - Structured JSON representation of the file policy.
- `Json` - Structured JSON representation of the file policy.
### Explanation
@@ -73,7 +73,7 @@ e.g.:
### Notes
1. Use this helper when downstream code expects `JsonValue` rather than text.
1. Use this helper when downstream code expects `Json` rather than text.
2. It pairs naturally with `FileSink::policy()`, `RuntimeSink::file_policy()`, and related default-policy accessors.
+4 -4
View File
@@ -13,12 +13,12 @@ key-word:
## File-sink-state-to-json
Convert `FileSinkState` into a `JsonValue`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
Convert `FileSinkState` into a `Json`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
### Interface
```moonbit
pub fn file_sink_state_to_json(state : FileSinkState) -> @json_parser.JsonValue {}
pub fn file_sink_state_to_json(state : FileSinkState) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn file_sink_state_to_json(state : FileSinkState) -> @json_parser.JsonValue
#### output
- `JsonValue` - Structured JSON representation of the file sink state.
- `Json` - Structured JSON representation of the file sink state.
### Explanation
@@ -72,7 +72,7 @@ e.g.:
### Notes
1. Use this helper when diagnostics consumers expect `JsonValue`.
1. Use this helper when diagnostics consumers expect `Json`.
2. It pairs naturally with `FileSink::state()`, `RuntimeSink::file_state()`, and `ConfiguredLogger::file_state()`.
+4 -4
View File
@@ -13,12 +13,12 @@ key-word:
## Logger-config-to-json
Convert a typed `LoggerConfig` into a `JsonValue`. This helper is the structured export path when config should be persisted, inspected, or embedded into larger JSON payloads.
Convert a typed `LoggerConfig` into a `Json`. This helper is the structured export path when config should be persisted, inspected, or embedded into larger JSON payloads.
### Interface
```moonbit
pub fn logger_config_to_json(config : LoggerConfig) -> @json_parser.JsonValue {}
pub fn logger_config_to_json(config : LoggerConfig) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn logger_config_to_json(config : LoggerConfig) -> @json_parser.JsonValue {}
#### output
- `JsonValue` - JSON representation of the logger config.
- `Json` - JSON representation of the logger config.
### Explanation
@@ -73,5 +73,5 @@ e.g.:
1. Use this helper when you need a reusable JSON value rather than a final JSON string.
2. Use `stringify_logger_config(...)` when the next consumer expects JSON text instead of `JsonValue`.
2. Use `stringify_logger_config(...)` when the next consumer expects JSON text instead of `Json`.
+4 -4
View File
@@ -13,12 +13,12 @@ key-word:
## Queue-config-to-json
Convert a typed `QueueConfig` into a `JsonValue`. This helper is the structured export path for synchronous queue wrapper configuration when callers want machine-readable config output.
Convert a typed `QueueConfig` into a `Json`. This helper is the structured export path for synchronous queue wrapper configuration when callers want machine-readable config output.
### Interface
```moonbit
pub fn queue_config_to_json(queue : QueueConfig) -> @json_parser.JsonValue {}
pub fn queue_config_to_json(queue : QueueConfig) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn queue_config_to_json(queue : QueueConfig) -> @json_parser.JsonValue {}
#### output
- `JsonValue` - Structured JSON representation of the queue config.
- `Json` - Structured JSON representation of the queue config.
### Explanation
@@ -74,5 +74,5 @@ e.g.:
1. Use this helper when you need a reusable JSON value rather than a final JSON string.
2. Use `stringify_queue_config(...)` when the next consumer expects text instead of `JsonValue`.
2. Use `stringify_queue_config(...)` when the next consumer expects text instead of `Json`.
+3 -3
View File
@@ -13,12 +13,12 @@ key-word:
## Runtime-file-state-to-json
Convert `RuntimeFileState` into a `JsonValue`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
Convert `RuntimeFileState` into a `Json`. On the root `src` facade, this helper forwards to the concrete serializer owned by `src/file_model`.
### Interface
```moonbit
pub fn runtime_file_state_to_json(state : RuntimeFileState) -> @json_parser.JsonValue {}
pub fn runtime_file_state_to_json(state : RuntimeFileState) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn runtime_file_state_to_json(state : RuntimeFileState) -> @json_parser.Json
#### output
- `JsonValue` - Structured JSON representation of the runtime file state.
- `Json` - Structured JSON representation of the runtime file state.
### Explanation
+3 -3
View File
@@ -13,12 +13,12 @@ key-word:
## Sink-config-to-json
Convert `SinkConfig` into a `JsonValue`. This helper is used directly for sink export and indirectly when exporting `LoggerConfig`.
Convert `SinkConfig` into a `Json`. This helper is used directly for sink export and indirectly when exporting `LoggerConfig`.
### Interface
```moonbit
pub fn sink_config_to_json(config : SinkConfig) -> @json_parser.JsonValue {}
pub fn sink_config_to_json(config : SinkConfig) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn sink_config_to_json(config : SinkConfig) -> @json_parser.JsonValue {}
#### output
- `JsonValue` - JSON representation of the sink configuration.
- `Json` - JSON representation of the sink configuration.
### Explanation
@@ -40,7 +40,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` returns compact JSON.
- `pretty=true` returns indented JSON for human inspection.
- This helper is built on top of `async_logger_build_config_to_json(...)`.
- Internally it serializes the `JsonValue` result with `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`, so the text form stays aligned with the structured async build-config export helper.
- Internally it serializes the `Json` result with `value.stringify(...)` or `value.stringify(indent=2)`, so the text form stays aligned with the structured async build-config export helper.
- The output keeps `logger` and `async_config` as separate sections, matching supported parser input.
- The serialized `logger` section preserves the full `LoggerConfig` shape, even though `build_async_text_logger(...)` later consumes only the selected text-oriented subset of that logger config.
- That includes preserving whatever `logger.sink.kind` text is present in the config, even though the later text-specific builder path still ignores that sink-kind branch and constructs `FormattedConsoleSink` from `logger.sink.text_formatter`.
@@ -80,7 +80,7 @@ In this example, compact JSON is returned without extra formatting.
### Error Case
e.g.:
- If callers need a `JsonValue` for further composition, they should use `async_logger_build_config_to_json(...)` instead.
- If callers need a `Json` for further composition, they should use `async_logger_build_config_to_json(...)` instead.
- If only one layer of config is required, this helper may be broader than necessary.
@@ -96,7 +96,7 @@ e.g.:
4. In particular, serialized `logger.sink.kind` text is descriptive config data, not a guarantee that the text-specific builder path will branch on that sink kind later.
5. Use `async_logger_build_config_to_json(...)` when the next consumer still needs a `JsonValue` for composition before final stringification.
5. Use `async_logger_build_config_to_json(...)` when the next consumer still needs a `Json` for composition before final stringification.
6. After parsing, the same text can also feed the application or library facade builders; string export preserves one shared build-config shape, not a direct-builder-only route.
+3 -3
View File
@@ -37,7 +37,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` returns compact JSON suitable for transport and snapshots.
- `pretty=true` returns indented JSON for humans.
- This helper is built on top of `async_logger_config_to_json(...)`.
- Internally it serializes the `JsonValue` result with `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`, so the text form stays aligned with the structured async-config export helper.
- Internally it serializes the `Json` result with `value.stringify(...)` or `value.stringify(indent=2)`, so the text form stays aligned with the structured async-config export helper.
- The exported text follows the supported async config schema rather than internal queue implementation details.
- Canonical policy labels such as `DropNewest` and `Never` are emitted even though the parser also accepts aliases like `DropLatest` and `None`.
@@ -68,7 +68,7 @@ In this example, compact JSON is returned without extra formatting.
### Error Case
e.g.:
- If callers need a `JsonValue` for composition, they should use `async_logger_config_to_json(...)` instead.
- If callers need a `Json` for composition, they should use `async_logger_config_to_json(...)` instead.
- If invalid constructor inputs were normalized earlier, the resulting text contains the normalized config values.
@@ -78,5 +78,5 @@ e.g.:
2. If negative `max_pending` semantics matter, remember that the serialized text preserves the config value while runtime queue creation later clamps the queue limit to `0`.
3. Use `async_logger_config_to_json(...)` when the next consumer still needs a `JsonValue` for composition before final stringification.
3. Use `async_logger_config_to_json(...)` when the next consumer still needs a `Json` for composition before final stringification.
+2 -2
View File
@@ -40,7 +40,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` returns compact JSON.
- `pretty=true` returns indented JSON suitable for human diagnostics.
- This helper is built on top of `async_logger_state_to_json(...)`.
- Internally it stringifies the same JSON snapshot shape returned by the public export helper, using `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`.
- Internally it stringifies the same JSON snapshot shape returned by the public export helper, using `value.stringify(...)` or `value.stringify(indent=2)`.
- The compact form matches snapshots such as `{"runtime":{"mode":"native_worker","background_worker":true},"phase":"ready","pending_count":0,...}`.
- String output is convenient for logs, CLI output, and startup diagnostics.
- The serializer does not care whether the input came from a live logger read or a synthetic `AsyncLoggerState::new(...)` call.
@@ -83,7 +83,7 @@ e.g.:
2. The compact output shape is already locked by the async runtime snapshot tests, so it is suitable for stable diagnostics and assertions.
3. Use `async_logger_state_to_json(...)` when the next consumer still needs a `JsonValue` for composition before final stringification.
3. Use `async_logger_state_to_json(...)` when the next consumer still needs a `Json` for composition before final stringification.
4. Pair it with `AsyncLogger::state()` for current logger diagnostics, or with `AsyncLoggerState::new(...)` when exporting a manual snapshot built by tests or adapters.
+2 -2
View File
@@ -40,7 +40,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` returns compact JSON.
- `pretty=true` returns indented JSON for human diagnostics.
- This helper is built on top of `async_runtime_state_to_json(...)`.
- Internally it serializes the `JsonValue` result with `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`, so the text form stays aligned with the structured runtime-state export helper.
- Internally it serializes the `Json` result with `value.stringify(...)` or `value.stringify(indent=2)`, so the text form stays aligned with the structured runtime-state export helper.
- The compact form matches the tested snapshot shape such as `{"mode":"native_worker","background_worker":true}`.
- It is well-suited for startup banners, support reports, and target capability logs.
@@ -79,5 +79,5 @@ e.g.:
2. This helper is the direct text form of the same two-field runtime snapshot exported by `async_runtime_state_to_json(...)`.
3. Use `async_runtime_state_to_json(...)` when the next consumer still needs a `JsonValue` for composition before final stringification.
3. Use `async_runtime_state_to_json(...)` when the next consumer still needs a `Json` for composition before final stringification.
+1 -1
View File
@@ -66,7 +66,7 @@ In this example, compact JSON is produced without extra formatting logic.
### Error Case
e.g.:
- If callers need a `JsonValue` for composition rather than text, `file_sink_policy_to_json(...)` is the better API.
- If callers need a `Json` for composition rather than text, `file_sink_policy_to_json(...)` is the better API.
- If rotation is disabled, the output still includes `rotation` as `null`.
+2 -2
View File
@@ -37,7 +37,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` produces compact JSON.
- `pretty=true` produces indented human-readable JSON.
- This helper builds on top of `logger_config_to_json(...)`.
- Internally it serializes the `JsonValue` result with `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`, so the text form stays aligned with the structured logger-config export helper.
- Internally it serializes the `Json` result with `value.stringify(...)` or `value.stringify(indent=2)`, so the text form stays aligned with the structured logger-config export helper.
- Output is stable and suited for roundtrip config workflows.
### How to Use
@@ -71,7 +71,7 @@ e.g.:
### Notes
1. Use this helper when the next consumer expects JSON text instead of `JsonValue`.
1. Use this helper when the next consumer expects JSON text instead of `Json`.
2. Use `logger_config_to_json(...)` when you still need to embed the config inside a larger JSON object before final stringification.
+3 -3
View File
@@ -37,7 +37,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` returns compact JSON suitable for logs and snapshots.
- `pretty=true` returns indented JSON for human inspection.
- This helper is built on top of `queue_config_to_json(...)`.
- Internally it serializes the `JsonValue` result with `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`, so the text form stays aligned with the structured export helper.
- Internally it serializes the `Json` result with `value.stringify(...)` or `value.stringify(indent=2)`, so the text form stays aligned with the structured export helper.
- The resulting text follows the same queue schema accepted by config parsing flows.
### How to Use
@@ -67,13 +67,13 @@ In this example, compact JSON is returned without extra formatting.
### Error Case
e.g.:
- If callers need a `JsonValue` for further composition, this API is the wrong layer and `queue_config_to_json(...)` should be used instead.
- If callers need a `Json` for further composition, this API is the wrong layer and `queue_config_to_json(...)` should be used instead.
- If queue policy is too aggressive for workload burst size, serialization still succeeds because this helper only exports config.
### Notes
1. Use this helper when the next consumer expects JSON text instead of `JsonValue`.
1. Use this helper when the next consumer expects JSON text instead of `Json`.
2. Use `queue_config_to_json(...)` when you still need to embed the queue config inside a larger JSON object before final stringification.
+1 -1
View File
@@ -69,7 +69,7 @@ In this example, compact JSON is returned without extra formatting logic.
### Error Case
e.g.:
- If callers need a `JsonValue` rather than text, `runtime_file_state_to_json(...)` is the better API.
- If callers need a `Json` rather than text, `runtime_file_state_to_json(...)` is the better API.
- If queue wrapping is not relevant, `stringify_file_sink_state(...)` may be the simpler API.
+2 -2
View File
@@ -37,7 +37,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` gives compact JSON.
- `pretty=true` gives indented output.
- This helper builds on top of `sink_config_to_json(...)`.
- Internally it serializes the `JsonValue` result with `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`, so the text form stays aligned with the structured sink export helper.
- Internally it serializes the `Json` result with `value.stringify(...)` or `value.stringify(indent=2)`, so the text form stays aligned with the structured sink export helper.
- It is useful when examples or generated docs want to show only sink-specific config.
### How to Use
@@ -71,7 +71,7 @@ e.g.:
### Notes
1. Use this helper when the next consumer expects JSON text instead of `JsonValue`.
1. Use this helper when the next consumer expects JSON text instead of `Json`.
2. Use `sink_config_to_json(...)` when you still need to embed the sink config inside a larger JSON object before final stringification.
+2 -2
View File
@@ -40,7 +40,7 @@ Detailed rules explaining key parameters and behaviors
- `pretty=false` returns compact JSON.
- `pretty=true` returns indented JSON for humans.
- This helper is built on top of `text_formatter_config_to_json(...)`.
- Internally it serializes the `JsonValue` result with `@json_parser.stringify(...)` or `@json_parser.stringify_pretty(value, 2)`, so the text form stays aligned with the structured formatter export helper.
- Internally it serializes the `Json` result with `value.stringify(...)` or `value.stringify(indent=2)`, so the text form stays aligned with the structured formatter export helper.
- The output preserves the supported formatter config schema instead of any runtime-only formatter instance details.
### How to Use
@@ -76,7 +76,7 @@ e.g.:
### Notes
1. Use this helper when the next consumer expects JSON text instead of `JsonValue`.
1. Use this helper when the next consumer expects JSON text instead of `Json`.
2. Use `text_formatter_config_to_json(...)` when you still need to embed formatter config inside a larger JSON object before final stringification.
+3 -3
View File
@@ -13,12 +13,12 @@ key-word:
## Text-formatter-config-to-json
Convert a typed `TextFormatterConfig` into a `JsonValue`. This helper exports formatter toggles, separators, color settings, markup behavior, and optional style tags in a machine-readable form.
Convert a typed `TextFormatterConfig` into a `Json`. This helper exports formatter toggles, separators, color settings, markup behavior, and optional style tags in a machine-readable form.
### Interface
```moonbit
pub fn text_formatter_config_to_json(config : TextFormatterConfig) -> @json_parser.JsonValue {}
pub fn text_formatter_config_to_json(config : TextFormatterConfig) -> Json {}
```
#### input
@@ -27,7 +27,7 @@ pub fn text_formatter_config_to_json(config : TextFormatterConfig) -> @json_pars
#### output
- `JsonValue` - Structured JSON representation of the formatter config.
- `Json` - Structured JSON representation of the formatter config.
### Explanation