@effect/platform-browser 4.0.0-beta.66 → 4.0.0-beta.68

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 +23 -0
  2. package/dist/BrowserCrypto.d.ts.map +1 -0
  3. package/dist/BrowserCrypto.js +61 -0
  4. package/dist/BrowserCrypto.js.map +1 -0
  5. package/dist/BrowserHttpClient.d.ts +23 -13
  6. package/dist/BrowserHttpClient.d.ts.map +1 -1
  7. package/dist/BrowserHttpClient.js +49 -12
  8. package/dist/BrowserHttpClient.js.map +1 -1
  9. package/dist/BrowserKeyValueStore.d.ts +15 -8
  10. package/dist/BrowserKeyValueStore.d.ts.map +1 -1
  11. package/dist/BrowserKeyValueStore.js +128 -4
  12. package/dist/BrowserKeyValueStore.js.map +1 -1
  13. package/dist/BrowserPersistence.d.ts +6 -2
  14. package/dist/BrowserPersistence.d.ts.map +1 -1
  15. package/dist/BrowserPersistence.js +6 -2
  16. package/dist/BrowserPersistence.js.map +1 -1
  17. package/dist/BrowserRuntime.d.ts +31 -4
  18. package/dist/BrowserRuntime.d.ts.map +1 -1
  19. package/dist/BrowserRuntime.js +3 -1
  20. package/dist/BrowserRuntime.js.map +1 -1
  21. package/dist/BrowserSocket.d.ts +31 -6
  22. package/dist/BrowserSocket.d.ts.map +1 -1
  23. package/dist/BrowserSocket.js +31 -6
  24. package/dist/BrowserSocket.js.map +1 -1
  25. package/dist/BrowserStream.d.ts +25 -3
  26. package/dist/BrowserStream.d.ts.map +1 -1
  27. package/dist/BrowserStream.js +25 -3
  28. package/dist/BrowserStream.js.map +1 -1
  29. package/dist/BrowserWorker.d.ts +8 -4
  30. package/dist/BrowserWorker.d.ts.map +1 -1
  31. package/dist/BrowserWorker.js +29 -5
  32. package/dist/BrowserWorker.js.map +1 -1
  33. package/dist/BrowserWorkerRunner.d.ts +12 -6
  34. package/dist/BrowserWorkerRunner.d.ts.map +1 -1
  35. package/dist/BrowserWorkerRunner.js +31 -7
  36. package/dist/BrowserWorkerRunner.js.map +1 -1
  37. package/dist/Clipboard.d.ts +35 -11
  38. package/dist/Clipboard.d.ts.map +1 -1
  39. package/dist/Clipboard.js +31 -9
  40. package/dist/Clipboard.js.map +1 -1
  41. package/dist/Geolocation.d.ts +52 -18
  42. package/dist/Geolocation.d.ts.map +1 -1
  43. package/dist/Geolocation.js +44 -14
  44. package/dist/Geolocation.js.map +1 -1
  45. package/dist/IndexedDb.d.ts +38 -11
  46. package/dist/IndexedDb.d.ts.map +1 -1
  47. package/dist/IndexedDb.js +35 -13
  48. package/dist/IndexedDb.js.map +1 -1
  49. package/dist/IndexedDbDatabase.d.ts +57 -10
  50. package/dist/IndexedDbDatabase.d.ts.map +1 -1
  51. package/dist/IndexedDbDatabase.js +36 -3
  52. package/dist/IndexedDbDatabase.js.map +1 -1
  53. package/dist/IndexedDbQueryBuilder.d.ts +102 -28
  54. package/dist/IndexedDbQueryBuilder.d.ts.map +1 -1
  55. package/dist/IndexedDbQueryBuilder.js +56 -26
  56. package/dist/IndexedDbQueryBuilder.js.map +1 -1
  57. package/dist/IndexedDbTable.d.ts +57 -13
  58. package/dist/IndexedDbTable.d.ts.map +1 -1
  59. package/dist/IndexedDbTable.js +21 -1
  60. package/dist/IndexedDbTable.js.map +1 -1
  61. package/dist/IndexedDbVersion.d.ts +37 -7
  62. package/dist/IndexedDbVersion.d.ts.map +1 -1
  63. package/dist/IndexedDbVersion.js +3 -1
  64. package/dist/IndexedDbVersion.js.map +1 -1
  65. package/dist/Permissions.d.ts +38 -11
  66. package/dist/Permissions.d.ts.map +1 -1
  67. package/dist/Permissions.js +33 -8
  68. package/dist/Permissions.js.map +1 -1
  69. package/dist/index.d.ts +334 -11
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +334 -11
  72. package/dist/index.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/BrowserCrypto.ts +71 -0
  75. package/src/BrowserHttpClient.ts +53 -14
  76. package/src/BrowserKeyValueStore.ts +144 -6
  77. package/src/BrowserPersistence.ts +19 -3
  78. package/src/BrowserRuntime.ts +31 -4
  79. package/src/BrowserSocket.ts +31 -6
  80. package/src/BrowserStream.ts +25 -3
  81. package/src/BrowserWorker.ts +29 -5
  82. package/src/BrowserWorkerRunner.ts +31 -7
  83. package/src/Clipboard.ts +35 -11
  84. package/src/Geolocation.ts +52 -18
  85. package/src/IndexedDb.ts +39 -21
  86. package/src/IndexedDbDatabase.ts +57 -10
  87. package/src/IndexedDbQueryBuilder.ts +171 -58
  88. package/src/IndexedDbTable.ts +57 -13
  89. package/src/IndexedDbVersion.ts +37 -7
  90. package/src/Permissions.ts +38 -11
  91. package/src/index.ts +335 -11
