@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.
Files changed (91) hide show
  1. package/dist/BrowserCrypto.d.ts +67 -4
  2. package/dist/BrowserCrypto.d.ts.map +1 -1
  3. package/dist/BrowserCrypto.js +67 -4
  4. package/dist/BrowserCrypto.js.map +1 -1
  5. package/dist/BrowserHttpClient.d.ts +16 -3
  6. package/dist/BrowserHttpClient.d.ts.map +1 -1
  7. package/dist/BrowserHttpClient.js +16 -3
  8. package/dist/BrowserHttpClient.js.map +1 -1
  9. package/dist/BrowserKeyValueStore.d.ts +20 -0
  10. package/dist/BrowserKeyValueStore.d.ts.map +1 -1
  11. package/dist/BrowserKeyValueStore.js +70 -15
  12. package/dist/BrowserKeyValueStore.js.map +1 -1
  13. package/dist/BrowserPersistence.d.ts +19 -0
  14. package/dist/BrowserPersistence.d.ts.map +1 -1
  15. package/dist/BrowserPersistence.js +19 -0
  16. package/dist/BrowserPersistence.js.map +1 -1
  17. package/dist/BrowserRuntime.d.ts +48 -0
  18. package/dist/BrowserRuntime.d.ts.map +1 -1
  19. package/dist/BrowserRuntime.js +16 -0
  20. package/dist/BrowserRuntime.js.map +1 -1
  21. package/dist/BrowserSocket.d.ts +55 -22
  22. package/dist/BrowserSocket.d.ts.map +1 -1
  23. package/dist/BrowserSocket.js +55 -22
  24. package/dist/BrowserSocket.js.map +1 -1
  25. package/dist/BrowserStream.d.ts +36 -21
  26. package/dist/BrowserStream.d.ts.map +1 -1
  27. package/dist/BrowserStream.js +36 -21
  28. package/dist/BrowserStream.js.map +1 -1
  29. package/dist/BrowserWorker.d.ts +17 -0
  30. package/dist/BrowserWorker.d.ts.map +1 -1
  31. package/dist/BrowserWorker.js +50 -18
  32. package/dist/BrowserWorker.js.map +1 -1
  33. package/dist/BrowserWorkerRunner.d.ts +19 -0
  34. package/dist/BrowserWorkerRunner.d.ts.map +1 -1
  35. package/dist/BrowserWorkerRunner.js +45 -14
  36. package/dist/BrowserWorkerRunner.js.map +1 -1
  37. package/dist/Clipboard.d.ts +55 -18
  38. package/dist/Clipboard.d.ts.map +1 -1
  39. package/dist/Clipboard.js +39 -15
  40. package/dist/Clipboard.js.map +1 -1
  41. package/dist/Geolocation.d.ts +63 -19
  42. package/dist/Geolocation.d.ts.map +1 -1
  43. package/dist/Geolocation.js +42 -18
  44. package/dist/Geolocation.js.map +1 -1
  45. package/dist/IndexedDb.d.ts +12 -0
  46. package/dist/IndexedDb.d.ts.map +1 -1
  47. package/dist/IndexedDb.js +12 -0
  48. package/dist/IndexedDb.js.map +1 -1
  49. package/dist/IndexedDbDatabase.d.ts +19 -0
  50. package/dist/IndexedDbDatabase.d.ts.map +1 -1
  51. package/dist/IndexedDbDatabase.js +19 -0
  52. package/dist/IndexedDbDatabase.js.map +1 -1
  53. package/dist/IndexedDbQueryBuilder.d.ts +8 -0
  54. package/dist/IndexedDbQueryBuilder.d.ts.map +1 -1
  55. package/dist/IndexedDbQueryBuilder.js +8 -0
  56. package/dist/IndexedDbQueryBuilder.js.map +1 -1
  57. package/dist/IndexedDbTable.d.ts +55 -17
  58. package/dist/IndexedDbTable.d.ts.map +1 -1
  59. package/dist/IndexedDbTable.js +55 -17
  60. package/dist/IndexedDbTable.js.map +1 -1
  61. package/dist/IndexedDbVersion.d.ts +14 -0
  62. package/dist/IndexedDbVersion.d.ts.map +1 -1
  63. package/dist/IndexedDbVersion.js +14 -0
  64. package/dist/IndexedDbVersion.js.map +1 -1
  65. package/dist/Permissions.d.ts +48 -18
  66. package/dist/Permissions.d.ts.map +1 -1
  67. package/dist/Permissions.js +48 -18
  68. package/dist/Permissions.js.map +1 -1
  69. package/dist/index.d.ts +0 -319
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +0 -319
  72. package/dist/index.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/BrowserCrypto.ts +67 -4
  75. package/src/BrowserHttpClient.ts +16 -3
  76. package/src/BrowserKeyValueStore.ts +70 -15
  77. package/src/BrowserPersistence.ts +66 -9
  78. package/src/BrowserRuntime.ts +48 -0
  79. package/src/BrowserSocket.ts +55 -22
  80. package/src/BrowserStream.ts +33 -18
  81. package/src/BrowserWorker.ts +50 -18
  82. package/src/BrowserWorkerRunner.ts +45 -14
  83. package/src/Clipboard.ts +55 -18
  84. package/src/Geolocation.ts +63 -19
  85. package/src/IndexedDb.ts +12 -0
  86. package/src/IndexedDbDatabase.ts +19 -0
  87. package/src/IndexedDbQueryBuilder.ts +8 -0
  88. package/src/IndexedDbTable.ts +55 -17
  89. package/src/IndexedDbVersion.ts +14 -0
  90. package/src/Permissions.ts +48 -18
  91. package/src/index.ts +0 -319
