@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
package/dist/index.js CHANGED
@@ -1,69 +1,392 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  // @barrel: Auto-generated exports. Do not edit manually.
5
5
  /**
6
+ * Browser platform implementation of the Crypto service.
7
+ *
6
8
  * @since 1.0.0
7
9
  */
10
+ export * as BrowserCrypto from "./BrowserCrypto.js";
11
+ /**
12
+ * Browser implementations of the Effect `HttpClient`.
13
+ *
14
+ * This module exposes HTTP client layers for code that runs in a browser. It
15
+ * re-exports the fetch-based client for the common case, where requests should
16
+ * use the platform `fetch` implementation and optional `RequestInit` defaults,
17
+ * and it provides an `XMLHttpRequest`-backed layer for integrations that need
18
+ * XHR semantics such as response type control or environments where XHR is the
19
+ * required transport.
20
+ *
21
+ * Use these layers for single-page applications, browser tests, generated
22
+ * `HttpApiClient`s, and other client-side Effect programs that need HTTP
23
+ * requests to participate in interruption, typed transport / decode errors, and
24
+ * Effect's response body readers.
25
+ *
26
+ * Browser networking rules still apply. Cross-origin requests are subject to
27
+ * CORS preflights and server allowlists, especially when using custom headers,
28
+ * non-simple methods, or non-simple content types. Only CORS-exposed response
29
+ * headers are readable, and cookies / authentication are controlled by the
30
+ * browser and the configured fetch `RequestInit.credentials` policy. The XHR
31
+ * layer uses the browser's `XMLHttpRequest` defaults for credentials.
32
+ *
33
+ * Body handling differs between the transports. Fetch delegates body framing to
34
+ * the Web Fetch implementation. The XHR client sends empty, raw, `Uint8Array`,
35
+ * and `FormData` bodies directly, buffers `Stream` request bodies before
36
+ * sending, defaults responses to text, and can be switched to `ArrayBuffer`
37
+ * responses with `withXHRArrayBuffer`. When sending `FormData`, avoid setting
38
+ * an incompatible `Content-Type` header so the browser can generate the
39
+ * multipart boundary.
40
+ *
41
+ * @since 4.0.0
42
+ */
8
43
  export * as BrowserHttpClient from "./BrowserHttpClient.js";
9
44
  /**
10
- * @since 1.0.0
45
+ * Browser-backed `KeyValueStore` layers for Effect programs.
46
+ *
47
+ * This module provides `KeyValueStore` implementations backed by the browser's
48
+ * synchronous Web Storage APIs: `localStorage` for origin-scoped data that
49
+ * persists across page reloads and browser sessions, and `sessionStorage` for
50
+ * page-session data that is cleared when that tab or window's page session
51
+ * ends. They are useful for small client-side values such as user preferences,
52
+ * feature flags, lightweight caches, persisted drafts, or session-only workflow
53
+ * state.
54
+ *
55
+ * Web Storage is only available in browser environments and is scoped by origin.
56
+ * Browsers may deny access in private modes or restricted contexts, and writes
57
+ * can fail when storage quotas are exceeded. The API stores strings and runs
58
+ * synchronously on the main thread, so prefer it for small payloads and avoid
59
+ * treating it as a database or a secure place for sensitive data.
60
+ *
61
+ * @since 4.0.0
11
62
  */
12
63
  export * as BrowserKeyValueStore from "./BrowserKeyValueStore.js";
13
64
  /**
14
- * @since 1.0.0
65
+ * Browser-backed persistence layers for Effect's persistence service.
66
+ *
67
+ * This module provides IndexedDB implementations of the Effect persistence services for applications that need a
68
+ * durable client-side cache, such as remembered query results, offline-capable workflows, or values that should survive
69
+ * page reloads. Entries are stored by persistence store id and key in a shared IndexedDB object store, with optional
70
+ * expiration timestamps for TTL-based invalidation.
71
+ *
72
+ * Because this storage depends on browser IndexedDB, operations can fail when storage is unavailable, quota is exceeded,
73
+ * data is cleared by the user or browser, or the payload cannot be structured-cloned by IndexedDB. Expired entries are
74
+ * removed lazily when they are read, so this module is best suited for application-managed cached objects rather than
75
+ * security-sensitive or authoritative data.
76
+ *
77
+ * @since 4.0.0
15
78
  */