@@ -1,16 +1,34 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser-backed `KeyValueStore` layers for Effect programs.
3
+ *
4
+ * This module provides `KeyValueStore` implementations backed by the browser's
5
+ * synchronous Web Storage APIs: `localStorage` for origin-scoped data that
6
+ * persists across page reloads and browser sessions, and `sessionStorage` for
7
+ * page-session data that is cleared when that tab or window's page session
8
+ * ends. They are useful for small client-side values such as user preferences,
9
+ * feature flags, lightweight caches, persisted drafts, or session-only workflow
10
+ * state.
11
+ *
12
+ * Web Storage is only available in browser environments and is scoped by origin.
13
+ * Browsers may deny access in private modes or restricted contexts, and writes
14
+ * can fail when storage quotas are exceeded. The API stores strings and runs
15
+ * synchronously on the main thread, so prefer it for small payloads and avoid
16
+ * treating it as a database or a secure place for sensitive data.
17
+ *
18
+ * @since 4.0.0
3
19
  */
4
- import type * as Layer from "effect/Layer"
20
+ import * as Effect from "effect/Effect"
21
+ import * as Layer from "effect/Layer"
5
22
  import * as KeyValueStore from "effect/unstable/persistence/KeyValueStore"
23
+ import { IndexedDb } from "./IndexedDb.ts"
6
24
 
7
25
  /**
8
26
  * Creates a `KeyValueStore` layer that uses the browser's `localStorage` api.
9
27
  *
10
28
  * Values are stored between sessions.
11
29
  *
12
- * @since 1.0.0
13
- * @category Layers
30
+ * @category layers
31
+ * @since 4.0.0
14
32
  */
