Entity
Every member of the Entity namespace: records whose cached copies a write updates everywhere.
Entity describes a record that can sit in many queries at once, and writes every cached copy of it. Import it from the core entry point:
import { } from "@monarcode/effetch-query";Its exports follow, grouped by the guide that covers them, each with its docs. Your editor shows the same docs, with an example, when you hover the name.
Entities
Guide: Entities.
Entity.make
Defines an entity: a schema, and how to get one's id. Define it once, beside the schema, and use that same schema in your queries: a query is searched for the schema itself (or a copy with annotations or checks added), not for another schema with the same fields.
A query is reached through its schema (Query.MakeOptions.schema), or an Effetch endpoint's output; a query without one is skipped. The entity is found in arrays, tuples, records, struct fields (optional and NullOr ones too), unions, nested and recursive (Schema.suspend) schemas, Schema.Class instances, infinite queries' pages, and the decoded side of schemas that transform. It isn't found inside Option, Map or other declarations, nor after a tuple's rest element, nor inside another copy of itself. A value hydrated from the server is reached once a query reads it: until then it's JSON with no schema to search.
Entity.get
Reads the entity whose id is id from the cached queries that hold it, or Option.none() if none does. Where copies differ, the one from the query that fetched or was written last wins. Use it for a detail query's placeholder, to show the list's copy while the detail loads.
Entity.isEntity
Checks whether a value is an Entity. Its value and id types can't be known from the value, so it narrows to Entity<unknown, unknown>.
Entity.remove
Drops the entity whose id is id from every cached query that holds it, as update writes: from arrays and records, from an optionalKey field, which loses its key, and from a field that takes null or undefined (NullOr, optional), which becomes that. Where the schema has no way to leave it out, such as a required field, a tuple's element, a non-empty array's last item or a detail query's whole value, it stays. Totals aren't changed, so invalidate the lists too, and have an infinite query's nextPageParam count from the page's params, not its length.
Entity.set
Writes an entity over every cached copy with the same id, as update does: use it with a mutation's result, in onSuccess. It only replaces copies: a list that doesn't hold the entity yet doesn't get it, so invalidate lists it should join.
Entity.TypeId
The property that marks an Entity.
Entity.update
Writes a value computed from the entity whose id is id into every cached query that holds it: each list, each loaded page, its detail query. In a mutation's optimistic, a failed run puts every one back, as it does Query.update's writes. Unlike Query.update, a query keeps its age: the write doesn't make it fresh, and a query that's invalidated or failed, or has no value or no schema, is left alone, to its next fetch. A query whose value doesn't change isn't written. If f throws, nothing is written and the Effect dies with the defect.
Entity.Entity
A record that many queries hold, such as a todo that's in a list, in a page of a search and in its own detail query, made with make. update, set and remove write it in every cached query whose schema holds it, and get reads it from any of them.
Nothing is normalized: each query keeps its own value, and an entity write maps it, as Query.update does.
Prop
Type
Entity.MakeOptions
Options for make.
Prop
Type