16
79
  export * as BrowserPersistence from "./BrowserPersistence.js";
17
80
  /**
18
- * @since 1.0.0
81
+ * Browser entry-point helpers for running Effect programs.
82
+ *
83
+ * This module exposes `runMain`, a browser-oriented main runner for launching
84
+ * an Effect as the root program of a page, single-page application, demo, or
85
+ * browser test harness. It delegates execution to the core Effect runtime while
86
+ * adding the browser lifecycle hook needed to interrupt the main fiber when the
87
+ * page receives `beforeunload`.
88
+ *
89
+ * `BrowserRuntime` does not provide application services by itself. Provide
90
+ * any required layers, such as browser HTTP, storage, worker, geolocation, or
91
+ * permission services, before passing the effect to `runMain`. Keep long-lived
92
+ * browser resources scoped so interruption can run their finalizers while the
93
+ * page is still active.
94
+ *
95
+ * Browser unload is more constrained than a process signal. Finalizers that
96
+ * need the network, timers, prompts, or long asynchronous work may not complete
97
+ * once navigation or tab close has started, and browsers do not expose a
98
+ * process exit status. Use `runMain` to connect the page lifecycle to Effect
99
+ * interruption, and use browser-specific persistence or delivery APIs for work
100
+ * that must survive page teardown.
101
+ *
102
+ * @since 4.0.0
19
103
  */
20
104
  export * as BrowserRuntime from "./BrowserRuntime.js";
21
105
  /**
22
- * @since 1.0.0
106
+ * Browser WebSocket layers for Effect sockets.
107
+ *
108
+ * This module provides the browser entry point for `Socket.Socket` values
109
+ * backed by the platform `WebSocket` implementation. Use `layerWebSocket` when
110
+ * client-side Effect programs, browser tests, RPC transports, or realtime UI
111
+ * features need a bidirectional socket connected to a WebSocket URL, and use
112
+ * `layerWebSocketConstructor` when lower-level socket APIs need access to the
113
+ * browser constructor service.
114
+ *
115
+ * Browser WebSocket rules still apply. Connections are created through
116
+ * `globalThis.WebSocket`, so URL schemes, subprotocol negotiation, mixed-content
117
+ * blocking, cookies, authentication, CORS-like origin checks, and extension
118
+ * negotiation are controlled by the browser and server rather than by Effect.
119
+ * Close events are translated into socket errors unless the provided
120
+ * `closeCodeIsError` predicate classifies the close code as clean, which is
121
+ * useful for protocols that use application-specific close codes.
122
+ *
123
+ * Messages are delivered as strings or binary `Uint8Array` values; browser
124
+ * `Blob` messages are read into bytes before they reach the socket handler.
125
+ * Outgoing data should already be serialized to a string or bytes, and protocol
126
+ * frames that represent an intentional close should be sent as `CloseEvent`
127
+ * values so the underlying `WebSocket.close` code and reason are preserved.
128
+ *
129
+ * @since 4.0.0
23
130
  */
24
131
  export * as BrowserSocket from "./BrowserSocket.js";
25
132
  /**
26
- * @since 1.0.0
133
+ * Browser `Stream` constructors for DOM event targets.
134
+ *
135
+ * This module provides typed helpers for turning `window.addEventListener` and
136
+ * `document.addEventListener` callbacks into Effect `Stream`s. They are useful
137
+ * for UI and runtime signals such as resize, visibility, keyboard, pointer,
138
+ * focus, online / offline, and other browser events that should be composed
139
+ * with Effect stream operators and finalized with the consuming fiber.
140
+ *
141
+ * Browser events are push-based `EventTarget` notifications, so they do not
142
+ * apply Web Streams backpressure to the browser event source. Events are
143
+ * buffered until downstream pulls them; the default buffer is unbounded, so
144
+ * high-frequency sources like scroll, pointermove, or mousemove should usually
145
+ * set `bufferSize` and use stream operators that sample, debounce, throttle, or
146
+ * drop work as appropriate.
147
+ *
148
+ * These helpers are for DOM events, not for adapting `ReadableStream` request
149
+ * or response bodies. Fetch bodies follow the Web Streams body rules, including
150
+ * single-consumer locking and disturbed bodies after reads, and should be
151
+ * handled with body-specific HTTP or Web Streams APIs instead. When using the
152
+ * browser `once` option, pair the stream with `Stream.take(1)` if a finite
153
+ * stream is required.
154
+ *
155
+ * @since 4.0.0
27
156
  */
