@effect/platform-browser 4.0.0-beta.70 → 4.0.0-beta.72

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.
Files changed (91) hide show
  1. package/dist/BrowserCrypto.d.ts +67 -4
  2. package/dist/BrowserCrypto.d.ts.map +1 -1
  3. package/dist/BrowserCrypto.js +67 -4
  4. package/dist/BrowserCrypto.js.map +1 -1
  5. package/dist/BrowserHttpClient.d.ts +16 -3
  6. package/dist/BrowserHttpClient.d.ts.map +1 -1
  7. package/dist/BrowserHttpClient.js +16 -3
  8. package/dist/BrowserHttpClient.js.map +1 -1
  9. package/dist/BrowserKeyValueStore.d.ts +20 -0
  10. package/dist/BrowserKeyValueStore.d.ts.map +1 -1
  11. package/dist/BrowserKeyValueStore.js +70 -15
  12. package/dist/BrowserKeyValueStore.js.map +1 -1
  13. package/dist/BrowserPersistence.d.ts +19 -0
  14. package/dist/BrowserPersistence.d.ts.map +1 -1
  15. package/dist/BrowserPersistence.js +19 -0
  16. package/dist/BrowserPersistence.js.map +1 -1
  17. package/dist/BrowserRuntime.d.ts +48 -0
  18. package/dist/BrowserRuntime.d.ts.map +1 -1
  19. package/dist/BrowserRuntime.js +16 -0
  20. package/dist/BrowserRuntime.js.map +1 -1
  21. package/dist/BrowserSocket.d.ts +55 -22
  22. package/dist/BrowserSocket.d.ts.map +1 -1
  23. package/dist/BrowserSocket.js +55 -22
  24. package/dist/BrowserSocket.js.map +1 -1
  25. package/dist/BrowserStream.d.ts +36 -21
  26. package/dist/BrowserStream.d.ts.map +1 -1
  27. package/dist/BrowserStream.js +36 -21
  28. package/dist/BrowserStream.js.map +1 -1
  29. package/dist/BrowserWorker.d.ts +17 -0
  30. package/dist/BrowserWorker.d.ts.map +1 -1
  31. package/dist/BrowserWorker.js +50 -18
  32. package/dist/BrowserWorker.js.map +1 -1
  33. package/dist/BrowserWorkerRunner.d.ts +19 -0
  34. package/dist/BrowserWorkerRunner.d.ts.map +1 -1
  35. package/dist/BrowserWorkerRunner.js +45 -14
  36. package/dist/BrowserWorkerRunner.js.map +1 -1
  37. package/dist/Clipboard.d.ts +55 -18
  38. package/dist/Clipboard.d.ts.map +1 -1
  39. package/dist/Clipboard.js +39 -15
  40. package/dist/Clipboard.js.map +1 -1
  41. package/dist/Geolocation.d.ts +63 -19
  42. package/dist/Geolocation.d.ts.map +1 -1
  43. package/dist/Geolocation.js +42 -18
  44. package/dist/Geolocation.js.map +1 -1
  45. package/dist/IndexedDb.d.ts +12 -0
  46. package/dist/IndexedDb.d.ts.map +1 -1
  47. package/dist/IndexedDb.js +12 -0
  48. package/dist/IndexedDb.js.map +1 -1
  49. package/dist/IndexedDbDatabase.d.ts +19 -0
  50. package/dist/IndexedDbDatabase.d.ts.map +1 -1
  51. package/dist/IndexedDbDatabase.js +19 -0
  52. package/dist/IndexedDbDatabase.js.map +1 -1
  53. package/dist/IndexedDbQueryBuilder.d.ts +8 -0
  54. package/dist/IndexedDbQueryBuilder.d.ts.map +1 -1
  55. package/dist/IndexedDbQueryBuilder.js +8 -0
  56. package/dist/IndexedDbQueryBuilder.js.map +1 -1
  57. package/dist/IndexedDbTable.d.ts +55 -17
  58. package/dist/IndexedDbTable.d.ts.map +1 -1
  59. package/dist/IndexedDbTable.js +55 -17
  60. package/dist/IndexedDbTable.js.map +1 -1
  61. package/dist/IndexedDbVersion.d.ts +14 -0
  62. package/dist/IndexedDbVersion.d.ts.map +1 -1
  63. package/dist/IndexedDbVersion.js +14 -0
  64. package/dist/IndexedDbVersion.js.map +1 -1
  65. package/dist/Permissions.d.ts +48 -18
  66. package/dist/Permissions.d.ts.map +1 -1
  67. package/dist/Permissions.js +48 -18
  68. package/dist/Permissions.js.map +1 -1
  69. package/dist/index.d.ts +0 -319
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +0 -319
  72. package/dist/index.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/BrowserCrypto.ts +67 -4
  75. package/src/BrowserHttpClient.ts +16 -3
  76. package/src/BrowserKeyValueStore.ts +70 -15
  77. package/src/BrowserPersistence.ts +66 -9
  78. package/src/BrowserRuntime.ts +48 -0
  79. package/src/BrowserSocket.ts +55 -22
  80. package/src/BrowserStream.ts +33 -18
  81. package/src/BrowserWorker.ts +50 -18
  82. package/src/BrowserWorkerRunner.ts +45 -14
  83. package/src/Clipboard.ts +55 -18
  84. package/src/Geolocation.ts +63 -19
  85. package/src/IndexedDb.ts +12 -0
  86. package/src/IndexedDbDatabase.ts +19 -0
  87. package/src/IndexedDbQueryBuilder.ts +8 -0
  88. package/src/IndexedDbTable.ts +55 -17
  89. package/src/IndexedDbVersion.ts +14 -0
  90. package/src/Permissions.ts +48 -18
  91. package/src/index.ts +0 -319
