Entity / One domain declaration

The shape of it

                        domain module
     Entity.define · Entity.relate · Entity.select · input structs
              (imports neither Remote nor Drizzle)
                 |                              |
                 v                              v
   client                                   server
   Remote.make({ entities })                bind(entities, { tables })
   Data.get(Selection, id)                  source(binding) · query(...)
   Form.make(Entity.input(...))             RemoteServer.mutation(...)
   Crud.editor · Crud.list

Three rules keep the copies from coming back:

  • Relations are declared in one step, with Entity.relate, over Entities that already exist. Entities point at each other, and TypeScript cannot infer two constants that are each typed in terms of the other.
  • A Selection carries its schema and fetches nothing. Remote compiles it into the requirement graph it plans from; a test can decode against it directly.
  • An operation's input is read against the Entity, not derived from it. Entity.input says what each key of the struct means (authorId is the author relation). From that reading follow the form's controls, what an edit screen loads (Entity.selectFor), and how a loaded value fills the form (Entity.valuesFor).

Where to start

  1. Read the foldkit-entity README: declare, relate, select.
  2. Run examples/entity. It reads one declaration from the client through the server into SQLite, then lists, edits, and saves through a form, as a trace and in a browser.
  3. Then the interpreter you need: Remote, Drizzle bind, foldkit-form, foldkit-mixins-form, foldkit-crud.

When not to use it

A Remote application with two entities and no forms is simpler with Remote's own Entity.make and Entity.ref, which still work and can share a domain with Entities declared here. Reach for foldkit-entity when the same domain is about to be written down a second time.