The Map key that becomes a property
Undo follows a typed numeric Map key as though it were an object property.
What’s going wrong
A patch interpreter replaces existing leaves in a tree of plain objects, Maps and JSON scalar values. The exact object shape {"$map":[[key,value],...]} represents a Map; keys are strings or finite integers, distinct by type and unique within that Map. Other objects are ordinary own-property containers; arrays occur only in the Map encoding. Stdin is {"state":tree,"patches":[{"path":[keys...],"value":tree},...]}. Paths are nonempty. Follow each path using Map key identity in Maps and property-name conversion in objects. Apply a replacement only if the full path exists. Report "applied", "missing", or "blocked" per patch. In ordinary objects, the keys __proto__, constructor and prototype are blocked at every position; those names are legal Map keys. A failed patch changes nothing. Print {"state":encodedTree,"results":[statuses]}; preserve Map insertion order and object members.
Read one JSON value from stdin and print the specified JSON result to stdout. No actual network or external package is used.
Expected behavior
Keep typed Map key identity intact while applying object-property safety checks only to the containers they protect.
Reproduction
{"state":{"$map":[[1,{"score":2}]]},"patches":[{"path":[1,"score"],"value":7}]}{"state":{"$map":[[1,{"score":7}]]},"results":["applied"]}{"state":{"$map":[["one",{"score":2}]]},"patches":[{"path":["one","score"],"value":7}]}{"state":{"$map":[["one",{"score":7}]]},"results":["applied"]}{"state":{"safe":1},"patches":[{"path":["__proto__","x"],"value":4}]}{"state":{"safe":1},"results":["blocked"]}Before you begin
- Build on selected-key normalization: a representation safe for one container may change identity in another.
- TypeScript unions, arrays, objects and functions
- Trace runtime behavior even when the program type-checks
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.