Add Conjure compliant deserialization engine#197
Draft
afloren-palantir wants to merge 1 commit into
Draft
Conversation
Generate changelog in
|
3 tasks
Introduces a schema-driven `deserialize<T>(type, json)` function and `ConjureType` descriptor DSL to conjure-client, addressing the serde layer requested in palantir/conjure-typescript#48, #78, #156. Key behaviours (Conjure wire spec §5.6): - null/absent optional → undefined - null/absent list/set/map → empty collection/object - integer: validates 32-bit signed range (§5.1) - safelong: validates ±(2^53−1) safe-integer range (§5.1) - double: converts "NaN"/"Infinity"/"-Infinity" wire strings to JS numbers (§5.1) - No implicit type casting (§5.6.2: "true" is not boolean) - Unknown union variants pass through unchanged (§4.4 forward-compat) - Unknown object fields ignored (§4.1 forward-compat) - Unknown enum values tolerated (§4.3 forward-compat) Builder functions: stringType, booleanType, integer, safelong, double, rid, uuid, bearertoken, binary, datetime, anyType, enumType, optional, list, set, map, object, union, alias, reference (lazy thunk for recursion). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
eab80d2 to
b78bae2
Compare
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview✨ Features
|
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.
Summary
Adds a schema-driven deserialization engine to
conjure-clientimplementing the Conjure wire spec §5.6, motivated by and addressing palantir/conjure-typescript#48, #78, #156.New exports from
conjure-clientConjureType— discriminated union type descriptor + builder functions (string(),list(item),object(fields),union(variants), etc.)deserialize<T>(type, json)— applies §5.6 coercions recursivelyConjureDeserializeError— thrown on violations, carries the dot/bracket JSON path to the failing field§5.6 behaviours implemented
optionalnull/absent →undefined(addresses Excavator: Update policy-bot config #156: standardise onundefinednotnull)list/set/mapnull → empty collection (addresses Excavator: Upgrade dependencies #78: null collections from server)ConjureDeserializeErrorinteger— validates 32-bit signed range and integrality (§5.1)safelong— validatesNumber.isSafeInteger()range ±(2^53−1) (§5.1)double— converts"NaN"/"Infinity"/"-Infinity"wire strings to actual JSnumbervalues (addresses Update dev dependencies #48: ergonomic double handling)boolean— rejects"true"string, no implicit cast (§5.6.2)unionunknown variant → pass through unchanged (§4.4 forward-compat)enumunknown value → pass through as string (§4.1 forward-compat)Design
The engine is schema-driven: callers supply a
ConjureTypedescriptor built from the builder functions. The companion PR (palantir/conjure-typescript#396) generates_TypeNamedescriptor constants for every type and wires them into service calls automatically when--useDeserializeris set. Flag is opt-in and default-off — no impact on existing code.Test plan
yarn testpasses inpackages/conjure-clientdeserializeandConjureTypebuilders are re-exported from the package root🤖 Generated with Claude Code