(I too got nerdsniped; the extra complexity is almost entirely hidden, but it expands Airglow's product complexity in a way that'd be harder to walk back, so this PR very much for discussion, rather than with the expectation of being merged!)
A non-standard extension to the JSONPatch used for update operations to allow targeting objects within arrays that are in unknown positions using JSONPath.
[
{ "op": "add", "path": "/updatedAt", "value": "{{now}}" },
{ "op": "add", "path": "$.layers[?@.id=='headphones'].equipped", "value": true }
]
Which targets the layers item with "id": "headphones", rather than having to refer by index (which may be unpredictable).
Benefits #
The "array of objects" mechanism being so popular in atproto (most uses of union type, and as mentioned in the RecordPath spec (https://tangled.org/microcosm.blue/RecordPath/blob/main/spec.md#23-arrays-are-unordered-sets) — supporting it allows interacting with things like:
- embeds on bluesky posts
- layers in actor.rpg.generator 😉
- pronouns on app.nearhorizon.actor.pronouns records
- DNS entries on at.marque records
- Your locations on city.atlas.actor.location records
- Labels on Tangled repos
- Any badge.blue attestation records (though I can't think of a good reason to alter those 😅)
- Airglow automations themselves!
Drawbacks #
The extra dependency. JSONPath supports a lot that we don't need here, and provides enough power to cause confusion.
FYI #
- To keep the complexity low, and to maintain predictability/compatibility, only JSONPaths which resolve to a single value will be acted upon.
- There is some interesting potential here though, like the ability to act on multiple records with simple maths (eg.
"$.things[?@.amount < 100]"to remove all things with a low amount) — but this slightly grates with JSON Patch syntax (what does a rename look like with multiple source hits?)
- There is some interesting potential here though, like the ability to act on multiple records with simple maths (eg.
- JSONPath syntax is checked in
validateJsonPatchOps(ie. in the UI) to give fast feedback when making fiddly - I think RecordPath would be perfect here, if it supported array filtering — I've asked the author of the draft for thoughts on the trade-offs of that extra complexity 😊
I'd love to hear your thoughts, but no rush!