refactor(js)!: redesign JSON serialization and parsing around gleam_json (#13) - #26
Merged
Merged
Conversation
Replace the handwritten JSON FFI in glendix/js/json with gleam_json. - stringify now delegates to gleam/json.to_string (source-compatible). - parse now takes an explicit decode.Decoder and returns the decoded value, delegating to gleam/json.parse. - JsonError distinguishes deterministic syntax failures (InvalidSyntax with JsonSyntaxError) from decoder/type failures (DecoderMismatch), mapped in pure Gleam without JavaScript engine-specific text. - Remove src/glendix/js/json_ffi.mjs and its externals. - Cover null, scalars, escaped strings, arrays, objects, malformed input, unexpected byte, and decoder mismatch (incl. nested path). - Document the migration in README.md/.ko/.ja. Closes #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #13.
Summary
Replaces the handwritten JSON FFI in
glendix/js/jsonwithgleam_json, andredesigns the parsing boundary to be type-directed.
stringify(value:)keeps its public signature and now delegates togleam/json.to_string(source-compatible, compact output).parsenow takes an explicitdecode.Decoder(value)and returns the decodedvalue, delegating to
gleam/json.parse(from:, using:).JsonErrordistinguishes deterministic syntax failures(
InvalidSyntax(JsonSyntaxError)) from decoder/type failures(
DecoderMismatch(List(decode.DecodeError))), mapped in pure Gleam withoutJavaScript-engine-specific exception text.
src/glendix/js/json_ffi.mjsand its externals (stringify_raw,parse_raw,raw_json_error_message) plustype RawJsonError.Public API / compatibility
This is a breaking change to
parseon the in-development6.0.0line. The olduntyped
parse(from:) -> Result(json.Json, JsonError)is replaced by adecoder-based API; migration examples are documented in
README.md,README.ko.md, andREADME.ja.md.glendix -> mendrawkeeps its declared Hexsource.
Tests
test/glendix/js/json_test.gleamcovers serialization and typed parsing fornull, scalars, escaped strings, arrays, objects, malformed input
(
UnexpectedEndOfInput,UnexpectedByte), decoder mismatch, and a nesteddecoder-error path. The obsolete untyped round-trip test in
test/glendix_test.gleamwas removed.Validation
gleam format --check,gleam check,gleam build --warnings-as-errors,gleam docs build: passed (glendix worktree).gleam test --runtime bun: 60 passed, no failures.dependency-mode.sh check-commit glendix: valid dependency sources.Family Lustre/Mendix browser E2E was not executed in this environment, so no
Mendix/Lustre compatibility claim is made beyond the unit/contract suite. This
module has no in-family consumers.