@@ -1,15 +1,53 @@
1
1
  /**
2
- * Browser-backed persistence layers for Effect's persistence service.
2
+ * IndexedDB-backed persistence layers for browser Effect programs.
3
3
  *
4
- * This module provides IndexedDB implementations of the Effect persistence services for applications that need a
5
- * durable client-side cache, such as remembered query results, offline-capable workflows, or values that should survive
6
- * page reloads. Entries are stored by persistence store id and key in a shared IndexedDB object store, with optional
7
- * expiration timestamps for TTL-based invalidation.
4
+ * `BrowserPersistence` connects the unstable persistence services to the
5
+ * browser's IndexedDB storage. Use it for client-side caches that should
6
+ * survive page reloads, offline-capable workflows, remembered query results,
7
+ * and other application-managed values that can be recomputed or invalidated
8
+ * when storage is unavailable.
8
9
  *
9
- * Because this storage depends on browser IndexedDB, operations can fail when storage is unavailable, quota is exceeded,
10
- * data is cleared by the user or browser, or the payload cannot be structured-cloned by IndexedDB. Expired entries are
11
- * removed lazily when they are read, so this module is best suited for application-managed cached objects rather than
12
- * security-sensitive or authoritative data.
10
+ * **Mental model**
11
+ *
12
+ * - {@link layerIndexedDb} provides the higher-level `Persistence` service by
13
+ * composing the IndexedDB backing layer with the core persistence layer.
14
+ * - {@link layerBackingIndexedDb} provides only `BackingPersistence` for code
15
+ * that composes persistence services manually.
16
+ * - Entries live in one IndexedDB database, defaulting to
17
+ * `"effect_persistence"`, and one object store keyed by `[storeId, key]`.
18
+ * - The `storeId` namespaces persisted request results; the key identifies one
19
+ * entry inside that store.
20
+ * - Finite TTLs are stored as expiration timestamps and expired entries are
21
+ * removed lazily when they are read.
22
+ *
23
+ * **Common tasks**
24
+ *
25
+ * - Provide browser persistence to `PersistedCache` or other persistence
26
+ * workflows with {@link layerIndexedDb}.
27
+ * - Isolate tests, apps, or migrations by passing a custom `database` option.
28
+ * - Use {@link layerBackingIndexedDb} when another layer should decide how to
29
+ * construct the higher-level `Persistence` service.
30
+ *
31
+ * **Gotchas**
32
+ *
33
+ * - This module requires browser IndexedDB and stores data per origin.
34
+ * - Opening IndexedDB is defected during layer acquisition if the database
35
+ * cannot be opened; later store operations report `PersistenceError`.
36
+ * - Values must be structured-cloneable objects, and writes can fail because of
37
+ * quota limits, browser settings, private browsing modes, or user-cleared
38
+ * storage.
39
+ * - Lazy TTL cleanup makes this suitable for caches, not for authoritative or
40
+ * security-sensitive state.
41
+ *
42
+ * **Example** (Providing browser persistence)
43
+ *
44
+ * ```ts
45
+ * import { BrowserPersistence } from "@effect/platform-browser"
46
+ *
47
+ * export const PersistenceLive = BrowserPersistence.layerIndexedDb({
48
+ * database: "my-app-cache"
49
+ * })
50
+ * ```
13
51
  *
14
52
  * @since 4.0.0
15
53
  */
