feat: add WP.Post / WP.Term / WP.Tax + extend WP.User with REST CRUD#3
Merged
feat: add WP.Post / WP.Term / WP.Tax + extend WP.User with REST CRUD#3
Conversation
Adds typed read/write helpers for the standard WP REST resources, all
sharing the WP.Http nonce auth and a consistent module shape.
New modules:
- WP.Post — list/get/create/update/delete against /wp/v2/posts. Handles
the dynamic shape of the WP REST post object via a `DecodeKeys` record
the caller passes in:
* `taxonomies : List String` — top-level taxonomy keys to extract
(e.g. ["categories", "tags", "genre"]) into a `Dict String (List Int)`.
Supports any registered taxonomy on any post type, not just the
built-in `categories` / `tags`.
* `meta : List String` — post meta keys registered with show_in_rest
to extract from the response's `meta` object into `Dict String Value`.
ListParams supports per-page, page, search, status, ordering, author, plus
per-taxonomy filters (e.g. `?categories=3&genre=5`). Body for create/update
has the same dynamic shape — set `taxonomies` and `meta` dicts to assign
on save.
Includes `taxonomyOf` and `metaOf` accessor helpers.
- WP.Term — list/get/create/update/delete for taxonomy terms. Operates on
any taxonomy via its rest_base ("categories", "tags", "genre", etc.).
Supports term meta via the same DecodeKeys + meta pattern.
- WP.Tax — read-only access to /wp/v2/taxonomies. Decodes the keyed-by-slug
response into a flat `List Taxonomy`.
- WP.User extended — adds restDecoder + DecodeKeys + Body + ListParams and
list/get/create/update/delete against /wp/v2/users. Maps the REST-side
"name" field to displayName, fills missing roles/capabilities with empty
lists for default context, extracts truthy capability keys for edit
context, and supports user meta via the same DecodeKeys pattern.
The flags-side `currentUser` decoder gains `optional "meta" ... Dict.empty`
so the User type stays unified across both sources (PHP-side
Standard_Flags doesn't currently emit user meta, but the structure is in
place if we add it later).
Internal modules (not exposed):
- WP.Query — shared URL query string builder with percent-encoding.
- WP.User.Type — defines the User record + flags-side decoder, used by
both WP.User and WP.Flags to break the import cycle that would
otherwise exist (User → Http → Flags → User).
Dependencies:
- elm/url added for percent-encoding query params.
Tests:
- 36 new tests across QueryTest, PostTest, TermTest, TaxTest, UserTest.
- Total suite: 52 tests, all passing.
Sandbox elm.json adjusted to add elm/url as a direct dep (the sandbox
reads elm-wp's source directly via source-directories so it inherits the
new dep).
Elm fetches package source from github.com/elm/<pkg>/zipball/... at compile time and occasionally those URLs return 502. The first failure on this PR's CI hit exactly that on elm/html. Adds an actions/cache step keyed on elm.json hash. First run still downloads (and could still 502 — re-run if so), but every subsequent run on the same elm.json hits the cache and is immune to GitHub flakes.
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.
Adds typed read/write helpers for the standard WP REST resources, all sharing the WP.Http nonce auth and a consistent module shape.
New modules:
WP.Post — list/get/create/update/delete against /wp/v2/posts. Handles the dynamic shape of the WP REST post object via a
DecodeKeysrecord the caller passes in:taxonomies : List String— top-level taxonomy keys to extract (e.g. ["categories", "tags", "genre"]) into aDict String (List Int). Supports any registered taxonomy on any post type, not just the built-incategories/tags.meta : List String— post meta keys registered with show_in_rest to extract from the response'smetaobject intoDict String Value. ListParams supports per-page, page, search, status, ordering, author, plus per-taxonomy filters (e.g.?categories=3&genre=5). Body for create/update has the same dynamic shape — settaxonomiesandmetadicts to assign on save. IncludestaxonomyOfandmetaOfaccessor helpers.WP.Term — list/get/create/update/delete for taxonomy terms. Operates on any taxonomy via its rest_base ("categories", "tags", "genre", etc.). Supports term meta via the same DecodeKeys + meta pattern.
WP.Tax — read-only access to /wp/v2/taxonomies. Decodes the keyed-by-slug response into a flat
List Taxonomy.WP.User extended — adds restDecoder + DecodeKeys + Body + ListParams and list/get/create/update/delete against /wp/v2/users. Maps the REST-side "name" field to displayName, fills missing roles/capabilities with empty lists for default context, extracts truthy capability keys for edit context, and supports user meta via the same DecodeKeys pattern. The flags-side
currentUserdecoder gainsoptional "meta" ... Dict.emptyso the User type stays unified across both sources (PHP-side Standard_Flags doesn't currently emit user meta, but the structure is in place if we add it later).Internal modules (not exposed):
Dependencies:
Tests:
Sandbox elm.json adjusted to add elm/url as a direct dep (the sandbox reads elm-wp's source directly via source-directories so it inherits the new dep).