28
157
  export * as BrowserStream from "./BrowserStream.js";
29
158
  /**
30
- * @since 1.0.0
159
+ * Parent-side browser support for Effect workers.
160
+ *
161
+ * This module provides the `WorkerPlatform` used by browser applications that
162
+ * spawn or connect to `Worker`, `SharedWorker`, and `MessagePort` endpoints
163
+ * through Effect's worker protocol. Pair it with `BrowserWorkerRunner` in the
164
+ * worker entrypoint when building worker-backed RPC clients, moving CPU-bound
165
+ * work off the main thread, isolating browser-only services, or adapting an
166
+ * existing `MessageChannel` in tests and custom transports.
167
+ *
168
+ * Dedicated workers communicate through the worker object itself, while shared
169
+ * workers communicate through `worker.port`; raw `MessagePort` values are also
170
+ * accepted and are started when supported. Messages are posted with the browser
171
+ * structured-clone algorithm, so payloads must be cloneable by the target
172
+ * runtime. Transfer lists can avoid copying values such as `ArrayBuffer` or
173
+ * `MessagePort`, but transferring moves ownership away from the sender and
174
+ * invalid or mismatched transferables can fail the send. Scope finalization
175
+ * sends the worker close signal over the port; the application that created a
176
+ * dedicated `Worker` remains responsible for any broader lifecycle such as
177
+ * terminating it.
178
+ *
179
+ * @since 4.0.0
31
180
  */
32
181
  export * as BrowserWorker from "./BrowserWorker.js";
33
182
  /**
34
- * @since 1.0.0
183
+ * Browser runtime support for Effect worker runners.
184
+ *
185
+ * This module is intended for code that is already executing in a browser
186
+ * worker context, or for tests and adapters that supply a `MessagePort` or
187
+ * `Window` endpoint directly. It provides the `WorkerRunnerPlatform` used by
188
+ * `WorkerRunner` and `RpcServer.layerProtocolWorkerRunner` to receive parent
189
+ * or client requests, run Effect handlers, and send responses through the
190
+ * browser `postMessage` channel.
191
+ *
192
+ * Use it with `BrowserWorker` when a browser application needs to move RPC
193
+ * handlers, CPU-bound computations, or browser-only services into a dedicated
194
+ * worker or shared worker. Dedicated workers communicate through the current
195
+ * `self` endpoint; shared workers accept multiple `onconnect` ports and cache
196
+ * ports that connect before the runner layer starts. Messages still use the
197
+ * browser structured-clone algorithm, so payload schemas, transfer lists,
198
+ * `messageerror` events, and the lifetime of each `MessagePort` must be
199
+ * considered when crossing worker boundaries.
200
+ *
201
+ * @since 4.0.0
35
202
  */
36
203
  export * as BrowserWorkerRunner from "./BrowserWorkerRunner.js";
37
204
  /**
38
- * @since 1.0.0
205
+ * Browser clipboard service for Effect programs.
206
+ *
207
+ * This module wraps the browser `navigator.clipboard` API in a `Clipboard`
208
+ * service so client-side applications can read, write, and clear clipboard
209
+ * contents as typed Effects. It is useful for common UI workflows such as copy
210
+ * buttons, paste/import actions, sharing generated text, and moving rich
211
+ * clipboard payloads like `Blob`-backed `ClipboardItem`s through an Effect
212
+ * environment.
213
+ *
214
+ * Browser clipboard rules still apply. Clipboard access generally requires a
215
+ * secure context, and browsers may require a user gesture, permission prompt, or
216
+ * active focused document before reads or writes are allowed. Support also
217
+ * varies by operation and payload type: text helpers are the most portable,
218
+ * while `ClipboardItem` and non-text MIME types may be unavailable or restricted
219
+ * in some browsers. Failed browser operations are surfaced as `ClipboardError`.
220
+ *
221
+ * @since 4.0.0
39
222
  */
40
223
  export * as Clipboard from "./Clipboard.js";
