import { HsonNode } from "../../../core/types.js"; import { JsonValue } from "../../../core/types.js"; import { type OrderedProjectedValue } from "../../../core/ordered-projected-value.js"; type JsonInputValue = JsonValue | OrderedProjectedValue; /** * Convert a JSON value into an `HsonNode` subtree, using a parent tag * to decide which Hson shape to build (`_hson_str`, `_hson_val`, `_hson_arr`, `_hson_obj`, * `_hson_elem`, `_hson_root`). * * Dispatch rules (by `$parentTag`): * * 1. Primitive branch (`STR_TAG` / `VAL_TAG`) * - `STR_TAG`: * - Requires `srcJson` to be a string, including `""`. * - Returns `<_hson_str>` with `$_content: [string]`. * - `VAL_TAG`: * - Requires `srcJson` to be a non-string primitive * (`number | boolean | null`). * - Returns `<_hson_val>` with `$_content: [primitive]`. * * 2. Array branch (`ARR_TAG`) * - Requires `srcJson` to be an array. * - For each item: * - Computes the child tag with `getTag(val)`. * - Recursively calls `nodeFromJson(val, childTag)` to get a child node. * - Wraps the child in an `<_hson_ii>` node with `$_meta.index` equal * to the array index. * - Returns `<_hson_arr>` containing the `_hson_ii` children. * * 3. Object branch (`OBJ_TAG`) * - Requires `srcJson` to be a non-array object. * - Applies one of three mutually exclusive paths: * * A) Root form: `{ _hson_root: , ... }` * - Forbids siblings alongside `_hson_root`. * - Recursively parses `` via `nodeFromJson`. * - Ensures the `_hson_root` child is a cluster: * - Scalar children (`_hson_str` / `_hson_val`) are wrapped in `<_hson_elem>`. * - Returns `<_hson_root>` containing a single cluster child. * * B) Element form: `{ "_hson_elem": [ ... ] }` * - Requires `_hson_elem` value to be an array. * - Each item must be one of: * - `string` → `<_hson_str>` child, * - `number | boolean | null` → `<_hson_val>` child, * - element-object: * `{ tagName: payload, $_attrs?, $_meta? }` * - Rejects reserved VSN keys via * `assertNoForbiddenVSNKeysInJSON`. * - Requires exactly one non-underscore tag key. * - Hoists `$_attrs` and `$_meta` onto the created element node. * - Normalizes `$_attrs.style`, accepting: * - style object → `serialize_style` → `parse_style_string`, * - style string → `parse_style_string`, * - null/undefined → dropped. * - Recursively builds the child subtree from `payload` using * `nodeFromJson(...)`. * - Returns a single `<_hson_elem>` node with these children. * * C) Generic object form (plain JSON object) * - Forbids reserved VSN keys via * `assertNoForbiddenVSNKeysInJSON`. * - For each own key: * - Builds a value node: * - `string` → `<_hson_str>`, * - `number | boolean | null` → `<_hson_val>`, * - array → recurse with parent `_hson_arr`, * - object → recurse with parent `_hson_obj`. * - Wraps non-cluster children in an `<_hson_obj>` to enforce JSON-mode * “object cluster” semantics. * - Wraps that in a property node `` whose `$_content` is the * cluster payload. * - Returns a single `<_hson_obj>` node containing all property nodes. * * Errors: * - Throws via `_throw_transform_err` when: * - `srcJson` type does not match the expected parent tag. * - `_hson_root` objects have illegal siblings. * - `_hson_elem` is not an array or has invalid items. * - A generic object contains reserved VSN keys. * - A value is not representable as a supported Hson shape. * * @param srcJson - The JSON value to convert (already parsed). * @param parentTag - The Hson tag that dictates how `srcJson` is interpreted * (`STR_TAG`, `VAL_TAG`, `ARR_TAG`, `OBJ_TAG`, etc). * @returns An object containing the constructed `node` subtree. * @see parse_json * @see getTag * @see assertNoForbiddenVSNKeysInJSON */ export declare function nodeFromJson(srcJson: JsonInputValue, parentTag: string): { node: HsonNode; }; /** * Parse JSON into a rooted `HsonNode` tree. * * Input handling: * - If `input` is a string, it is parsed with `JSON.parse`. Any parse * error is wrapped and rethrown via `_throw_transform_err`. * - The parsed or supplied value is detached recursively before conversion. * Caller records and arrays are never normalized in place or retained by * the canonical graph. * - Cyclic and non-JSON object values reject deterministically. * * Explicit `_hson_root` handling: * - A top-level `{ "_hson_root": , "$_meta"?: ... }` is constructed * as a root node rather than unwrapped. * - Empty `$_meta` is normalized away; populated or malformed root metadata * reaches canonical validation and rejects. * * Conversion: * - Delegates to `nodeFromJson(parsed, getTag(parsed))` * to build the main Hson subtree. * - Wraps the resulting node in a `_hson_root` wrapper: * - `$_tag: ROOT_TAG` * - `$_content: [node]` * - Runs `assert_invariants` on the final root to ensure structural * correctness. * * @param input - JSON string or already-parsed `JsonValue`. * @returns A `_hson_root`-wrapped `HsonNode` representing the JSON payload. * @throws If JSON parsing fails or invariants are violated. * @see nodeFromJson * @see getTag * @see assert_invariants */ export declare function parse_json(input: string | JsonValue): HsonNode; export {}; //# sourceMappingURL=parse-json.d.ts.map