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