@@ -23,6 +61,25 @@ import * as Persistence from "effect/unstable/persistence/Persistence"
23
61
  /**
24
62
  * Creates a `BackingPersistence` layer backed by IndexedDB, optionally using the provided database name.
25
63
  *
64
+ * **When to use**
65
+ *
66
+ * Use when composing persistence manually and the lower-level
67
+ * `BackingPersistence` service should be backed by browser IndexedDB.
68
+ *
69
+ * **Details**
70
+ *
71
+ * The database name defaults to `"effect_persistence"`. Entries are stored by
72
+ * persistence store id and key in a shared object store, and TTL expiration is
73
+ * checked when values are read.
74
+ *
75
+ * **Gotchas**
76
+ *
77
+ * Opening the database is defected during layer acquisition if IndexedDB is
78
+ * unavailable or cannot be opened. Store operations report `PersistenceError`
79
+ * for IndexedDB request, transaction, quota, and structured-clone failures.
80
+ *
81
+ * @see {@link layerIndexedDb} for providing the higher-level `Persistence` service
82
+ *
26
83
  * @category layers
27
84
  * @since 4.0.0
28
85
  */
@@ -28,6 +28,22 @@ import { makeRunMain, type Teardown } from "effect/Runtime"
28
28
  /**
29
29
  * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
30
30
  *
31
+ * **When to use**
32
+ *
33
+ * Use to launch a browser page, single-page application, demo, or browser test
34
+ * harness as a root Effect program.
35
+ *
36
+ * **Details**
37
+ *
38
+ * Supports both direct and curried call forms. Options are forwarded to
39
+ * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
40
+ * behavior.
41
+ *
42
+ * **Gotchas**
43
+ *
44
+ * The `beforeunload` interruption is best-effort. Browser teardown may prevent
45
+ * asynchronous finalizers, network work, timers, or prompts from completing.
46
+ *
31
47
  * @category Runtime
32
48
  * @since 4.0.0
33
49
  */