@@ -1,19 +1,35 @@
1
1
  /**
2
- * Browser geolocation support for Effect programs.
3
- *
4
- * This module provides a `Geolocation` service and browser-backed layer for
5
- * reading device location through `navigator.geolocation`. Use
6
- * `getCurrentPosition` when an application needs one location fix, such as a
7
- * nearby-search, check-in, or delivery estimate, and `watchPosition` when it
8
- * needs a stream of updates for navigation, tracking, or location-aware UI.
9
- *
10
- * The implementation is browser-only and relies on the browser permission and
11
- * policy model for geolocation. Calls may prompt the user, fail when permission
12
- * is denied, time out, or report that position data is unavailable because of
13
- * device, browser, privacy, origin, or secure-context restrictions. Watched
14
- * positions are scoped so the underlying browser watch is cleared when the
15
- * stream is finalized, and slow consumers should account for the sliding
16
- * buffer used by `watchPosition`.
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
  */
@@ -29,7 +45,27 @@ const TypeId = "~@effect/platform-browser/Geolocation"
29
45
  const ErrorTypeId = "~@effect/platform-browser/Geolocation/GeolocationError"
30
46
 
31
47
  /**
32
- * Service interface for browser geolocation, providing effects for the current position and streams of watched positions.
48
+ * Defines the service interface for browser geolocation, providing effects for the current position and streams of watched positions.
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
33
69
  *
34
70
  * @category models
35
71
  * @since 4.0.0
@@ -49,7 +85,14 @@ export interface Geolocation {
49
85
  }
50
86
 
51
87
  /**
52
- * Service tag for the browser `Geolocation` service.
88
+ * Service tag for browser geolocation capabilities.
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
53
96
  *
54
97
  * @category services
55
98
  * @since 4.0.0
@@ -194,9 +237,10 @@ export const layer: Layer.Layer<Geolocation> = Layer.succeed(
194
237
  )
195
238
 
196
239
  /**
197
- * Streams positions from the `Geolocation` service using `watchPosition`, with an optional sliding buffer size.
240
+ * Reads geolocation positions from the `Geolocation` service as a stream, with
241
+ * an optional sliding buffer size.
198
242
  *
199
- * @category Accessors
243
+ * @category accessors
200
244
  * @since 4.0.0
201
245
  */
