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