@@ -35,6 +51,22 @@ export const runMain: {
35
51
  /**
36
52
  * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
37
53
  *
54
+ * **When to use**
55
+ *
56
+ * Use to launch a browser page, single-page application, demo, or browser test
57
+ * harness as a root Effect program.
58
+ *
59
+ * **Details**
60
+ *
61
+ * Supports both direct and curried call forms. Options are forwarded to
62
+ * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
63
+ * behavior.
64
+ *
65
+ * **Gotchas**
66
+ *
67
+ * The `beforeunload` interruption is best-effort. Browser teardown may prevent
68
+ * asynchronous finalizers, network work, timers, or prompts from completing.
69
+ *
38
70
  * @category Runtime
39
71
  * @since 4.0.0
40
72
  */
@@ -47,6 +79,22 @@ export const runMain: {
47
79
  /**
48
80
  * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
49
81
  *
82
+ * **When to use**
83
+ *
84
+ * Use to launch a browser page, single-page application, demo, or browser test
85
+ * harness as a root Effect program.
86
+ *
87
+ * **Details**
88
+ *
89
+ * Supports both direct and curried call forms. Options are forwarded to
90
+ * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
91
+ * behavior.
92
+ *
93
+ * **Gotchas**
94
+ *
95
+ * The `beforeunload` interruption is best-effort. Browser teardown may prevent
96
+ * asynchronous finalizers, network work, timers, or prompts from completing.
97
+ *
50
98
  * @category Runtime
51
99
  * @since 4.0.0
52
100
  */
@@ -1,26 +1,40 @@
1
1
  /**
2
- * Browser WebSocket layers for Effect sockets.
3
- *
4
- * This module provides the browser entry point for `Socket.Socket` values
5
- * backed by the platform `WebSocket` implementation. Use `layerWebSocket` when
6
- * client-side Effect programs, browser tests, RPC transports, or realtime UI
7
- * features need a bidirectional socket connected to a WebSocket URL, and use
8
- * `layerWebSocketConstructor` when lower-level socket APIs need access to the
9
- * browser constructor service.
10
- *
11
- * Browser WebSocket rules still apply. Connections are created through
12
- * `globalThis.WebSocket`, so URL schemes, subprotocol negotiation, mixed-content
13
- * blocking, cookies, authentication, CORS-like origin checks, and extension
14
- * negotiation are controlled by the browser and server rather than by Effect.
15
- * Close events are translated into socket errors unless the provided
16
- * `closeCodeIsError` predicate classifies the close code as clean, which is
17
- * useful for protocols that use application-specific close codes.
18
- *
19
- * Messages are delivered as strings or binary `Uint8Array` values; browser
20
- * `Blob` messages are read into bytes before they reach the socket handler.
21
- * Outgoing data should already be serialized to a string or bytes, and protocol
22
- * frames that represent an intentional close should be sent as `CloseEvent`
23
- * values so the underlying `WebSocket.close` code and reason are preserved.
2
+ * Provide Effect sockets backed by the browser `WebSocket` implementation.
3
+ *
4
+ * This module is the browser entry point for Effect's socket abstraction. Use
5
+ * {@link layerWebSocket} when a client-side Effect program needs a complete
6
+ * `Socket.Socket` connected to a WebSocket URL. Use
7
+ * {@link layerWebSocketConstructor} when lower-level socket code only needs the
8
+ * browser-backed constructor service.
9
+ *
10
+ * ## Mental model
11
+ *
12
+ * `layerWebSocket` delegates socket behavior to Effect's WebSocket support and
13
+ * supplies `globalThis.WebSocket` as the constructor. Incoming browser messages
14
+ * are normalized to strings or binary `Uint8Array` values. Browser `Blob`
15
+ * messages are read into bytes before they reach the socket consumer.
16
+ *
17
+ * Outgoing data should already be serialized to a string or bytes. To close the
18
+ * underlying browser socket with a specific code and reason, send a
19
+ * `CloseEvent` value so the close metadata is preserved.
20
+ *
21
+ * ## Common tasks
22
+ *
23
+ * - Connect RPC transports, browser tests, or realtime UI features to a
24
+ * WebSocket URL with {@link layerWebSocket}.
25
+ * - Provide only the browser constructor service with
26
+ * {@link layerWebSocketConstructor} when another socket layer builds the
27
+ * connection.
28
+ * - Customize `closeCodeIsError` for protocols that treat specific close codes
29
+ * as normal completion instead of socket failure.
30
+ *
31
+ * ## Gotchas
32
+ *
33
+ * Browser WebSocket rules still apply. URL schemes, subprotocol negotiation,
34
+ * mixed-content blocking, cookies, authentication, server origin checks, and
35
+ * extension negotiation are controlled by the browser and server rather than by
36
+ * Effect. Close events become socket errors unless `closeCodeIsError`
37
+ * classifies the close code as clean.
24
38
  *
25
39
  * @since 4.0.0
26
40
  */
@@ -30,6 +44,25 @@ import * as Socket from "effect/unstable/socket/Socket"
30
44
  /**
31
45
  * Creates a `Socket` layer connected to the given URL using the browser `WebSocket` constructor.
32
46
  *
47
+ * **When to use**
48
+ *
49
+ * Use when browser or client-side code needs a complete `Socket` layer
50
+ * connected to a WebSocket URL.
51
+ *
52
+ * **Details**
53
+ *
54
+ * Delegates socket construction to `Socket.makeWebSocket` and provides the
55
+ * browser-backed `WebSocketConstructor` service.
56
+ *
57
+ * **Gotchas**
58
+ *
59
+ * Browser WebSocket rules still control URL schemes, mixed-content blocking,
60
+ * cookies, authentication, origin checks, subprotocols, and extensions. Close
61
+ * events are errors unless `closeCodeIsError` classifies the close code as
62
+ * clean.
63
+ *
64
+ * @see {@link layerWebSocketConstructor} for providing only the browser constructor service
65
+ *
33
66
  * @category layers
34
67
  * @since 4.0.0
35
68
  */
@@ -1,25 +1,40 @@
1
1
  /**
2
- * Browser `Stream` constructors for DOM event targets.
2
+ * Convert browser DOM events into Effect streams.
3
3
  *
4
- * This module provides typed helpers for turning `window.addEventListener` and
5
- * `document.addEventListener` callbacks into Effect `Stream`s. They are useful
6
- * for UI and runtime signals such as resize, visibility, keyboard, pointer,
7
- * focus, online / offline, and other browser events that should be composed
8
- * with Effect stream operators and finalized with the consuming fiber.
4
+ * This module provides typed constructors for listening to `window` and
5
+ * `document` events from Effect programs. Use {@link fromEventListenerWindow}
6
+ * for viewport, network, focus, pointer, keyboard, and other `Window` events,
7
+ * and use {@link fromEventListenerDocument} for document lifecycle,
8
+ * visibility, selection, fullscreen, and other `Document` events.
9
9
  *
10
- * Browser events are push-based `EventTarget` notifications, so they do not
11
- * apply Web Streams backpressure to the browser event source. Events are
12
- * buffered until downstream pulls them; the default buffer is unbounded, so
13
- * high-frequency sources like scroll, pointermove, or mousemove should usually
14
- * set `bufferSize` and use stream operators that sample, debounce, throttle, or
15
- * drop work as appropriate.
10
+ * ## Mental model
16
11
  *
17
- * These helpers are for DOM events, not for adapting `ReadableStream` request
18
- * or response bodies. Fetch bodies follow the Web Streams body rules, including
19
- * single-consumer locking and disturbed bodies after reads, and should be
20
- * handled with body-specific HTTP or Web Streams APIs instead. When using the
21
- * browser `once` option, pair the stream with `Stream.take(1)` if a finite
22
- * stream is required.
12
+ * Each constructor registers a DOM `addEventListener` callback when the stream
13
+ * is consumed and removes it when the stream is finalized. Browser events are
14
+ * push-based `EventTarget` notifications, so the browser does not slow down the
15
+ * event source when downstream stream processing is busy. Events are buffered
16
+ * inside the stream until a consumer pulls them.
17
+ *
18
+ * ## Common tasks
19
+ *
20
+ * - Track browser state such as resize, online / offline, focus, visibility, or
21
+ * pointer activity with Effect stream operators.
22
+ * - Scope DOM listeners to a fiber so they are removed when the consuming
23
+ * effect is interrupted or completes.
24
+ * - Set `bufferSize` for bursty event sources before applying sampling,
25
+ * throttling, debouncing, or dropping logic downstream.
26
+ *
27
+ * ## Gotchas
28
+ *
29
+ * The default buffer is unbounded. High-frequency sources such as `scroll`,
30
+ * `pointermove`, or `mousemove` should usually specify `bufferSize` and reduce
31
+ * the event rate with stream operators.
32
+ *
33
+ * These helpers are for DOM events, not for `ReadableStream` request or
34
+ * response bodies. Fetch bodies follow Web Streams rules such as
35
+ * single-consumer locking and disturbed bodies after reads. When using the DOM
36
+ * `once` option, also use `Stream.take(1)` if the consuming code needs a finite
37
+ * stream.
23
38
  *
24
39
  * @since 4.0.0
25
40
  */
@@ -1,22 +1,37 @@
1
1
  /**
2
- * Parent-side browser support for Effect workers.
3
- *
4
- * This module provides the `WorkerPlatform` used by browser applications that
5
- * spawn or connect to `Worker`, `SharedWorker`, and `MessagePort` endpoints
6
- * through Effect's worker protocol. Pair it with `BrowserWorkerRunner` in the
7
- * worker entrypoint when building worker-backed RPC clients, moving CPU-bound
8
- * work off the main thread, isolating browser-only services, or adapting an
9
- * existing `MessageChannel` in tests and custom transports.
10
- *
11
- * Dedicated workers communicate through the worker object itself, while shared
12
- * workers communicate through `worker.port`; raw `MessagePort` values are also
13
- * accepted and are started when supported. Messages are posted with the browser
14
- * structured-clone algorithm, so payloads must be cloneable by the target
15
- * runtime. Transfer lists can avoid copying values such as `ArrayBuffer` or
16
- * `MessagePort`, but transferring moves ownership away from the sender and
17
- * invalid or mismatched transferables can fail the send. Scope finalization
18
- * sends the worker close signal over the port; the application that created a
19
- * dedicated `Worker` remains responsible for any broader lifecycle such as
2
+ * Parent-side browser platform for running Effect workers.
3
+ *
4
+ * This module provides the `WorkerPlatform` used by browser code that spawns or
5
+ * connects to `Worker`, `SharedWorker`, and `MessagePort` endpoints through
6
+ * Effect's worker protocol. Pair it with `BrowserWorkerRunner` in the worker
7
+ * entrypoint when building worker-backed RPC clients, moving CPU-bound work off
8
+ * the main thread, isolating browser-only services, or adapting an existing
9
+ * `MessageChannel` in tests.
10
+ *
11
+ * **Mental model**
12
+ *
13
+ * Browser worker communication is normalized to a message port. Dedicated
14
+ * workers post messages on the worker object itself, shared workers post
15
+ * through `worker.port`, and raw `MessagePort` values can be supplied directly.
16
+ * `layerPlatform` provides only the browser platform, while `layer` combines
17
+ * the platform with a `Spawner` that creates a worker endpoint for each worker
18
+ * id.
19
+ *
20
+ * **Common tasks**
21
+ *
22
+ * Use `layer` when parent code should both provide browser worker messaging and
23
+ * define how workers are spawned. Use `layerPlatform` when a spawner is already
24
+ * provided elsewhere. Return a `MessagePort` from the spawner for tests or
25
+ * custom channels, a `Worker` for dedicated workers, or a `SharedWorker` when
26
+ * multiple browser contexts should share one worker runtime.
27
+ *
28
+ * **Gotchas**
29
+ *
30
+ * Messages use the browser structured-clone algorithm, so payloads and transfer
31
+ * lists must be accepted by the target runtime. Transferring an `ArrayBuffer` or
32
+ * `MessagePort` moves ownership away from the sender. Scope finalization sends
33
+ * the worker close signal over the port, but code that created a dedicated
34
+ * `Worker` remains responsible for broader lifecycle concerns such as
20
35
  * terminating it.
21
36
  *
22
37
  * @since 4.0.0
@@ -31,6 +46,23 @@ import { WorkerError, WorkerReceiveError } from "effect/unstable/workers/WorkerE
31
46
  /**
32
47
  * Creates browser worker layers by combining the default `WorkerPlatform` with a spawner for `Worker`, `SharedWorker`, or `MessagePort` instances.
33
48
  *
49
+ * **When to use**
50
+ *
51
+ * Use when browser parent or client code needs both the browser
52
+ * `WorkerPlatform` and a `Spawner` from one layer.
53
+ *
54
+ * **Details**
55
+ *
56
+ * The `spawn` callback receives the numeric worker id and may return a
57
+ * `Worker`, `SharedWorker`, or `MessagePort`.
58
+ *
59
+ * **Gotchas**
60
+ *
61
+ * Scope finalization sends the worker close protocol over the port. Dedicated
62
+ * workers created by `spawn` are not terminated by this layer.
63
+ *
64
+ * @see {@link layerPlatform} for providing only the browser worker platform
65
+ *
34
66
  * @category layers
35
67
  * @since 4.0.0
36
68
  */
@@ -1,21 +1,33 @@
1
1
  /**
2
- * Browser runtime support for Effect worker runners.
2
+ * Runner-side browser platform for Effect worker handlers.
3
3
  *
4
- * This module is intended for code that is already executing in a browser
5
- * worker context, or for tests and adapters that supply a `MessagePort` or
6
- * `Window` endpoint directly. It provides the `WorkerRunnerPlatform` used by
7
- * `WorkerRunner` and `RpcServer.layerProtocolWorkerRunner` to receive parent
8
- * or client requests, run Effect handlers, and send responses through the
9
- * browser `postMessage` channel.
4
+ * This module is for code already executing inside a browser worker, or for
5
+ * tests and adapters that pass a `MessagePort` or `Window` endpoint directly.
6
+ * It provides the `WorkerRunnerPlatform` used by `WorkerRunner` and protocols
7
+ * such as `RpcServer.layerProtocolWorkerRunner` to receive parent or client
8
+ * requests, run Effect handlers, and post responses back through the browser
9
+ * messaging channel.
10
10
  *
11
- * Use it with `BrowserWorker` when a browser application needs to move RPC
11
+ * **Mental model**
12
+ *
13
+ * Dedicated workers use the ambient `self` endpoint. Shared workers receive one
14
+ * `MessagePort` per `onconnect` event, and this module caches ports that arrive
15
+ * before the runner layer starts. `layer` reads from the global worker `self`;
16
+ * `make` and `layerMessagePort` are for explicit endpoints supplied by tests,
17
+ * custom channels, or adapter code.
18
+ *
19
+ * **Common tasks**
20
+ *
21
+ * Pair this module with `BrowserWorker` in the parent page when moving RPC
12
22
  * handlers, CPU-bound computations, or browser-only services into a dedicated
13
- * worker or shared worker. Dedicated workers communicate through the current
14
- * `self` endpoint; shared workers accept multiple `onconnect` ports and cache
15
- * ports that connect before the runner layer starts. Messages still use the
16
- * browser structured-clone algorithm, so payload schemas, transfer lists,
17
- * `messageerror` events, and the lifetime of each `MessagePort` must be
18
- * considered when crossing worker boundaries.
23
+ * worker or shared worker. Use `layer` in normal worker entry points and
24
+ * `layerMessagePort` when a test or integration already owns the transport.
25
+ *
26
+ * **Gotchas**
27
+ *
28
+ * Payloads and transfer lists must satisfy the browser structured-clone
29
+ * algorithm. `messageerror` and `error` events fail the runner, and each
30
+ * connected `MessagePort` is closed when its scope finalizes.
19
31
  *
20
32
  * @since 4.0.0
21
33
  */
@@ -173,6 +185,25 @@ export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatf
173
185
  /**
174
186
  * Layer that provides a browser `WorkerRunnerPlatform` using the global `self` worker context.
175
187
  *
188
+ * **When to use**
189
+ *
190
+ * Use when a browser worker entry point uses the ambient `self` object as the
191
+ * worker transport.
192
+ *
193
+ * **Details**
194
+ *
195
+ * Delegates to `make(self)` and provides the runner-side platform used by
196
+ * protocols such as `RpcServer.layerProtocolWorkerRunner`.
197
+ *
198
+ * **Gotchas**
199
+ *
200
+ * This layer depends on the browser worker global `self`. Use
201
+ * `layerMessagePort` when the transport is an explicit `MessagePort` or
202
+ * `Window`.
203
+ *
204
+ * @see {@link make} for constructing a runner platform from an explicit endpoint
205
+ * @see {@link layerMessagePort} for providing a platform from an explicit endpoint
206
+ *
176
207
  * @category layers
177
208
  * @since 4.0.0
178
209
  */
package/src/Clipboard.ts CHANGED
@@ -1,19 +1,35 @@
1
1
  /**
2
- * Browser clipboard service for Effect programs.
3
- *
4
- * This module wraps the browser `navigator.clipboard` API in a `Clipboard`
5
- * service so client-side applications can read, write, and clear clipboard
6
- * contents as typed Effects. It is useful for common UI workflows such as copy
7
- * buttons, paste/import actions, sharing generated text, and moving rich
8
- * clipboard payloads like `Blob`-backed `ClipboardItem`s through an Effect
9
- * environment.
10
- *
11
- * Browser clipboard rules still apply. Clipboard access generally requires a
12
- * secure context, and browsers may require a user gesture, permission prompt, or
13
- * active focused document before reads or writes are allowed. Support also
14
- * varies by operation and payload type: text helpers are the most portable,
15
- * while `ClipboardItem` and non-text MIME types may be unavailable or restricted
16
- * in some browsers. Failed browser operations are surfaced as `ClipboardError`.
2
+ * Browser clipboard integration for Effect programs.
3
+ *
4
+ * This module provides a `Clipboard` service backed by `navigator.clipboard`.
5
+ * It keeps copy, paste, clear, and rich clipboard operations inside the Effect
6
+ * environment so browser UI code can require clipboard capability without
7
+ * calling the global API directly. Text helpers cover portable copy and paste
8
+ * flows, while `read`, `write`, and `writeBlob` expose `ClipboardItem` payloads
9
+ * for browsers that support richer MIME types.
10
+ *
11
+ * **Mental model**
12
+ *
13
+ * `Clipboard` is a capability service. Application code depends on the service
14
+ * tag, {@link layer} supplies the live browser implementation, and {@link make}
15
+ * builds custom implementations for tests, unsupported browsers, or constrained
16
+ * capabilities. Browser failures are converted to {@link ClipboardError}.
17
+ *
18
+ * **Common tasks**
19
+ *
20
+ * - Provide {@link layer} near the browser application edge.
21
+ * - Use `writeString` for copy buttons and generated text.
22
+ * - Use `readString` for paste or import workflows.
23
+ * - Use `write` or `writeBlob` for rich clipboard payloads when
24
+ * `ClipboardItem` is available.
25
+ * - Use `clear` to replace the clipboard with an empty string.
26
+ *
27
+ * **Gotchas**
28
+ *
29
+ * Clipboard access requires a secure context in modern browsers and may also
30
+ * require user activation, permissions, and a focused document. Support differs
31
+ * between reads, writes, text, and custom MIME payloads, so feature detection or
32
+ * graceful fallback is often needed around `ClipboardItem` usage.
17
33
  *
18
34
  * @since 4.0.0
19
35
  */
@@ -26,7 +42,20 @@ const TypeId = "~@effect/platform-browser/Clipboard"
26
42
  const ErrorTypeId = "~@effect/platform-browser/Clipboard/ClipboardError"
27
43
 
28
44
  /**
29
- * Service interface for reading from, writing to, and clearing the browser clipboard.
45
+ * Defines the service interface for reading from, writing to, and clearing the browser clipboard.
46
+ *
47
+ * **Details**
48
+ *
49
+ * `read` and `write` work with `ClipboardItem` arrays. `readString` and
50
+ * `writeString` use text, `writeBlob` writes one `Blob`, and `clear` writes an
51
+ * empty string.
52
+ *
53
+ * **Gotchas**
54
+ *
55
+ * Clipboard access generally requires a secure context and may require user
56
+ * activation, permissions, or a focused document. `ClipboardItem` and non-text
57
+ * MIME type support varies by browser. Failed browser operations are surfaced
58
+ * as `ClipboardError`.
30
59
  *
31
60
  * @category models
32
61
  * @since 4.0.0
@@ -55,7 +84,15 @@ export class ClipboardError extends Data.TaggedError("ClipboardError")<{
55
84
  }
56
85
 
57
86
  /**
58
- * Service tag for the browser `Clipboard` service.
87
+ * Service tag for browser clipboard capabilities.
88
+ *
89
+ * **When to use**
90
+ *
91
+ * Use when an Effect needs to require or provide clipboard capabilities through
92
+ * the context.
93
+ *
94
+ * @see {@link make} for building a custom clipboard service
95
+ * @see {@link layer} for providing the browser-backed clipboard service
59
96
  *
60
97
  * @category services
61
98
  * @since 4.0.0
@@ -79,7 +116,7 @@ export const make = (
79
116
  })
80
117
 
81
118
  /**
82
- * A layer that directly interfaces with the navigator.clipboard api
119
+ * Layer that directly interfaces with the browser Clipboard API.
83
120
  *
84
121
  * @category layers
85
122
  * @since 4.0.0