15
33
  export const layerLocalStorage: Layer.Layer<KeyValueStore.KeyValueStore> = KeyValueStore.layerStorage(() =>
16
34
  globalThis.localStorage
@@ -21,9 +39,129 @@ export const layerLocalStorage: Layer.Layer<KeyValueStore.KeyValueStore> = KeyVa
21
39
  *
22
40
  * Values are stored only for the current session.
23
41
  *
24
- * @since 1.0.0
25
- * @category Layers
42
+ * @category layers
43
+ * @since 4.0.0
26
44
  */
27
45
  export const layerSessionStorage: Layer.Layer<KeyValueStore.KeyValueStore> = KeyValueStore.layerStorage(() =>
28
46
  globalThis.sessionStorage
29
47
  )
48
+
49
+ /**
50
+ * Creates a `KeyValueStore` layer backed by IndexedDB.
51
+ *
52
+ * @category layers
53
+ * @since 4.0.0
54
+ */
55
+ export const layerIndexedDb = (options?: {
56
+ readonly database?: string | undefined
57
+ }): Layer.Layer<KeyValueStore.KeyValueStore, never, IndexedDb> =>
58
+ Layer.effect(KeyValueStore.KeyValueStore)(
59
+ Effect.gen(function*() {
60
+ const db = yield* Effect.acquireRelease(
61
+ openDatabase(options?.database ?? "effect_key_value_store"),
62
+ (db) => Effect.sync(() => db.close())
63
+ ).pipe(Effect.orDie)
64
+
65
+ return KeyValueStore.make({
66
+ clear: Effect.suspend(() => {
67
+ const store = getKvsEntriesStore(db, "readwrite")
68
+ return idbRequest({ method: "clear", message: "Failed to clear backing store" }, () => store.clear())
69
+ }),
70
+ get: (key: string) =>
71
+ Effect.map(
72
+ Effect.suspend(() => {
73
+ const store = getKvsEntriesStore(db, "readonly")
74
+ return idbRequest<{ key: string; value: string } | undefined>({
75
+ method: "get",
76
+ message: "Failed to get value from backing store",
77
+ key
78
+ }, () => store.get(key))
79
+ }),
80
+ (found) => typeof found?.value === "string" ? found.value : undefined
81
+ ),
82
+ getUint8Array: (key: string) =>
83
+ Effect.map(
84
+ Effect.suspend(() => {
85
+ const store = getKvsEntriesStore(db, "readonly")
86
+ return idbRequest<{ key: string; value: Uint8Array } | undefined>({
87
+ method: "getUint8Array",
88
+ message: "Failed to get value from backing store",
89
+ key
90
+ }, () => store.get(key))
91
+ }),
92
+ (found) => found?.value && found.value instanceof Uint8Array ? found.value : undefined
93
+ ),
94
+ set: (key: string, value: string | Uint8Array) =>
95
+ Effect.asVoid(Effect.suspend(() => {
96
+ const store = getKvsEntriesStore(db, "readwrite")
97
+ return idbRequest(
98
+ { method: "set", message: "Failed to set value in backing store", key },
99
+ () => store.put({ key, value })
100
+ )
101
+ })),
102
+ size: Effect.suspend(() => {
103
+ const store = getKvsEntriesStore(db, "readonly")
104
+ return idbRequest<number>(
105
+ { method: "size", message: "Failed to get backing store size" },
106
+ () => store.count()
107
+ )
108
+ }),
109
+ remove: (key: string) =>
110
+ Effect.asVoid(Effect.suspend(() => {
111
+ const store = getKvsEntriesStore(db, "readwrite")
112
+ return idbRequest(
113
+ { method: "remove", message: "Failed to remove value from backing store", key },
114
+ () => store.delete(key)
115
+ )
116
+ }))
117
+ })
118
+ })
119
+ )
120
+
121
+ const databaseVersion = 1
122
+ const entriesStoreName = "entries"
123
+ const openDatabase = Effect.fnUntraced(function*(database: string) {
124
+ const idb = (yield* IndexedDb).indexedDB
125
+ const openRequest = yield* Effect.try({
126
+ try: () => idb.open(database, databaseVersion),
127
+ catch: (cause) =>
128
+ new KeyValueStore.KeyValueStoreError({
129
+ method: "open",
130
+ message: "Failed to open backing store database",
131
+ cause
132
+ })
133
+ })
134
+ openRequest.onupgradeneeded = () => {
135
+ const db = openRequest.result
136
+ if (!db.objectStoreNames.contains(entriesStoreName)) {
137
+ db.createObjectStore(entriesStoreName, { keyPath: "key" })
138
+ }
139
+ }
140
+ return yield* idbRequest({ method: "open", message: "Failed to open backing store database" }, () => openRequest)
141
+ })
142
+
143
+ const idbRequest = <A>(
144
+ failArgs: { method: string; message: string; key?: string },
145
+ evaluate: () => IDBRequest<A>
146
+ ): Effect.Effect<A, KeyValueStore.KeyValueStoreError> =>
147
+ Effect.callback<A, KeyValueStore.KeyValueStoreError>((resume) => {
148
+ const request = evaluate()
149
+ if (request.readyState === "done") {
150
+ return resume(Effect.succeed(request.result))
151
+ }
152
+ request.onsuccess = () => {
153
+ resume(Effect.succeed(request.result))
154
+ }
155
+ request.onerror = () =>
156
+ resume(Effect.fail(
157
+ new KeyValueStore.KeyValueStoreError({
158
+ ...failArgs,
159
+ cause: request.error
160
+ })
161
+ ))
162
+ })
163
+
164
+ const getKvsEntriesStore = (db: IDBDatabase, mode: IDBTransactionMode) => {
165
+ const transaction = db.transaction(entriesStoreName, mode)
166
+ return transaction.objectStore(entriesStoreName)
167
+ }
@@ -1,5 +1,17 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser-backed persistence layers for Effect's persistence service.
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.
8
+ *
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.
13
+ *
14
+ * @since 4.0.0
3
15
  */
4
16
  import type * as Arr from "effect/Array"
5
17
  import * as Clock from "effect/Clock"
@@ -9,8 +21,10 @@ import * as Layer from "effect/Layer"
9
21
  import * as Persistence from "effect/unstable/persistence/Persistence"
10
22
 
11
23
  /**
12
- * @since 1.0.0
24
+ * Creates a `BackingPersistence` layer backed by IndexedDB, optionally using the provided database name.
25
+ *
13
26
  * @category layers
27
+ * @since 4.0.0
14
28
  */
15
29
  export const layerBackingIndexedDb = (options?: {
16
30
  readonly database?: string | undefined
@@ -42,8 +56,10 @@ const entriesStoreName = "entries"
42
56
  const storeIdIndexName = "storeId"
43
57
 
44
58
  /**
45
- * @since 1.0.0
59
+ * Creates a `Persistence` layer backed by IndexedDB, optionally using the provided database name.
60
+ *
46
61
  * @category layers
62
+ * @since 4.0.0
47
63
  */
48
64
  export const layerIndexedDb = (options?: {
49
65
  readonly database?: string | undefined
@@ -1,17 +1,42 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser entry-point helpers for running Effect programs.
3
+ *
4
+ * This module exposes `runMain`, a browser-oriented main runner for launching
5
+ * an Effect as the root program of a page, single-page application, demo, or
6
+ * browser test harness. It delegates execution to the core Effect runtime while
7
+ * adding the browser lifecycle hook needed to interrupt the main fiber when the
8
+ * page receives `beforeunload`.
9
+ *
10
+ * `BrowserRuntime` does not provide application services by itself. Provide
11
+ * any required layers, such as browser HTTP, storage, worker, geolocation, or
12
+ * permission services, before passing the effect to `runMain`. Keep long-lived
13
+ * browser resources scoped so interruption can run their finalizers while the
14
+ * page is still active.
15
+ *
16
+ * Browser unload is more constrained than a process signal. Finalizers that
17
+ * need the network, timers, prompts, or long asynchronous work may not complete
18
+ * once navigation or tab close has started, and browsers do not expose a
19
+ * process exit status. Use `runMain` to connect the page lifecycle to Effect
20
+ * interruption, and use browser-specific persistence or delivery APIs for work
21
+ * that must survive page teardown.
22
+ *
23
+ * @since 4.0.0
3
24
  */
4
25
  import type * as Effect from "effect/Effect"
5
26
  import { makeRunMain, type Teardown } from "effect/Runtime"
6
27
 
7
28
  /**
8
- * @since 1.0.0
29
+ * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
30
+ *
9
31
  * @category Runtime
32
+ * @since 4.0.0
10
33
  */
11
34
  export const runMain: {
12
35
  /**
13
- * @since 1.0.0
36
+ * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
37
+ *
14
38
  * @category Runtime
39
+ * @since 4.0.0
15
40
  */
16
41
  (
17
42
  options?: {
@@ -20,8 +45,10 @@ export const runMain: {
20
45
  }
21
46
  ): <E, A>(effect: Effect.Effect<A, E>) => void
22
47
  /**
23
- * @since 1.0.0
48
+ * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
49
+ *
24
50
  * @category Runtime
51
+ * @since 4.0.0
25
52
  */
26
53
  <E, A>(
27
54
  effect: Effect.Effect<A, E>,
@@ -1,12 +1,37 @@
1
1
  /**
2
- * @since 1.0.0
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.
24
+ *
25
+ * @since 4.0.0
3
26
  */
4
27
  import * as Layer from "effect/Layer"
5
28
  import * as Socket from "effect/unstable/socket/Socket"
6
29
 
7
30
  /**
8
- * @since 1.0.0
9
- * @category Layers
31
+ * Creates a `Socket` layer connected to the given URL using the browser `WebSocket` constructor.
32
+ *
33
+ * @category layers
34
+ * @since 4.0.0
10
35
  */
11
36
  export const layerWebSocket = (url: string, options?: {
12
37
  readonly closeCodeIsError?: (code: number) => boolean
@@ -16,10 +41,10 @@ export const layerWebSocket = (url: string, options?: {
16
41
  )
17
42
 
18
43
  /**
19
- * A WebSocket constructor that uses `globalThis.WebSocket`.
44
+ * Layer that provides a `WebSocketConstructor` service backed by `globalThis.WebSocket`.
20
45
  *
21
- * @since 1.0.0
22
- * @category Layers
46
+ * @category layers
47
+ * @since 4.0.0
23
48
  */
24
49
  export const layerWebSocketConstructor: Layer.Layer<Socket.WebSocketConstructor> =
25
50
  Socket.layerWebSocketConstructorGlobal
@@ -1,5 +1,27 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser `Stream` constructors for DOM event targets.
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.
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.
16
+ *
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.
23
+ *
24
+ * @since 4.0.0
3
25
  */
4
26
 
5
27
  import * as Stream from "effect/Stream"
@@ -10,8 +32,8 @@ import * as Stream from "effect/Stream"
10
32
  * By default, the underlying buffer is unbounded in size. You can customize the
11
33
  * buffer size an object as the second argument with the `bufferSize` field.
12
34
  *
13
- * @since 1.0.0
14
35
  * @category Streams
36
+ * @since 4.0.0
15
37
  */
16
38
  export const fromEventListenerWindow = <K extends keyof WindowEventMap>(
17
39
  type: K,
@@ -29,8 +51,8 @@ export const fromEventListenerWindow = <K extends keyof WindowEventMap>(
29
51
  * By default, the underlying buffer is unbounded in size. You can customize the
30
52
  * buffer size an object as the second argument with the `bufferSize` field.
31
53
  *
32
- * @since 1.0.0
33
54
  * @category Streams
55
+ * @since 4.0.0
34
56
  */
35
57
  export const fromEventListenerDocument = <K extends keyof DocumentEventMap>(
36
58
  type: K,
@@ -1,5 +1,25 @@
1
1
  /**
2
- * @since 1.0.0
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
20
+ * terminating it.
21
+ *
22
+ * @since 4.0.0
3
23
  */
4
24
  import * as Deferred from "effect/Deferred"
5
25
  import * as Effect from "effect/Effect"
@@ -9,8 +29,10 @@ import * as Worker from "effect/unstable/workers/Worker"
9
29
  import { WorkerError, WorkerReceiveError } from "effect/unstable/workers/WorkerError"
10
30
 
11
31
  /**
12
- * @since 1.0.0
13
- * @category Layers
32
+ * Creates browser worker layers by combining the default `WorkerPlatform` with a spawner for `Worker`, `SharedWorker`, or `MessagePort` instances.
33
+ *
34
+ * @category layers
35
+ * @since 4.0.0
14
36
  */
15
37
  export const layer = (
16
38
  spawn: (id: number) => Worker | SharedWorker | MessagePort
@@ -21,8 +43,10 @@ export const layer = (
21
43
  )
22
44
 
23
45
  /**
24
- * @since 1.0.0
25
- * @category Layers
46
+ * Layer that provides the browser `WorkerPlatform` for `Worker`, `SharedWorker`, and `MessagePort` communication.
47
+ *
48
+ * @category layers
49
+ * @since 4.0.0
26
50
  */
27
51
  export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(Worker.WorkerPlatform)(
28
52
  Worker.makePlatform<globalThis.SharedWorker | globalThis.Worker | MessagePort>()({
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser runtime support for Effect worker runners.
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.
10
+ *
11
+ * Use it with `BrowserWorker` when a browser application needs to move RPC
12
+ * 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.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import * as Cause from "effect/Cause"
5
23
  import * as Deferred from "effect/Deferred"
@@ -22,8 +40,10 @@ if (typeof self !== "undefined" && "onconnect" in self) {
22
40
  }
23
41
 
24
42
  /**
25
- * @since 1.0.0
26
- * @category Constructors
43
+ * Creates a `WorkerRunnerPlatform` service that runs worker handlers over a `MessagePort` or `Window`.
44
+ *
45
+ * @category constructors
46
+ * @since 4.0.0
27
47
  */
28
48
  export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatform["Service"] => ({
29
49
  start: Effect.fnUntraced(function*<O = unknown, I = unknown>() {
@@ -151,16 +171,20 @@ export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatf
151
171
  })
152
172
 
153
173
  /**
154
- * @since 1.0.0
155
- * @category Layers
174
+ * Layer that provides a browser `WorkerRunnerPlatform` using the global `self` worker context.
175
+ *
176
+ * @category layers
177
+ * @since 4.0.0
156
178
  */
157
179
  export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.sync(WorkerRunner.WorkerRunnerPlatform)(() =>
158
180
  make(self)
159
181
  )
160
182
 
161
183
  /**
162
- * @since 1.0.0
163
- * @category Layers
184
+ * Layer that provides a `WorkerRunnerPlatform` using the supplied `MessagePort` or `Window`.
185
+ *
186
+ * @category layers
187
+ * @since 4.0.0
164
188
  */
165
189
  export const layerMessagePort = (port: MessagePort | Window): Layer.Layer<WorkerRunner.WorkerRunnerPlatform> =>
166
190
  Layer.succeed(WorkerRunner.WorkerRunnerPlatform)(make(port))
package/src/Clipboard.ts CHANGED
@@ -1,5 +1,21 @@
1
1
  /**
2
- * @since 1.0.0
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`.
17
+ *
18
+ * @since 4.0.0
3
19
  */
4
20
  import * as Context from "effect/Context"
5
21
  import * as Data from "effect/Data"
@@ -10,8 +26,10 @@ const TypeId = "~@effect/platform-browser/Clipboard"
10
26
  const ErrorTypeId = "~@effect/platform-browser/Clipboard/ClipboardError"
11
27
 
12
28
  /**
13
- * @since 1.0.0
14
- * @category Models
29
+ * Service interface for reading from, writing to, and clearing the browser clipboard.
30
+ *
31
+ * @category models
32
+ * @since 4.0.0
15
33
  */
16
34
  export interface Clipboard {
17
35
  readonly [TypeId]: typeof TypeId
@@ -24,8 +42,10 @@ export interface Clipboard {
24
42
  }
25
43
 
26
44
  /**
27
- * @since 1.0.0
28
- * @category Errors
45
+ * Tagged error raised when a browser clipboard operation fails.
46
+ *
47
+ * @category errors
48
+ * @since 4.0.0
29
49
  */
30
50
  export class ClipboardError extends Data.TaggedError("ClipboardError")<{
31
51
  readonly message: string
@@ -35,14 +55,18 @@ export class ClipboardError extends Data.TaggedError("ClipboardError")<{
35
55
  }
36
56
 
37
57
  /**
38
- * @since 1.0.0
39
- * @category Service
58
+ * Service tag for the browser `Clipboard` service.
59
+ *
60
+ * @category services
61
+ * @since 4.0.0
40
62
  */
41
63
  export const Clipboard: Context.Service<Clipboard, Clipboard> = Context.Service<Clipboard>(TypeId)
42
64
 
43
65
  /**
44
- * @since 1.0.0
45
- * @category Constructors
66
+ * Builds a `Clipboard` service from primitive read and write operations, deriving `clear` and `writeBlob` helpers.
67
+ *
68
+ * @category constructors
69
+ * @since 4.0.0
46
70
  */
47
71
  export const make = (
48
72
  impl: Omit<Clipboard, "clear" | "writeBlob" | typeof TypeId>
@@ -57,8 +81,8 @@ export const make = (
57
81
  /**
58
82
  * A layer that directly interfaces with the navigator.clipboard api
59
83
  *
60
- * @since 1.0.0
61
- * @category Layers
84
+ * @category layers
85
+ * @since 4.0.0
62
86
  */
63
87
  export const layer: Layer.Layer<Clipboard> = Layer.succeed(
64
88
  Clipboard,