foldkit-remote 0.10.0 → 0.12.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
@@ -331,13 +331,62 @@ const clientLayer = RemoteServer.memory({
331
331
  }).layer
332
332
  ```
333
333
 
334
- With a server, adapt your configured Effect RPC client instead; the
334
+ With a server, hand Remote the Effect RPC client for `RemoteRpc`; the
335
335
  [server guide](../remote-server/README.md) supplies the other side:
336
336
 
337
337
  ```ts
338
- const clientLayer = Remote.clientLayer(rpcClient)
338
+ import { Effect, Layer } from 'effect'
339
+ import { FetchHttpClient } from 'effect/http'
340
+ import { RpcClient, RpcSerialization } from 'effect/rpc'
341
+ import { RemoteRpc } from 'foldkit-remote'
342
+
343
+ const clientLayer = Layer.unwrap(
344
+ Effect.map(RpcClient.make(RemoteRpc), rpcClient => Remote.clientLayer(rpcClient)),
345
+ ).pipe(
346
+ Layer.provide(RpcClient.layerProtocolHttp({ url: '/rpc' })),
347
+ Layer.provide([RpcSerialization.layerJson, FetchHttpClient.layer]),
348
+ )
349
+ ```
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
+ )
339
361
  ```
340
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
+
385
+ The stock client is accepted as it is. When its transport fails, the call
386
+ fails with its own Remote error (`RemoteReadError`, `RemoteQueryError`,
387
+ `RemoteMutationError`, `RemoteLiveError`), which the UI shows and retries like
388
+ any other failure.
389
+
341
390
  Either is a Layer the runtime provides to `subscriptions` and Commands. The
342
391
  transport itself is not owned by Remote. See
343
392
  [`RemoteServer.memory`](../remote-server/README.md#a-backend-held-in-memory)
@@ -1755,7 +1804,9 @@ The wire schemas (`ReadBatch`, `QueryRequest`, `MutationRequest`,
1755
1804
  `LiveRequirement`, results/errors) and the `RemoteRpc` group are exported.
1756
1805
 
1757
1806
  `Remote.clientLayer(rpcClient, { window? })` adapts an Effect RPC client,
1758
- including live-change mapping. Compatible reads and queries coalesce:
1807
+ including live-change mapping. It takes the client `RpcClient.make(RemoteRpc)`
1808
+ builds, whose calls can also fail with `RpcClientError`; each such failure
1809
+ becomes the call's Remote error rather than a defect. Compatible reads and queries coalesce:
1759
1810
  requirements issued together become one `ReadBatch`, an identical in-flight
1760
1811
  requirement/query is joined, and a failed request releases the coalesced entry.
1761
1812
  A relation request with its own pagination window stays separate because one