foldkit-remote 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -348,6 +348,40 @@ const clientLayer = Layer.unwrap(
348
348
  )
349
349
  ```
350
350
 
351
+ Or, with no Effect RPC on the server, plain JSON over HTTP: each call a `POST`
352
+ of `{ operation, payload }`, answered `{ result }` or `{ error }`.
353
+ [`RemoteServer.answer`](../remote-server/README.md#over-plain-json) is the
354
+ other end. `Remote.json(send)` is the same client over any other way of
355
+ sending the request, a worker or a server running in the page:
356
+
357
+ ```ts
358
+ const overHttp = Remote.clientLayer(
359
+ Remote.http('/remote', { headers: () => ({ 'x-session': 'the session token' }) }),
360
+ )
361
+ ```
362
+
363
+ `headers` is read for each request, so a token that changes reaches the next
364
+ call. Neither carries live data.
365
+
366
+ For a server in a worker or in the page (a sandbox), `foldkit-remote/port`
367
+ speaks Effect's own RPC worker protocol over a `MessagePort`, so live data,
368
+ typed errors and interruption cross it too.
369
+ [`servePort`](../remote-server/README.md#over-a-messageport) is the other end:
370
+
371
+ ```ts
372
+ import { port } from 'foldkit-remote/port'
373
+
374
+ // A new conversation each time the protocol connects: one port here, the other to the server.
375
+ const overPort = port(() => {
376
+ const channel = new MessageChannel()
377
+ worker.port.postMessage({ open: 'remote' }, [channel.port2])
378
+ return channel.port1
379
+ })
380
+ ```
381
+
382
+ It is a `Layer<RemoteClient>` like the others; a port that cannot be set up is
383
+ a defect, not a failed read.
384
+
351
385
  The stock client is accepted as it is. When its transport fails, the call
352
386
  fails with its own Remote error (`RemoteReadError`, `RemoteQueryError`,
353
387
  `RemoteMutationError`, `RemoteLiveError`), which the UI shows and retries like
@@ -500,7 +534,8 @@ When a read sits at `Initial` and you expected data, ask the Model why with
500
534
  `Data.why`; see [Why is it still `Initial`?](#why-is-it-still-initial).
501
535
 
502
536
  `RemoteData.match` is exhaustive, so adding or omitting a state is visible at
503
- compile time.
537
+ compile time. `RemoteData.answered(data)` is whether a read has an answer yet:
538
+ `Ready`, `Refreshing`, `Failed` or `NotFound`, not `Initial` or `Loading`.
504
539
 
505
540
  ### Drawing one: `RemoteData.render`
506
541