41
224
  /**
42
- * @since 1.0.0
225
+ * Browser geolocation support for Effect programs.
226
+ *
227
+ * This module provides a `Geolocation` service and browser-backed layer for
228
+ * reading device location through `navigator.geolocation`. Use
229
+ * `getCurrentPosition` when an application needs one location fix, such as a
230
+ * nearby-search, check-in, or delivery estimate, and `watchPosition` when it
231
+ * needs a stream of updates for navigation, tracking, or location-aware UI.
232
+ *
233
+ * The implementation is browser-only and relies on the browser permission and
234
+ * policy model for geolocation. Calls may prompt the user, fail when permission
235
+ * is denied, time out, or report that position data is unavailable because of
236
+ * device, browser, privacy, origin, or secure-context restrictions. Watched
237
+ * positions are scoped so the underlying browser watch is cleared when the
238
+ * stream is finalized, and slow consumers should account for the sliding
239
+ * buffer used by `watchPosition`.
240
+ *
241
+ * @since 4.0.0
43
242
  */
44
243
  export * as Geolocation from "./Geolocation.js";
45
244
  /**
245
+ * Browser IndexedDB primitives and key schemas for Effect applications.
246
+ *
247
+ * This module is the low-level bridge used by the platform-browser IndexedDB
248
+ * integration. It provides an `IndexedDb` service around the browser
249
+ * `indexedDB` factory and `IDBKeyRange` constructor, a `layerWindow` layer for
250
+ * wiring those primitives from `window`, and schemas for the key shapes accepted
251
+ * by IndexedDB object stores and indexes.
252
+ *
253
+ * Use it when building typed local persistence for browser caches,
254
+ * offline-first state, background queues, drafts, or other client-side data
255
+ * that should be validated before it reaches IndexedDB. Higher-level database,
256
+ * version, table, and query modules build on these primitives for migrations
257
+ * and typed transactions.
258
+ *
259
+ * IndexedDB still follows the browser rules: schema changes happen only during
260
+ * version upgrades, upgrades may be blocked by other open tabs or connections,
261
+ * and reads or writes must run in transactions scoped to the object stores they
262
+ * touch. The `layerWindow` constructor should be used only where browser
263
+ * globals are available, and code that also runs during SSR or in restricted
264
+ * browser contexts should account for `indexedDB` or `IDBKeyRange` being
265
+ * missing.
266
+ *
46
267
  * @since 4.0.0
47
268
  */
48
269
  export * as IndexedDb from "./IndexedDb.js";
49
270
  /**
271
+ * Builds and opens typed IndexedDB databases from versioned schema migrations.
272
+ *
273
+ * This module turns an `IndexedDbVersion` migration chain into an
274
+ * `IndexedDbDatabase` layer. The layer opens the browser database, runs any
275
+ * pending upgrade migrations, provides a query builder for the current schema,
276
+ * and exposes a `rebuild` effect that deletes and reopens the database. It is
277
+ * the database-level companion to the table, version, and query builder
278
+ * modules.
279
+ *
280
+ * Use it for browser-local persistence such as offline-first application
281
+ * state, cached server data, background queues, drafts, and other client-side
282
+ * stores that need typed reads and writes backed by IndexedDB transactions.
283
+ *
284
+ * IndexedDB schema changes can only happen inside upgrade transactions, so
285
+ * every call to `make` or `.add` represents the next browser database version
286
+ * and only migrations after the existing browser version are run. Table and
287
+ * index definitions type the migration and query APIs, but object stores and
288
+ * indexes still need to be created or removed explicitly with the migration
289
+ * transaction helpers. Include the complete target table set in each version,
290
+ * create indexes before querying them, and treat key path or auto-increment
291
+ * changes as store migrations that copy data into a replacement object store.
292
+ * Upgrades can be blocked by other open connections, and all migration reads,
293
+ * writes, store changes, and index changes share the single upgrade
294
+ * transaction supplied by the browser.
295
+ *
50
296
  * @since 4.0.0
51
297
  */
52
298
  export * as IndexedDbDatabase from "./IndexedDbDatabase.js";
