@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.
- package/dist/BrowserCrypto.d.ts +67 -4
- package/dist/BrowserCrypto.d.ts.map +1 -1
- package/dist/BrowserCrypto.js +67 -4
- package/dist/BrowserCrypto.js.map +1 -1
- package/dist/BrowserHttpClient.d.ts +16 -3
- package/dist/BrowserHttpClient.d.ts.map +1 -1
- package/dist/BrowserHttpClient.js +16 -3
- package/dist/BrowserHttpClient.js.map +1 -1
- package/dist/BrowserKeyValueStore.d.ts +20 -0
- package/dist/BrowserKeyValueStore.d.ts.map +1 -1
- package/dist/BrowserKeyValueStore.js +70 -15
- package/dist/BrowserKeyValueStore.js.map +1 -1
- package/dist/BrowserPersistence.d.ts +19 -0
- package/dist/BrowserPersistence.d.ts.map +1 -1
- package/dist/BrowserPersistence.js +19 -0
- package/dist/BrowserPersistence.js.map +1 -1
- package/dist/BrowserRuntime.d.ts +48 -0
- package/dist/BrowserRuntime.d.ts.map +1 -1
- package/dist/BrowserRuntime.js +16 -0
- package/dist/BrowserRuntime.js.map +1 -1
- package/dist/BrowserSocket.d.ts +55 -22
- package/dist/BrowserSocket.d.ts.map +1 -1
- package/dist/BrowserSocket.js +55 -22
- package/dist/BrowserSocket.js.map +1 -1
- package/dist/BrowserStream.d.ts +36 -21
- package/dist/BrowserStream.d.ts.map +1 -1
- package/dist/BrowserStream.js +36 -21
- package/dist/BrowserStream.js.map +1 -1
- package/dist/BrowserWorker.d.ts +17 -0
- package/dist/BrowserWorker.d.ts.map +1 -1
- package/dist/BrowserWorker.js +50 -18
- package/dist/BrowserWorker.js.map +1 -1
- package/dist/BrowserWorkerRunner.d.ts +19 -0
- package/dist/BrowserWorkerRunner.d.ts.map +1 -1
- package/dist/BrowserWorkerRunner.js +45 -14
- package/dist/BrowserWorkerRunner.js.map +1 -1
- package/dist/Clipboard.d.ts +55 -18
- package/dist/Clipboard.d.ts.map +1 -1
- package/dist/Clipboard.js +39 -15
- package/dist/Clipboard.js.map +1 -1
- package/dist/Geolocation.d.ts +63 -19
- package/dist/Geolocation.d.ts.map +1 -1
- package/dist/Geolocation.js +42 -18
- package/dist/Geolocation.js.map +1 -1
- package/dist/IndexedDb.d.ts +12 -0
- package/dist/IndexedDb.d.ts.map +1 -1
- package/dist/IndexedDb.js +12 -0
- package/dist/IndexedDb.js.map +1 -1
- package/dist/IndexedDbDatabase.d.ts +19 -0
- package/dist/IndexedDbDatabase.d.ts.map +1 -1
- package/dist/IndexedDbDatabase.js +19 -0
- package/dist/IndexedDbDatabase.js.map +1 -1
- package/dist/IndexedDbQueryBuilder.d.ts +8 -0
- package/dist/IndexedDbQueryBuilder.d.ts.map +1 -1
- package/dist/IndexedDbQueryBuilder.js +8 -0
- package/dist/IndexedDbQueryBuilder.js.map +1 -1
- package/dist/IndexedDbTable.d.ts +55 -17
- package/dist/IndexedDbTable.d.ts.map +1 -1
- package/dist/IndexedDbTable.js +55 -17
- package/dist/IndexedDbTable.js.map +1 -1
- package/dist/IndexedDbVersion.d.ts +14 -0
- package/dist/IndexedDbVersion.d.ts.map +1 -1
- package/dist/IndexedDbVersion.js +14 -0
- package/dist/IndexedDbVersion.js.map +1 -1
- package/dist/Permissions.d.ts +48 -18
- package/dist/Permissions.d.ts.map +1 -1
- package/dist/Permissions.js +48 -18
- package/dist/Permissions.js.map +1 -1
- package/dist/index.d.ts +0 -319
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -319
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/BrowserCrypto.ts +67 -4
- package/src/BrowserHttpClient.ts +16 -3
- package/src/BrowserKeyValueStore.ts +70 -15
- package/src/BrowserPersistence.ts +66 -9
- package/src/BrowserRuntime.ts +48 -0
- package/src/BrowserSocket.ts +55 -22
- package/src/BrowserStream.ts +33 -18
- package/src/BrowserWorker.ts +50 -18
- package/src/BrowserWorkerRunner.ts +45 -14
- package/src/Clipboard.ts +55 -18
- package/src/Geolocation.ts +63 -19
- package/src/IndexedDb.ts +12 -0
- package/src/IndexedDbDatabase.ts +19 -0
- package/src/IndexedDbQueryBuilder.ts +8 -0
- package/src/IndexedDbTable.ts +55 -17
- package/src/IndexedDbVersion.ts +14 -0
- package/src/Permissions.ts +48 -18
- package/src/index.ts +0 -319
package/dist/index.js
CHANGED
|
@@ -3,389 +3,70 @@
|
|
|
3
3
|
*/
|
|
4
4
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
5
5
|
/**
|
|
6
|
-
* Browser platform implementation of the Crypto service.
|
|
7
|
-
*
|
|
8
6
|
* @since 1.0.0
|
|
9
7
|
*/
|
|
10
8
|
export * as BrowserCrypto from "./BrowserCrypto.js";
|
|
11
9
|
/**
|
|
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
10
|
* @since 4.0.0
|
|
42
11
|
*/
|
|
43
12
|
export * as BrowserHttpClient from "./BrowserHttpClient.js";
|
|
44
13
|
/**
|
|
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
14
|
* @since 4.0.0
|
|
62
15
|
*/
|
|
63
16
|
export * as BrowserKeyValueStore from "./BrowserKeyValueStore.js";
|
|
64
17
|
/**
|
|
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
18
|
* @since 4.0.0
|
|
78
19
|
*/
|
|
79
20
|
export * as BrowserPersistence from "./BrowserPersistence.js";
|
|
80
21
|
/**
|
|
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
22
|
* @since 4.0.0
|
|
103
23
|
*/
|
|
104
24
|
export * as BrowserRuntime from "./BrowserRuntime.js";
|
|
105
25
|
/**
|
|
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
26
|
* @since 4.0.0
|
|
130
27
|
*/
|
|
131
28
|
export * as BrowserSocket from "./BrowserSocket.js";
|
|
132
29
|
/**
|
|
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
30
|
* @since 4.0.0
|
|
156
31
|
*/
|
|
157
32
|
export * as BrowserStream from "./BrowserStream.js";
|
|
158
33
|
/**
|
|
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
34
|
* @since 4.0.0
|
|
180
35
|
*/
|
|
181
36
|
export * as BrowserWorker from "./BrowserWorker.js";
|
|
182
37
|
/**
|
|
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
38
|
* @since 4.0.0
|
|
202
39
|
*/
|
|
203
40
|
export * as BrowserWorkerRunner from "./BrowserWorkerRunner.js";
|
|
204
41
|
/**
|
|
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
42
|
* @since 4.0.0
|
|
222
43
|
*/
|
|
223
44
|
export * as Clipboard from "./Clipboard.js";
|
|
224
45
|
/**
|
|
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
46
|
* @since 4.0.0
|
|
242
47
|
*/
|
|
243
48
|
export * as Geolocation from "./Geolocation.js";
|
|
244
49
|
/**
|
|
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
|
-
*
|
|
267
50
|
* @since 4.0.0
|
|
268
51
|
*/
|
|
269
52
|
export * as IndexedDb from "./IndexedDb.js";
|
|
270
53
|
/**
|
|
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
|
-
*
|
|
296
54
|
* @since 4.0.0
|
|
297
55
|
*/
|
|
298
56
|
export * as IndexedDbDatabase from "./IndexedDbDatabase.js";
|
|
299
57
|
/**
|
|
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
|
-
*
|
|
326
58
|
* @since 4.0.0
|
|
327
59
|
*/
|
|
328
60
|
export * as IndexedDbQueryBuilder from "./IndexedDbQueryBuilder.js";
|
|
329
61
|
/**
|
|
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
|
-
*
|
|
348
62
|
* @since 4.0.0
|
|
349
63
|
*/
|
|
350
64
|
export * as IndexedDbTable from "./IndexedDbTable.js";
|
|
351
65
|
/**
|
|
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
|
-
*
|
|
368
66
|
* @since 4.0.0
|
|
369
67
|
*/
|
|
370
68
|
export * as IndexedDbVersion from "./IndexedDbVersion.js";
|
|
371
69
|
/**
|
|
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
70
|
* @since 4.0.0
|
|
390
71
|
*/
|
|
391
72
|
export * as Permissions from "./Permissions.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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;;;AAGA,OAAO,KAAKA,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,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":[]}
|
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.
|
|
4
|
+
"version": "4.0.0-beta.72",
|
|
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.
|
|
48
|
+
"effect": "^4.0.0-beta.72"
|
|
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.
|
|
53
|
+
"effect": "^4.0.0-beta.72"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"multipasta": "^0.2.7"
|
package/src/BrowserCrypto.ts
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Browser
|
|
2
|
+
* Browser-backed implementation of Effect's Crypto service.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a `Crypto.Crypto` layer backed by the Web Crypto API.
|
|
5
|
+
* The {@link WebCrypto} context reference defaults to `globalThis.crypto`, so
|
|
6
|
+
* browser programs can use the standard implementation while tests or embedded
|
|
7
|
+
* runtimes can provide their own `Crypto` object.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* {@link layer} reads {@link WebCrypto}, adapts `getRandomValues` to the
|
|
12
|
+
* random byte primitive used by `effect/Crypto`, and delegates digest requests
|
|
13
|
+
* to `crypto.subtle.digest`. Higher-level helpers such as UUID generation are
|
|
14
|
+
* derived by the core Crypto service from those primitives.
|
|
15
|
+
*
|
|
16
|
+
* **Common tasks**
|
|
17
|
+
*
|
|
18
|
+
* - Provide cryptographic randomness, UUID generation, and digest operations in
|
|
19
|
+
* browser Effect programs with {@link layer}
|
|
20
|
+
* - Override {@link WebCrypto} in tests to make randomness or digest output
|
|
21
|
+
* deterministic
|
|
22
|
+
*
|
|
23
|
+
* **Gotchas**
|
|
24
|
+
*
|
|
25
|
+
* - The browser must expose `globalThis.crypto`; otherwise layer acquisition
|
|
26
|
+
* dies because no secure randomness source is available.
|
|
27
|
+
* - Digest support depends on `crypto.subtle.digest` and the algorithms the
|
|
28
|
+
* browser accepts. Rejected digest operations fail with `PlatformError`.
|
|
29
|
+
*
|
|
30
|
+
* **Example** (Provide browser crypto)
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { BrowserCrypto } from "@effect/platform-browser"
|
|
34
|
+
* import { Crypto, Effect } from "effect"
|
|
35
|
+
*
|
|
36
|
+
* const program = Effect.gen(function*() {
|
|
37
|
+
* const crypto = yield* Crypto.Crypto
|
|
38
|
+
* return yield* crypto.randomUUIDv4
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* Effect.runPromise(
|
|
42
|
+
* program.pipe(Effect.provide(BrowserCrypto.layer))
|
|
43
|
+
* ).then(console.log)
|
|
44
|
+
* ```
|
|
3
45
|
*
|
|
4
46
|
* @since 1.0.0
|
|
5
47
|
*/
|
|
@@ -10,9 +52,14 @@ import * as Layer from "effect/Layer"
|
|
|
10
52
|
import * as PlatformError from "effect/PlatformError"
|
|
11
53
|
|
|
12
54
|
/**
|
|
13
|
-
* Browser Web Crypto APIs used by the Crypto service implementation.
|
|
55
|
+
* Provides Browser Web Crypto APIs used by the Crypto service implementation.
|
|
56
|
+
*
|
|
57
|
+
* **When to use**
|
|
58
|
+
*
|
|
59
|
+
* Use to override the browser `Crypto` object used by the platform crypto
|
|
60
|
+
* layer.
|
|
14
61
|
*
|
|
15
|
-
* @category
|
|
62
|
+
* @category references
|
|
16
63
|
* @since 1.0.0
|
|
17
64
|
*/
|
|
18
65
|
export const WebCrypto = Context.Reference<Crypto>("@effect/platform-browser/Crypto/WebCrypto", {
|
|
@@ -20,7 +67,23 @@ export const WebCrypto = Context.Reference<Crypto>("@effect/platform-browser/Cry
|
|
|
20
67
|
})
|
|
21
68
|
|
|
22
69
|
/**
|
|
23
|
-
*
|
|
70
|
+
* Layer that directly interfaces with the Web Crypto API.
|
|
71
|
+
*
|
|
72
|
+
* **When to use**
|
|
73
|
+
*
|
|
74
|
+
* Use to provide cryptographic randomness, UUID generation, and digest
|
|
75
|
+
* operations in browser runtimes backed by `globalThis.crypto`.
|
|
76
|
+
*
|
|
77
|
+
* **Details**
|
|
78
|
+
*
|
|
79
|
+
* Random bytes are produced with `crypto.getRandomValues`. Digests are computed
|
|
80
|
+
* with `crypto.subtle.digest` and returned as `Uint8Array` values.
|
|
81
|
+
*
|
|
82
|
+
* **Gotchas**
|
|
83
|
+
*
|
|
84
|
+
* The layer dies if the Web Crypto object is unavailable. Digest operations
|
|
85
|
+
* fail with `PlatformError` when `crypto.subtle.digest` is unavailable or the
|
|
86
|
+
* browser rejects the digest request.
|
|
24
87
|
*
|
|
25
88
|
* @category layers
|
|
26
89
|
* @since 1.0.0
|
package/src/BrowserHttpClient.ts
CHANGED
|
@@ -71,9 +71,14 @@ export {
|
|
|
71
71
|
*/
|
|
72
72
|
layer as layerFetch,
|
|
73
73
|
/**
|
|
74
|
-
* Service
|
|
74
|
+
* Service that contains default fetch options for the browser fetch client.
|
|
75
75
|
*
|
|
76
|
-
*
|
|
76
|
+
* **When to use**
|
|
77
|
+
*
|
|
78
|
+
* Use to provide default credentials, cache, redirect, integrity, or other
|
|
79
|
+
* fetch options for browser HTTP requests.
|
|
80
|
+
*
|
|
81
|
+
* @category fetch
|
|
77
82
|
* @since 4.0.0
|
|
78
83
|
*/
|
|
79
84
|
RequestInit
|
|
@@ -92,7 +97,15 @@ export {
|
|
|
92
97
|
export type XHRResponseType = "arraybuffer" | "text"
|
|
93
98
|
|
|
94
99
|
/**
|
|
95
|
-
*
|
|
100
|
+
* Context reference for the `XMLHttpRequest.responseType` used by the browser XHR HTTP client, defaulting to `"text"`.
|
|
101
|
+
*
|
|
102
|
+
* **When to use**
|
|
103
|
+
*
|
|
104
|
+
* Use when XHR-backed HTTP requests need to receive response bodies as text or
|
|
105
|
+
* as raw `ArrayBuffer` values.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link XHRResponseType} for the allowed response body modes
|
|
108
|
+
* @see {@link withXHRArrayBuffer} for scoping XHR response handling to `ArrayBuffer`
|
|
96
109
|
*
|
|
97
110
|
* @category references
|
|
98
111
|
* @since 4.0.0
|
|
@@ -1,19 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Browser-backed `KeyValueStore` layers for Effect programs.
|
|
3
|
-
*
|
|
4
|
-
* This module provides
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
2
|
+
* Browser-backed `KeyValueStore` layers for client-side Effect programs.
|
|
3
|
+
*
|
|
4
|
+
* This module provides browser implementations of the unstable persistence
|
|
5
|
+
* `KeyValueStore` service. Use {@link layerLocalStorage} for small
|
|
6
|
+
* origin-scoped values that should survive reloads and browser restarts, use
|
|
7
|
+
* {@link layerSessionStorage} for tab / page-session state, and use
|
|
8
|
+
* {@link layerIndexedDb} when the store should be asynchronous and backed by
|
|
9
|
+
* IndexedDB.
|
|
10
|
+
*
|
|
11
|
+
* ## Mental model
|
|
12
|
+
*
|
|
13
|
+
* All exports provide the same `KeyValueStore.KeyValueStore` service; the layer
|
|
14
|
+
* chooses the browser storage backend. The Web Storage layers delegate to
|
|
15
|
+
* `globalThis.localStorage` or `globalThis.sessionStorage` and adapt the
|
|
16
|
+
* string-only API, encoding `Uint8Array` values as base64. The IndexedDB layer
|
|
17
|
+
* stores strings and `Uint8Array` values in an object store and requires the
|
|
18
|
+
* browser `IndexedDb` service to open the database.
|
|
19
|
+
*
|
|
20
|
+
* ## Common tasks
|
|
21
|
+
*
|
|
22
|
+
* - Persist user preferences, lightweight caches, or drafts with
|
|
23
|
+
* {@link layerLocalStorage}.
|
|
24
|
+
* - Keep tab-scoped workflow state with {@link layerSessionStorage}.
|
|
25
|
+
* - Avoid blocking the main thread for larger client-side stores by using
|
|
26
|
+
* {@link layerIndexedDb}.
|
|
27
|
+
*
|
|
28
|
+
* ## Gotchas
|
|
29
|
+
*
|
|
30
|
+
* These layers only work where browser storage APIs are available. Browsers may
|
|
31
|
+
* deny storage in private modes, sandboxed frames, disabled-storage settings, or
|
|
32
|
+
* quota-limited contexts. Web Storage is synchronous and origin-scoped, so keep
|
|
33
|
+
* payloads small and do not use it as a secure store for secrets. IndexedDB is
|
|
34
|
+
* asynchronous but can still be blocked by permissions, quota limits, version
|
|
35
|
+
* upgrades, or other open tabs.
|
|
36
|
+
*
|
|
37
|
+
* **Example** (Provide localStorage to a program)
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { BrowserKeyValueStore } from "@effect/platform-browser"
|
|
41
|
+
* import { Effect } from "effect"
|
|
42
|
+
* import { KeyValueStore } from "effect/unstable/persistence"
|
|
43
|
+
*
|
|
44
|
+
* const program = Effect.gen(function*() {
|
|
45
|
+
* const store = yield* KeyValueStore.KeyValueStore
|
|
46
|
+
* yield* store.set("theme", "dark")
|
|
47
|
+
* return yield* store.get("theme")
|
|
48
|
+
* }).pipe(
|
|
49
|
+
* Effect.provide(BrowserKeyValueStore.layerLocalStorage)
|
|
50
|
+
* )
|
|
51
|
+
* ```
|
|
17
52
|
*
|
|
18
53
|
* @since 4.0.0
|
|
19
54
|
*/
|
|
@@ -45,6 +80,26 @@ export const layerSessionStorage: Layer.Layer<KeyValueStore.KeyValueStore> = Key
|
|
|
45
80
|
/**
|
|
46
81
|
* Creates a `KeyValueStore` layer backed by IndexedDB.
|
|
47
82
|
*
|
|
83
|
+
* **When to use**
|
|
84
|
+
*
|
|
85
|
+
* Use when a browser `KeyValueStore` needs persistent asynchronous IndexedDB
|
|
86
|
+
* storage instead of the synchronous Web Storage APIs.
|
|
87
|
+
*
|
|
88
|
+
* **Details**
|
|
89
|
+
*
|
|
90
|
+
* The database name defaults to `"effect_key_value_store"`. The layer requires
|
|
91
|
+
* the `IndexedDb` service and stores string and `Uint8Array` values in the same
|
|
92
|
+
* backing object store.
|
|
93
|
+
*
|
|
94
|
+
* **Gotchas**
|
|
95
|
+
*
|
|
96
|
+
* IndexedDB may be unavailable or blocked by browser settings, private browsing,
|
|
97
|
+
* quota limits, or restricted contexts. The string and `Uint8Array` accessors do
|
|
98
|
+
* not coerce values stored with the other representation.
|
|
99
|
+
*
|
|
100
|
+
* @see {@link layerLocalStorage} for synchronous persistent Web Storage
|
|
101
|
+
* @see {@link layerSessionStorage} for synchronous tab-session Web Storage
|
|
102
|
+
*
|
|
48
103
|
* @category layers
|
|
49
104
|
* @since 4.0.0
|
|
50
105
|
*/
|