202
246
  export const watchPosition = (
package/src/IndexedDb.ts CHANGED
@@ -73,6 +73,18 @@ export const IDBValidKey = Schema.Union([IDBFlatKey, Schema.Array(IDBFlatKey)])
73
73
  /**
74
74
  * Schema for auto-incremented IndexedDB keys, accepting integers from 1 through `2 ** 53`.
75
75
  *
76
+ * **When to use**
77
+ *
78
+ * Use when defining numeric key-path fields for `IndexedDbTable` definitions
79
+ * that use IndexedDB auto-increment keys.
80
+ *
81
+ * **Details**
82
+ *
83
+ * The schema accepts integer values from `1` through `2 ** 53`, matching the
84
+ * range used for generated IndexedDB auto-increment keys.
85
+ *
86
+ * @see {@link IDBValidKey} for the broader IndexedDB key schema
87
+ *
76
88
  * @category schemas
77
89
  * @since 4.0.0
78
90
  */
@@ -123,6 +123,25 @@ export class IndexedDbDatabaseError extends Data.TaggedError(
123
123
  /**
124
124
  * Service tag for an open IndexedDB database, its `IDBKeyRange` constructor, reactivity service, and rebuild effect.
125
125
  *
126
+ * **When to use**
127
+ *
128
+ * Use when an effect needs access to the live database service after an
129
+ * `IndexedDbSchema` layer has been provided, especially for `rebuild` or
130
+ * lower-level database primitives.
131
+ *
132
+ * **Details**
133
+ *
134
+ * `database` is a mutable reference to the current `IDBDatabase`. `IDBKeyRange`
135
+ * and `reactivity` are shared with query builders created from the schema.
136
+ *
137
+ * **Gotchas**
138
+ *
139
+ * `rebuild` closes and deletes the browser database, then reopens it and reruns
140
+ * migrations. Records not recreated by migrations are removed.
141
+ *
142
+ * @see {@link IndexedDb.IndexedDb} for the lower-level browser IndexedDB primitives
143
+ * @see {@link make} for creating a schema that provides this service as a layer
144
+ *
126
145
  * @category models
127
146
  * @since 4.0.0
128
147
  */
@@ -84,6 +84,14 @@ export type ErrorReason =
84
84
  /**
85
85
  * Tagged error for IndexedDB query operations, carrying a query error reason and the original cause.
86
86
  *
87
+ * **Details**
88
+ *
89
+ * `reason` is the query failure category, `cause` preserves the underlying
90
+ * schema, IndexedDB request, transaction, or user callback failure, and
91
+ * `message` is set to the reason.
92
+ *
93
+ * @see {@link ErrorReason} for the supported failure categories
94
+ *
87
95
  * @category errors
88
96
  * @since 4.0.0
89
97
  */
@@ -1,21 +1,38 @@
1
1
  /**
2
- * Defines typed table descriptors for the browser IndexedDB integration.
3
- *
4
- * An `IndexedDbTable` records the object store name, row schema, primary key
5
- * path, indexes, auto-increment behavior, and transaction durability used by
6
- * database versions, migrations, and typed queries. These descriptors are
7
- * useful for local caches, offline-first application state, background queues,
8
- * drafts, and other browser-persisted data that should be validated through
9
- * `Schema`.
10
- *
11
- * Key paths and index paths must reference encoded schema fields whose values
12
- * are valid IndexedDB keys, and compound paths are represented as readonly
13
- * arrays. Tables without a key path use an out-of-line `key` that is added to
14
- * reads and required for writes, so the row schema itself cannot define a
15
- * `key` field. Auto-increment tables require a numeric key path; when that key
16
- * is omitted on write, the module uses a derived schema without the generated
17
- * key. Declaring indexes here types query builder index selection, but the
18
- * indexes still need to be created during database migrations.
2
+ * Typed object-store descriptors for the browser IndexedDB integration.
3
+ *
4
+ * An {@link IndexedDbTable} is the schema-backed description of one IndexedDB
5
+ * object store. It carries the store name, row schema, key path, index key
6
+ * paths, auto-increment mode, and transaction durability used by database
7
+ * versions, migrations, and typed queries.
8
+ *
9
+ * **Mental model**
10
+ *
11
+ * A table value is metadata. `make` does not create an object store; it gives
12
+ * database versions, migration helpers, and the query builder the information
13
+ * they need to type table names, validate rows, and choose schemas for reads
14
+ * and writes. The stored values are the encoded schema values accepted by
15
+ * IndexedDB, with derived schemas for out-of-line keys and generated
16
+ * auto-increment keys.
17
+ *
18
+ * **Common tasks**
19
+ *
20
+ * - Define object stores for browser caches, offline state, drafts, and
21
+ * background queues.
22
+ * - Reuse the same table descriptor in database versions, migrations, and
23
+ * typed queries.
24
+ * - Declare index key paths so query builders can restrict index names and key
25
+ * values.
26
+ *
27
+ * **Gotchas**
28
+ *
29
+ * Key paths and index paths point at encoded schema fields whose values must be
30
+ * valid IndexedDB keys. Tables without an inline key path use an out-of-line
31
+ * `key`, so the row schema cannot define a `key` field. Auto-increment tables
32
+ * require a numeric key path, and declared indexes still have to be created in
33
+ * migrations.
34
+ *
35
+ * @see {@link make} for constructing table descriptors.
19
36
  *
20
37
  * @since 4.0.0
21
38
  */
@@ -176,6 +193,27 @@ const Proto = {
176
193
  /**
177
194
  * Creates a typed IndexedDB table definition from its name, schema, optional key path, indexes, auto-increment flag, and durability.
178
195
  *
196
+ * **When to use**
197
+ *
198
+ * Use to define a typed object-store descriptor for inclusion in an
199
+ * `IndexedDbVersion` and for migration or query APIs.
200
+ *
201
+ * **Details**
202
+ *
203
+ * `autoIncrement` defaults to `false` and `durability` defaults to `"relaxed"`.
204
+ * Tables without a key path get a read schema that includes an out-of-line
205
+ * `key`, while auto-increment tables use a write schema where the generated key
206
+ * may be omitted.
207
+ *
208
+ * **Gotchas**
209
+ *
210
+ * Tables without a key path cannot define a `key` field in their row schema.
211
+ * Key paths and index paths must point to encoded fields whose values are valid
212
+ * IndexedDB keys, and declared indexes still need to be created during
213
+ * database migrations.
214
+ *
215
+ * @see `IndexedDbVersion.make` for grouping table definitions into a schema version
216
+ *
179
217
  * @category constructors
180
218
  * @since 4.0.0
181
219
  */
@@ -106,6 +106,20 @@ const makeProto = <Tables extends IndexedDbTable.AnyWithProps>(options: {
106
106
  /**
107
107
  * Creates an `IndexedDbVersion` from one or more table definitions.
108
108
  *
109
+ * **Details**
110
+ *
111
+ * The returned version exposes a `tables` map keyed by each table's
112
+ * `tableName`, and its type is the union of the supplied table definitions.
113
+ *
114
+ * **Gotchas**
115
+ *
116
+ * This constructor only describes the target schema; object stores and indexes
117
+ * still need to be created in the corresponding `IndexedDbDatabase` migration.
118
+ * Duplicate table names are not rejected, and the runtime map keeps the later
119
+ * table for a repeated key.
120
+ *
121
+ * @see {@link IndexedDbTable.make} for creating table definitions consumed by this constructor
122
+ *
109
123
  * @category constructors
110
124
  * @since 4.0.0
111
125
  */
@@ -1,20 +1,35 @@
1
1
  /**
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.
2
+ * Effect service for the browser Permissions API.
3
+ *
4
+ * This module wraps `navigator.permissions` in a `Permissions` service and a
5
+ * browser-backed layer. It lets browser programs query whether a capability is
6
+ * currently `granted`, `prompt`, or `denied` before deciding which UI or
7
+ * feature flow to show for geolocation, notifications, clipboard access,
8
+ * camera, microphone, persistent storage, and other browser-gated features.
9
+ *
10
+ * **Mental model**
11
+ *
12
+ * A permission query is a status read, not an access request. The service
13
+ * delegates to `navigator.permissions.query({ name })` and returns the browser's
14
+ * `PermissionStatus`, while browser rejections are represented as
15
+ * `PermissionsError` values.
16
+ *
17
+ * **Common tasks**
18
+ *
19
+ * - Check whether a feature is already available before rendering a prompt or
20
+ * settings path.
21
+ * - Require permission querying through Effect context instead of reaching for
22
+ * the ambient `navigator` in application code.
23
+ * - Provide the live browser implementation with `layer`.
24
+ *
25
+ * **Gotchas**
26
+ *
27
+ * Browser support for permission names and states is uneven, and unsupported or
28
+ * invalid descriptors may reject. Some permissions are only meaningful in
29
+ * secure contexts or after user activation. Returned `PermissionStatus` objects
30
+ * can change when the user updates browser settings or responds to prompts; if
31
+ * you subscribe to `change` or `onchange`, clean up listeners with the
32
+ * surrounding Effect scope.
18
33
  *
19
34
  * @since 4.0.0
20
35
  */
@@ -109,7 +124,12 @@ export class PermissionsError extends Data.TaggedError("PermissionsError")<{
109
124
  }
110
125
 
111
126
  /**
112
- * Service tag for the browser `Permissions` service.
127
+ * Service tag for browser permission querying.
128
+ *
129
+ * **When to use**
130
+ *
131
+ * Use when an Effect needs to require or provide browser permission querying
132
+ * through the context.
113
133
  *
114
134
  * @category services
115
135
  * @since 4.0.0
@@ -117,7 +137,17 @@ export class PermissionsError extends Data.TaggedError("PermissionsError")<{
117
137
  export const Permissions: Context.Service<Permissions, Permissions> = Context.Service<Permissions>(TypeId)
118
138
 
119
139
  /**
120
- * A layer that directly interfaces with the `navigator.permissions` api
140
+ * Provides the `Permissions` service using the browser `navigator.permissions` API.
141
+ *
142
+ * **When to use**
143
+ *
144
+ * Use when browser programs need a live `Permissions` service backed by the
145
+ * ambient `navigator.permissions` implementation.
146
+ *
147
+ * **Details**
148
+ *
149
+ * `query` delegates to `navigator.permissions.query({ name })` and wraps
150
+ * rejected browser operations in `PermissionsError`.
121
151
  *
122
152
  * @category layers
123
153
  * @since 4.0.0