53
299
  /**
300
+ * Builds effectful, schema-aware queries for typed browser IndexedDB versions.
301
+ *
302
+ * An `IndexedDbQueryBuilder` is created from an open database and a version's
303
+ * table descriptors, then exposes `from(tableName)` as the entry point for
304
+ * table operations. The resulting query objects can select, count, delete,
305
+ * insert, upsert, clear tables, stream paged reads, react to invalidations, and
306
+ * run multiple effects in a shared `IDBTransaction` with `withTransaction`.
307
+ *
308
+ * Use this module for local browser persistence such as caches, offline-first
309
+ * state, background queues, drafts, and other client-side data where writes
310
+ * should be encoded through `Schema` and reads should be decoded before they
311
+ * reach application code.
312
+ *
313
+ * Index and range helpers are thinly typed wrappers around IndexedDB object
314
+ * stores, indexes, `IDBKeyRange`, and cursors. Index names must be declared on
315
+ * the table and created during migrations; without an index, queries use the
316
+ * object store key path. Range values are encoded IndexedDB key values, and
317
+ * compound key paths must follow the declared key order. Filters, offsets,
318
+ * reverse reads, out-of-line keys, and limited deletes require cursor-based
319
+ * scans, while simpler selects can use `getAll`.
320
+ *
321
+ * Table schema details affect runtime behavior: auto-increment writes may omit
322
+ * the generated numeric key, stores without a key path require an out-of-line
323
+ * `key` for writes and add that `key` back to selected rows, and schema
324
+ * mismatches surface as `EncodeError` or `DecodeError` query failures.
325
+ *
54
326
  * @since 4.0.0
55
327
  */
56
328
  export * as IndexedDbQueryBuilder from "./IndexedDbQueryBuilder.js";
57
329
  /**
330
+ * Defines typed table descriptors for the browser IndexedDB integration.
331
+ *
332
+ * An `IndexedDbTable` records the object store name, row schema, primary key
333
+ * path, indexes, auto-increment behavior, and transaction durability used by
334
+ * database versions, migrations, and typed queries. These descriptors are
335
+ * useful for local caches, offline-first application state, background queues,
336
+ * drafts, and other browser-persisted data that should be validated through
337
+ * `Schema`.
338
+ *
339
+ * Key paths and index paths must reference encoded schema fields whose values
340
+ * are valid IndexedDB keys, and compound paths are represented as readonly
341
+ * arrays. Tables without a key path use an out-of-line `key` that is added to
342
+ * reads and required for writes, so the row schema itself cannot define a
343
+ * `key` field. Auto-increment tables require a numeric key path; when that key
344
+ * is omitted on write, the module uses a derived schema without the generated
345
+ * key. Declaring indexes here types query builder index selection, but the
346
+ * indexes still need to be created during database migrations.
347
+ *
58
348
  * @since 4.0.0
59
349
  */
60
350
  export * as IndexedDbTable from "./IndexedDbTable.js";
61
351
  /**
352
+ * Typed IndexedDB schema version definitions.
353
+ *
354
+ * This module represents one logical IndexedDB database version as a non-empty set of `IndexedDbTable` definitions.
355
+ * Versions are consumed by `IndexedDbDatabase.make` and `.add` to type query builders and migration transactions, so
356
+ * applications can describe the tables available after initialization or after each schema upgrade.
357
+ *
358
+ * Use an `IndexedDbVersion` when defining the initial stores for a browser database, adding or removing object stores,
359
+ * changing indexes, or moving data between differently shaped table schemas. The version value is a typed description of
360
+ * the target schema; creating and deleting object stores or indexes still happens explicitly inside the corresponding
361
+ * `IndexedDbDatabase` migration callback.
362
+ *
363
+ * IndexedDB versioning is ordered by the migration chain rather than by a number stored here. Each `.add` step becomes
364
+ * the next browser database version, and only migrations after the browser's current version are run. Include every table
365
+ * that should be queryable in each target version, avoid duplicate table names, and remember that key-path or
366
+ * auto-increment changes usually require creating a new object store and copying data during the upgrade transaction.
367
+ *
62
368
  * @since 4.0.0
63
369
  */
64
370
  export * as IndexedDbVersion from "./IndexedDbVersion.js";
65
371
  /**
66
- * @since 1.0.0
372
+ * Browser Permissions API support for Effect programs.
373
+ *
374
+ * This module provides a `Permissions` service and browser-backed layer for
375
+ * querying `navigator.permissions` from Effect code. Use it to check whether a
376
+ * browser capability is currently `granted`, `prompt`, or `denied` before
377
+ * showing UI for flows such as geolocation, notifications, clipboard access,
378
+ * camera, microphone, or persistent storage.
379
+ *
380
+ * Permission queries do not request access by themselves and should not replace
381
+ * the feature API that actually performs the operation. Browser support for
382
+ * permission names and states is uneven, queries may reject for unsupported or
383
+ * invalid descriptors, and some permissions are only meaningful in secure
384
+ * contexts or after user activation. Returned `PermissionStatus` objects can
385
+ * change when the user updates browser settings or responds to prompts; when
386
+ * watching `change` or `onchange`, account for browser differences and clean up
387
+ * listeners when the surrounding Effect scope ends.
388
+ *
389
+ * @since 4.0.0
67
390
  */
68
391
  export * as Permissions from "./Permissions.js";
69
392
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["BrowserHttpClient","BrowserKeyValueStore","BrowserPersistence","BrowserRuntime","BrowserSocket","BrowserStream","BrowserWorker","BrowserWorkerRunner","Clipboard","Geolocation","IndexedDb","IndexedDbDatabase","IndexedDbQueryBuilder","IndexedDbTable","IndexedDbVersion","Permissions"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;AAGA,OAAO,KAAKA,iBAAiB,MAAM,wBAAwB;AAE3D;;;AAGA,OAAO,KAAKC,oBAAoB,MAAM,2BAA2B;AAEjE;;;AAGA,OAAO,KAAKC,kBAAkB,MAAM,yBAAyB;AAE7D;;;AAGA,OAAO,KAAKC,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,mBAAmB,MAAM,0BAA0B;AAE/D;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAKC,WAAW,MAAM,kBAAkB;AAE/C;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAKC,iBAAiB,MAAM,wBAAwB;AAE3D;;;AAGA,OAAO,KAAKC,qBAAqB,MAAM,4BAA4B;AAEnE;;;AAGA,OAAO,KAAKC,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAKC,gBAAgB,MAAM,uBAAuB;AAEzD;;;AAGA,OAAO,KAAKC,WAAW,MAAM,kBAAkB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["BrowserCrypto","BrowserHttpClient","BrowserKeyValueStore","BrowserPersistence","BrowserRuntime","BrowserSocket","BrowserStream","BrowserWorker","BrowserWorkerRunner","Clipboard","Geolocation","IndexedDb","IndexedDbDatabase","IndexedDbQueryBuilder","IndexedDbTable","IndexedDbVersion","Permissions"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;;;AAKA,OAAO,KAAKA,aAAa,MAAM,oBAAoB;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,OAAO,KAAKC,iBAAiB,MAAM,wBAAwB;AAE3D;;;;;;;;;;;;;;;;;;;AAmBA,OAAO,KAAKC,oBAAoB,MAAM,2BAA2B;AAEjE;;;;;;;;;;;;;;;AAeA,OAAO,KAAKC,kBAAkB,MAAM,yBAAyB;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,KAAKC,cAAc,MAAM,qBAAqB;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,KAAKC,mBAAmB,MAAM,0BAA0B;AAE/D;;;;;;;;;;;;;;;;;;;AAmBA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;;;;;;;;;;;;;;;;;AAmBA,OAAO,KAAKC,WAAW,MAAM,kBAAkB;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,OAAO,KAAKC,iBAAiB,MAAM,wBAAwB;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,OAAO,KAAKC,qBAAqB,MAAM,4BAA4B;AAEnE;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,KAAKC,cAAc,MAAM,qBAAqB;AAErD;;;;;;;;;;;;;;;;;;;AAmBA,OAAO,KAAKC,gBAAgB,MAAM,uBAAuB;AAEzD;;;;;;;;;;;;;;;;;;;;AAoBA,OAAO,KAAKC,WAAW,MAAM,kBAAkB","ignoreList":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@effect/platform-browser",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.66",
4
+ "version": "4.0.0-beta.68",
5
5
  "license": "MIT",
6
6
  "description": "Platform specific implementations for the browser",
7
7
  "homepage": "https://effect.website",
@@ -45,12 +45,12 @@
45
45
  "provenance": true
46
46
  },
47
47
  "peerDependencies": {
48
- "effect": "^4.0.0-beta.66"
48
+ "effect": "^4.0.0-beta.68"
49
49
  },
50
50
  "devDependencies": {
51
51
  "mock-xmlhttprequest": "^8.4.1",
52
52
  "fake-indexeddb": "^6.2.5",
53
- "effect": "^4.0.0-beta.66"
53
+ "effect": "^4.0.0-beta.68"
54
54
  },
55
55
  "dependencies": {
56
56
  "multipasta": "^0.2.7"
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Browser platform implementation of the Crypto service.
3
+ *
4
+ * @since 1.0.0
5
+ */
6
+ import * as Context from "effect/Context"
7
+ import * as EffectCrypto from "effect/Crypto"
8
+ import * as Effect from "effect/Effect"
9
+ import * as Layer from "effect/Layer"
10
+ import * as PlatformError from "effect/PlatformError"
11
+
12
+ /**
13
+ * Browser Web Crypto APIs used by the Crypto service implementation.
14
+ *
15
+ * @category models
16
+ * @since 1.0.0
17
+ */
18
+ export const WebCrypto = Context.Reference<Crypto>("@effect/platform-browser/Crypto/WebCrypto", {
19
+ defaultValue: () => globalThis.crypto
20
+ })
21
+
22
+ /**
23
+ * A layer that directly interfaces with the Web Crypto API.
24
+ *
25
+ * @category layers
26
+ * @since 1.0.0
27
+ */
28
+ export const layer: Layer.Layer<EffectCrypto.Crypto> = Layer.effect(
29
+ EffectCrypto.Crypto,
30
+ Effect.gen(function*() {
31
+ const crypto = yield* WebCrypto
32
+ if (!crypto) {
33
+ return yield* Effect.die(new Error("Web Crypto API is not available"))
34
+ }
35
+ const randomBytes = (size: number): Uint8Array => {
36
+ const bytes = new Uint8Array(size)
37
+ crypto.getRandomValues(bytes)
38
+ return bytes
39
+ }
40
+
41
+ const digest: EffectCrypto.Crypto["digest"] = (algorithm, data) => {
42
+ if (typeof crypto.subtle.digest !== "function") {
43
+ return Effect.fail(PlatformError.systemError({
44
+ module: "Crypto",
45
+ method: "digest",
46
+ _tag: "Unknown",
47
+ description: "crypto.subtle.digest is not available"
48
+ }))
49
+ }
50
+ return Effect.map(
51
+ Effect.tryPromise({
52
+ try: () => crypto.subtle.digest(algorithm, new Uint8Array(data)),
53
+ catch: (cause) =>
54
+ PlatformError.systemError({
55
+ module: "Crypto",
56
+ method: "digest",
57
+ _tag: "Unknown",
58
+ description: "Could not compute digest",
59
+ cause
60
+ })
61
+ }),
62
+ (buffer) => new Uint8Array(buffer)
63
+ )
64
+ }
65
+
66
+ return EffectCrypto.make({
67
+ randomBytes,
68
+ digest
69
+ })
70
+ })
71
+ )
@@ -1,5 +1,34 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser implementations of the Effect `HttpClient`.
3
+ *
4
+ * This module exposes HTTP client layers for code that runs in a browser. It
5
+ * re-exports the fetch-based client for the common case, where requests should
6
+ * use the platform `fetch` implementation and optional `RequestInit` defaults,
7
+ * and it provides an `XMLHttpRequest`-backed layer for integrations that need
8
+ * XHR semantics such as response type control or environments where XHR is the
9
+ * required transport.
10
+ *
11
+ * Use these layers for single-page applications, browser tests, generated
12
+ * `HttpApiClient`s, and other client-side Effect programs that need HTTP
13
+ * requests to participate in interruption, typed transport / decode errors, and
14
+ * Effect's response body readers.
15
+ *
16
+ * Browser networking rules still apply. Cross-origin requests are subject to
17
+ * CORS preflights and server allowlists, especially when using custom headers,
18
+ * non-simple methods, or non-simple content types. Only CORS-exposed response
19
+ * headers are readable, and cookies / authentication are controlled by the
20
+ * browser and the configured fetch `RequestInit.credentials` policy. The XHR
21
+ * layer uses the browser's `XMLHttpRequest` defaults for credentials.
22
+ *
23
+ * Body handling differs between the transports. Fetch delegates body framing to
24
+ * the Web Fetch implementation. The XHR client sends empty, raw, `Uint8Array`,
25
+ * and `FormData` bodies directly, buffers `Stream` request bodies before
26
+ * sending, defaults responses to text, and can be switched to `ArrayBuffer`
27
+ * responses with `withXHRArrayBuffer`. When sending `FormData`, avoid setting
28
+ * an incompatible `Content-Type` header so the browser can generate the
29
+ * multipart boundary.
30
+ *
31
+ * @since 4.0.0
3
32
  */
4
33
  import * as Cause from "effect/Cause"
5
34
  import * as Context from "effect/Context"
@@ -28,18 +57,18 @@ import * as HeaderParser from "multipasta/HeadersParser"
28
57
 
29
58
  export {
30
59
  /**
31
- * @since 1.0.0
32
60
  * @category Fetch
61
+ * @since 4.0.0
33
62
  */
34
63
  Fetch,
35
64
  /**
36
- * @since 1.0.0
37
65
  * @category Fetch
66
+ * @since 4.0.0
38
67
  */
39
68
  layer as layerFetch,
40
69
  /**
41
- * @since 1.0.0
42
70
  * @category Fetch
71
+ * @since 4.0.0
43
72
  */
44
73
  RequestInit
45
74
  } from "effect/unstable/http/FetchHttpClient"
@@ -49,14 +78,18 @@ export {
49
78
  // =============================================================================
50
79
 
51
80
  /**
52
- * @since 1.0.0
53
- * @category Models
81
+ * Allowed response body modes for the browser XHR HTTP client.
82
+ *
83
+ * @category models
84
+ * @since 4.0.0
54
85
  */
55
86
  export type XHRResponseType = "arraybuffer" | "text"
56
87
 
57
88
  /**
58
- * @since 1.0.0
59
- * @category References
89
+ * Reference that controls the `XMLHttpRequest.responseType` used by the browser XHR HTTP client, defaulting to `"text"`.
90
+ *
91
+ * @category references
92
+ * @since 4.0.0
60
93
  */
61
94
  export const CurrentXHRResponseType: Context.Reference<XHRResponseType> = Context.Reference(
62
95
  "@effect/platform-browser/BrowserHttpClient/CurrentXHRResponseType",
@@ -64,8 +97,10 @@ export const CurrentXHRResponseType: Context.Reference<XHRResponseType> = Contex
64
97
  )
65
98
 
66
99
  /**
67
- * @since 1.0.0
68
- * @category References
100
+ * Runs an effect with `CurrentXHRResponseType` set to `"arraybuffer"` so the XHR HTTP client receives response bodies as `ArrayBuffer` values.
101
+ *
102
+ * @category references
103
+ * @since 4.0.0
69
104
  */
70
105
  export const withXHRArrayBuffer = <A, E, R>(
71
106
  self: Effect.Effect<A, E, R>
@@ -77,8 +112,10 @@ export const withXHRArrayBuffer = <A, E, R>(
77
112
  )
78
113
 
79
114
  /**
80
- * @since 1.0.0
81
- * @category Services
115
+ * Service tag for the `XMLHttpRequest` constructor used by the browser XHR HTTP client.
116
+ *
117
+ * @category services
118
+ * @since 4.0.0
82
119
  */
83
120
  export class XMLHttpRequest extends Context.Service<
84
121
  XMLHttpRequest,
@@ -384,8 +421,10 @@ class ClientResponseImpl extends IncomingMessageImpl<HttpClientError.HttpClientE
384
421
  }
385
422
 
386
423
  /**
387
- * @since 1.0.0
388
- * @category Layers
424
+ * Layer that provides an `HttpClient` implementation backed by the browser `XMLHttpRequest` API.
425
+ *
426
+ * @category layers
427
+ * @since 4.0.0
389
428
  */
390
429
  export const layerXMLHttpRequest: Layer.Layer<HttpClient.HttpClient> = HttpClient.layerMergedContext(
391
430
  Effect.succeed(makeXmlHttpRequest)