@effect/platform-browser 4.0.0-beta.8 → 4.0.0-beta.80

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 +49 -0
  2. package/dist/BrowserCrypto.d.ts.map +1 -0
  3. package/dist/BrowserCrypto.js +87 -0
  4. package/dist/BrowserCrypto.js.map +1 -0
  5. package/dist/BrowserHttpClient.d.ts +48 -19
  6. package/dist/BrowserHttpClient.d.ts.map +1 -1
  7. package/dist/BrowserHttpClient.js +62 -21
  8. package/dist/BrowserHttpClient.js.map +1 -1
  9. package/dist/BrowserKeyValueStore.d.ts +37 -14
  10. package/dist/BrowserKeyValueStore.d.ts.map +1 -1
  11. package/dist/BrowserKeyValueStore.js +144 -10
  12. package/dist/BrowserKeyValueStore.js.map +1 -1
  13. package/dist/BrowserPersistence.d.ts +40 -0
  14. package/dist/BrowserPersistence.d.ts.map +1 -0
  15. package/dist/BrowserPersistence.js +207 -0
  16. package/dist/BrowserPersistence.js.map +1 -0
  17. package/dist/BrowserRuntime.d.ts +64 -4
  18. package/dist/BrowserRuntime.d.ts.map +1 -1
  19. package/dist/BrowserRuntime.js +19 -1
  20. package/dist/BrowserRuntime.js.map +1 -1
  21. package/dist/BrowserSocket.d.ts +33 -6
  22. package/dist/BrowserSocket.d.ts.map +1 -1
  23. package/dist/BrowserSocket.js +33 -6
  24. package/dist/BrowserSocket.js.map +1 -1
  25. package/dist/BrowserStream.d.ts +19 -7
  26. package/dist/BrowserStream.d.ts.map +1 -1
  27. package/dist/BrowserStream.js +19 -7
  28. package/dist/BrowserStream.js.map +1 -1
  29. package/dist/BrowserWorker.d.ts +25 -4
  30. package/dist/BrowserWorker.d.ts.map +1 -1
  31. package/dist/BrowserWorker.js +34 -6
  32. package/dist/BrowserWorker.js.map +1 -1
  33. package/dist/BrowserWorkerRunner.d.ts +31 -6
  34. package/dist/BrowserWorkerRunner.d.ts.map +1 -1
  35. package/dist/BrowserWorkerRunner.js +43 -10
  36. package/dist/BrowserWorkerRunner.js.map +1 -1
  37. package/dist/Clipboard.d.ts +59 -14
  38. package/dist/Clipboard.d.ts.map +1 -1
  39. package/dist/Clipboard.js +34 -12
  40. package/dist/Clipboard.js.map +1 -1
  41. package/dist/Geolocation.d.ts +80 -25
  42. package/dist/Geolocation.d.ts.map +1 -1
  43. package/dist/Geolocation.js +48 -17
  44. package/dist/Geolocation.js.map +1 -1
  45. package/dist/IndexedDb.d.ts +75 -0
  46. package/dist/IndexedDb.d.ts.map +1 -0
  47. package/dist/IndexedDb.js +85 -0
  48. package/dist/IndexedDb.js.map +1 -0
  49. package/dist/IndexedDbDatabase.d.ts +153 -0
  50. package/dist/IndexedDbDatabase.d.ts.map +1 -0
  51. package/dist/IndexedDbDatabase.js +327 -0
  52. package/dist/IndexedDbDatabase.js.map +1 -0
  53. package/dist/IndexedDbQueryBuilder.d.ts +422 -0
  54. package/dist/IndexedDbQueryBuilder.d.ts.map +1 -0
  55. package/dist/IndexedDbQueryBuilder.js +935 -0
  56. package/dist/IndexedDbQueryBuilder.js.map +1 -0
  57. package/dist/IndexedDbTable.d.ts +166 -0
  58. package/dist/IndexedDbTable.d.ts.map +1 -0
  59. package/dist/IndexedDbTable.js +71 -0
  60. package/dist/IndexedDbTable.js.map +1 -0
  61. package/dist/IndexedDbVersion.d.ts +99 -0
  62. package/dist/IndexedDbVersion.d.ts.map +1 -0
  63. package/dist/IndexedDbVersion.js +44 -0
  64. package/dist/IndexedDbVersion.js.map +1 -0
  65. package/dist/Permissions.d.ts +52 -16
  66. package/dist/Permissions.d.ts.map +1 -1
  67. package/dist/Permissions.js +42 -11
  68. package/dist/Permissions.js.map +1 -1
  69. package/dist/index.d.ts +38 -10
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +38 -10
  72. package/dist/index.js.map +1 -1
  73. package/package.json +4 -3
  74. package/src/BrowserCrypto.ts +97 -0
  75. package/src/BrowserHttpClient.ts +72 -27
  76. package/src/BrowserKeyValueStore.ts +160 -12
  77. package/src/BrowserPersistence.ts +334 -0
  78. package/src/BrowserRuntime.ts +64 -4
  79. package/src/BrowserSocket.ts +33 -6
  80. package/src/BrowserStream.ts +19 -7
  81. package/src/BrowserWorker.ts +34 -6
  82. package/src/BrowserWorkerRunner.ts +43 -10
  83. package/src/Clipboard.ts +56 -14
  84. package/src/Geolocation.ts +76 -21
  85. package/src/IndexedDb.ts +113 -0
  86. package/src/IndexedDbDatabase.ts +648 -0
  87. package/src/IndexedDbQueryBuilder.ts +2032 -0
  88. package/src/IndexedDbTable.ts +260 -0
  89. package/src/IndexedDbVersion.ts +138 -0
  90. package/src/Permissions.ts +47 -14
  91. package/src/index.ts +45 -10
@@ -1,5 +1,11 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser DOM event streams.
3
+ *
4
+ * This module provides typed constructors that turn `window.addEventListener`
5
+ * and `document.addEventListener` events into Effect `Stream` values. Both
6
+ * helpers accept the usual listener options and an optional stream buffer size.
7
+ *
8
+ * @since 4.0.0
3
9
  */
4
10
 
5
11
  import * as Stream from "effect/Stream"
@@ -7,11 +13,14 @@ import * as Stream from "effect/Stream"
7
13
  /**
8
14
  * Creates a `Stream` from `window.addEventListener`.
9
15
  *
16
+ * **Details**
17
+ *
10
18
  * By default, the underlying buffer is unbounded in size. You can customize the
11
- * buffer size an object as the second argument with the `bufferSize` field.
19
+ * buffer size by passing an object as the second argument with the `bufferSize`
20
+ * field.
12
21
  *
13
- * @since 1.0.0
14
- * @category Streams
22
+ * @category streams
23
+ * @since 4.0.0
15
24
  */
16
25
  export const fromEventListenerWindow = <K extends keyof WindowEventMap>(
17
26
  type: K,
@@ -26,11 +35,14 @@ export const fromEventListenerWindow = <K extends keyof WindowEventMap>(
26
35
  /**
27
36
  * Creates a `Stream` from `document.addEventListener`.
28
37
  *
38
+ * **Details**
39
+ *
29
40
  * By default, the underlying buffer is unbounded in size. You can customize the
30
- * buffer size an object as the second argument with the `bufferSize` field.
41
+ * buffer size by passing an object as the second argument with the `bufferSize`
42
+ * field.
31
43
  *
32
- * @since 1.0.0
33
- * @category Streams
44
+ * @category streams
45
+ * @since 4.0.0
34
46
  */
35
47
  export const fromEventListenerDocument = <K extends keyof DocumentEventMap>(
36
48
  type: K,
@@ -1,5 +1,12 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Parent-side browser platform for Effect workers.
3
+ *
4
+ * `layerPlatform` provides the `WorkerPlatform` used to communicate with a
5
+ * browser `Worker`, `SharedWorker`, or `MessagePort` through Effect's worker
6
+ * protocol. `layer` combines that platform with a `Spawner` built from a
7
+ * callback that creates or returns the worker endpoint for each worker id.
8
+ *
9
+ * @since 4.0.0
3
10
  */
4
11
  import * as Deferred from "effect/Deferred"
5
12
  import * as Effect from "effect/Effect"
@@ -9,8 +16,27 @@ import * as Worker from "effect/unstable/workers/Worker"
9
16
  import { WorkerError, WorkerReceiveError } from "effect/unstable/workers/WorkerError"
10
17
 
11
18
  /**
12
- * @since 1.0.0
13
- * @category Layers
19
+ * Creates browser worker layers by combining the default `WorkerPlatform` with a spawner for `Worker`, `SharedWorker`, or `MessagePort` instances.
20
+ *
21
+ * **When to use**
22
+ *
23
+ * Use when you need both the browser `WorkerPlatform` and a `Spawner` from one
24
+ * layer.
25
+ *
26
+ * **Details**
27
+ *
28
+ * The `spawn` callback receives the numeric worker id and may return a
29
+ * `Worker`, `SharedWorker`, or `MessagePort`.
30
+ *
31
+ * **Gotchas**
32
+ *
33
+ * Scope finalization sends the worker close protocol over the port. Dedicated
34
+ * workers created by `spawn` are not terminated by this layer.
35
+ *
36
+ * @see {@link layerPlatform} for providing only the browser worker platform
37
+ *
38
+ * @category layers
39
+ * @since 4.0.0
14
40
  */
15
41
  export const layer = (
16
42
  spawn: (id: number) => Worker | SharedWorker | MessagePort
@@ -21,8 +47,10 @@ export const layer = (
21
47
  )
22
48
 
23
49
  /**
24
- * @since 1.0.0
25
- * @category Layers
50
+ * Layer that provides the browser `WorkerPlatform` for `Worker`, `SharedWorker`, and `MessagePort` communication.
51
+ *
52
+ * @category layers
53
+ * @since 4.0.0
26
54
  */
27
55
  export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(Worker.WorkerPlatform)(
28
56
  Worker.makePlatform<globalThis.SharedWorker | globalThis.Worker | MessagePort>()({
@@ -50,7 +78,7 @@ export const layerPlatform: Layer.Layer<Worker.WorkerPlatform> = Layer.succeed(W
50
78
  message: "An error event was emitter",
51
79
  cause: event.error ?? event.message
52
80
  })
53
- }).asEffect()
81
+ })
54
82
  )
55
83
  }
56
84
  port.addEventListener("message", onMessage as any)
@@ -1,5 +1,13 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Runner-side browser platform for Effect worker handlers.
3
+ *
4
+ * `make` builds a `WorkerRunnerPlatform` over a `MessagePort` or `Window`.
5
+ * `layer` provides the platform from the global worker `self`, and
6
+ * `layerMessagePort` provides it from an explicit endpoint. The platform
7
+ * receives parent or client messages, runs Effect handlers, and posts responses
8
+ * back through the browser messaging channel.
9
+ *
10
+ * @since 4.0.0
3
11
  */
4
12
  import * as Cause from "effect/Cause"
5
13
  import * as Deferred from "effect/Deferred"
@@ -22,8 +30,10 @@ if (typeof self !== "undefined" && "onconnect" in self) {
22
30
  }
23
31
 
24
32
  /**
25
- * @since 1.0.0
26
- * @category Constructors
33
+ * Creates a `WorkerRunnerPlatform` service that runs worker handlers over a `MessagePort` or `Window`.
34
+ *
35
+ * @category constructors
36
+ * @since 4.0.0
27
37
  */
28
38
  export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatform["Service"] => ({
29
39
  start: Effect.fnUntraced(function*<O = unknown, I = unknown>() {
@@ -44,7 +54,7 @@ export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatf
44
54
  Effect.scopedWith(Effect.fnUntraced(function*(scope) {
45
55
  const closeLatch = Deferred.makeUnsafe<void, WorkerError>()
46
56
  const trackFiber = Fiber.runIn(scope)
47
- const services = yield* Effect.services<R>()
57
+ const services = yield* Effect.context<R>()
48
58
  const runFork = Effect.runForkWith(services)
49
59
  const onExit = (exit: Exit.Exit<any, E>) => {
50
60
  if (exit._tag === "Failure" && !Cause.hasInterruptsOnly(exit.cause)) {
@@ -83,7 +93,7 @@ export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatf
83
93
  message: "An messageerror event was emitted",
84
94
  cause: error.data
85
95
  })
86
- }).asEffect()
96
+ })
87
97
  )
88
98
  }
89
99
  function onError(error: any) {
@@ -94,7 +104,7 @@ export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatf
94
104
  message: "An error event was emitted",
95
105
  cause: error.data
96
106
  })
97
- }).asEffect()
107
+ })
98
108
  )
99
109
  }
100
110
  function handlePort(port: MessagePort) {
@@ -151,16 +161,39 @@ export const make = (self: MessagePort | Window): WorkerRunner.WorkerRunnerPlatf
151
161
  })
152
162
 
153
163
  /**
154
- * @since 1.0.0
155
- * @category Layers
164
+ * Layer that provides a browser `WorkerRunnerPlatform` using the global `self` worker context.
165
+ *
166
+ * **When to use**
167
+ *
168
+ * Use when you need a browser worker entry point to use the ambient `self`
169
+ * object as the worker transport.
170
+ *
171
+ * **Details**
172
+ *
173
+ * Delegates to `make(self)` and provides the runner-side platform used by
174
+ * protocols such as `RpcServer.layerProtocolWorkerRunner`.
175
+ *
176
+ * **Gotchas**
177
+ *
178
+ * This layer depends on the browser worker global `self`. Use
179
+ * `layerMessagePort` when the transport is an explicit `MessagePort` or
180
+ * `Window`.
181
+ *
182
+ * @see {@link make} for constructing a runner platform from an explicit endpoint
183
+ * @see {@link layerMessagePort} for providing a platform from an explicit endpoint
184
+ *
185
+ * @category layers
186
+ * @since 4.0.0
156
187
  */
157
188
  export const layer: Layer.Layer<WorkerRunner.WorkerRunnerPlatform> = Layer.sync(WorkerRunner.WorkerRunnerPlatform)(() =>
158
189
  make(self)
159
190
  )
160
191
 
161
192
  /**
162
- * @since 1.0.0
163
- * @category Layers
193
+ * Layer that provides a `WorkerRunnerPlatform` using the supplied `MessagePort` or `Window`.
194
+ *
195
+ * @category layers
196
+ * @since 4.0.0
164
197
  */
165
198
  export const layerMessagePort = (port: MessagePort | Window): Layer.Layer<WorkerRunner.WorkerRunnerPlatform> =>
166
199
  Layer.succeed(WorkerRunner.WorkerRunnerPlatform)(make(port))
package/src/Clipboard.ts CHANGED
@@ -1,17 +1,45 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser clipboard integration for Effect programs.
3
+ *
4
+ * This module defines the `Clipboard` service, the `ClipboardError` raised by
5
+ * failed browser operations, a `make` constructor for custom implementations,
6
+ * and a browser-backed `layer` that uses `navigator.clipboard`. The service
7
+ * supports reading and writing text, reading and writing `ClipboardItem`
8
+ * payloads, writing one `Blob`, and clearing the clipboard.
9
+ *
10
+ * @since 4.0.0
3
11
  */
12
+ import * as Context from "effect/Context"
4
13
  import * as Data from "effect/Data"
5
14
  import * as Effect from "effect/Effect"
6
15
  import * as Layer from "effect/Layer"
7
- import * as ServiceMap from "effect/ServiceMap"
8
16
 
9
17
  const TypeId = "~@effect/platform-browser/Clipboard"
10
18
  const ErrorTypeId = "~@effect/platform-browser/Clipboard/ClipboardError"
11
19
 
12
20
  /**
13
- * @since 1.0.0
14
- * @category Models
21
+ * Defines the service interface for reading from, writing to, and clearing the browser clipboard.
22
+ *
23
+ * **When to use**
24
+ *
25
+ * Use when an application needs clipboard operations through an Effect service
26
+ * so browser failures stay in the error channel.
27
+ *
28
+ * **Details**
29
+ *
30
+ * `read` and `write` work with `ClipboardItem` arrays. `readString` and
31
+ * `writeString` use text, `writeBlob` writes one `Blob`, and `clear` writes an
32
+ * empty string.
33
+ *
34
+ * **Gotchas**
35
+ *
36
+ * Clipboard access generally requires a secure context and may require user
37
+ * activation, permissions, or a focused document. `ClipboardItem` and non-text
38
+ * MIME type support varies by browser. Failed browser operations are surfaced
39
+ * as `ClipboardError`.
40
+ *
41
+ * @category models
42
+ * @since 4.0.0
15
43
  */
16
44
  export interface Clipboard {
17
45
  readonly [TypeId]: typeof TypeId
@@ -24,8 +52,10 @@ export interface Clipboard {
24
52
  }
25
53
 
26
54
  /**
27
- * @since 1.0.0
28
- * @category Errors
55
+ * Tagged error raised when a browser clipboard operation fails.
56
+ *
57
+ * @category errors
58
+ * @since 4.0.0
29
59
  */
30
60
  export class ClipboardError extends Data.TaggedError("ClipboardError")<{
31
61
  readonly message: string
@@ -35,14 +65,26 @@ export class ClipboardError extends Data.TaggedError("ClipboardError")<{
35
65
  }
36
66
 
37
67
  /**
38
- * @since 1.0.0
39
- * @category Service
68
+ * Service tag for browser clipboard capabilities.
69
+ *
70
+ * **When to use**
71
+ *
72
+ * Use when you need to require or provide clipboard capabilities through
73
+ * Effect's context.
74
+ *
75
+ * @see {@link make} for building a custom clipboard service
76
+ * @see {@link layer} for providing the browser-backed clipboard service
77
+ *
78
+ * @category services
79
+ * @since 4.0.0
40
80
  */
41
- export const Clipboard: ServiceMap.Service<Clipboard, Clipboard> = ServiceMap.Service<Clipboard>(TypeId)
81
+ export const Clipboard: Context.Service<Clipboard, Clipboard> = Context.Service<Clipboard>(TypeId)
42
82
 
43
83
  /**
44
- * @since 1.0.0
45
- * @category Constructors
84
+ * Builds a `Clipboard` service from primitive read and write operations, deriving `clear` and `writeBlob` helpers.
85
+ *
86
+ * @category constructors
87
+ * @since 4.0.0
46
88
  */
47
89
  export const make = (
48
90
  impl: Omit<Clipboard, "clear" | "writeBlob" | typeof TypeId>
@@ -55,10 +97,10 @@ export const make = (
55
97
  })
56
98
 
57
99
  /**
58
- * A layer that directly interfaces with the navigator.clipboard api
100
+ * Layer that directly interfaces with the browser Clipboard API.
59
101
  *
60
- * @since 1.0.0
61
- * @category Layers
102
+ * @category layers
103
+ * @since 4.0.0
62
104
  */
63
105
  export const layer: Layer.Layer<Clipboard> = Layer.succeed(
64
106
  Clipboard,
@@ -1,20 +1,51 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser geolocation integration for Effect programs.
3
+ *
4
+ * This module defines a `Geolocation` service backed by
5
+ * `navigator.geolocation`. The service can read one current position or stream
6
+ * watched position updates with a sliding buffer. Browser callback failures are
7
+ * represented as `GeolocationError` values with `PositionUnavailable`,
8
+ * `PermissionDenied`, or `Timeout` reasons. The module also provides the
9
+ * browser-backed layer and a `watchPosition` accessor.
10
+ *
11
+ * @since 4.0.0
3
12
  */
4
13
  import * as Cause from "effect/Cause"
14
+ import * as Context from "effect/Context"
5
15
  import * as Data from "effect/Data"
6
16
  import * as Effect from "effect/Effect"
7
17
  import * as Layer from "effect/Layer"
8
18
  import * as Queue from "effect/Queue"
9
- import * as ServiceMap from "effect/ServiceMap"
10
19
  import * as Stream from "effect/Stream"
11
20
 
12
21
  const TypeId = "~@effect/platform-browser/Geolocation"
13
22
  const ErrorTypeId = "~@effect/platform-browser/Geolocation/GeolocationError"
14
23
 
15
24
  /**
16
- * @since 1.0.0
17
- * @category Models
25
+ * Defines the service interface for browser geolocation, providing effects for the current position and streams of watched positions.
26
+ *
27
+ * **When to use**
28
+ *
29
+ * Use when browser code needs a typed Effect service for one-shot location
30
+ * reads or streamed location updates.
31
+ *
32
+ * **Details**
33
+ *
34
+ * `getCurrentPosition` returns one position effect. `watchPosition` returns a
35
+ * stream and accepts the browser `PositionOptions` plus an optional sliding
36
+ * `bufferSize`.
37
+ *
38
+ * **Gotchas**
39
+ *
40
+ * Browser permission prompts, denied permissions, timeouts, unavailable
41
+ * position data, secure-context restrictions, and policy restrictions are
42
+ * surfaced as `GeolocationError`.
43
+ *
44
+ * @see {@link GeolocationError} for represented browser geolocation failures
45
+ * @see {@link layer} for the browser-backed service implementation
46
+ *
47
+ * @category models
48
+ * @since 4.0.0
18
49
  */
19
50
  export interface Geolocation {
20
51
  readonly [TypeId]: typeof TypeId
@@ -31,14 +62,25 @@ export interface Geolocation {
31
62
  }
32
63
 
33
64
  /**
34
- * @since 1.0.0
35
- * @category Service
65
+ * Service tag for browser geolocation capabilities.
66
+ *
67
+ * **When to use**
68
+ *
69
+ * Use when you need to access or provide geolocation capabilities through
70
+ * Effect's context.
71
+ *
72
+ * @see {@link layer} for providing the browser-backed geolocation service
73
+ *
74
+ * @category services
75
+ * @since 4.0.0
36
76
  */
37
- export const Geolocation: ServiceMap.Service<Geolocation, Geolocation> = ServiceMap.Service<Geolocation>(TypeId)
77
+ export const Geolocation: Context.Service<Geolocation, Geolocation> = Context.Service<Geolocation>(TypeId)
38
78
 
39
79
  /**
40
- * @since 1.0.0
41
- * @category Errors
80
+ * Tagged error wrapping a browser geolocation failure reason.
81
+ *
82
+ * @category errors
83
+ * @since 4.0.0
42
84
  */
43
85
  export class GeolocationError extends Data.TaggedError("GeolocationError")<{
44
86
  readonly reason: GeolocationErrorReason
@@ -60,8 +102,10 @@ export class GeolocationError extends Data.TaggedError("GeolocationError")<{
60
102
  }
61
103
 
62
104
  /**
63
- * @since 1.0.0
64
- * @category Errors
105
+ * Error reason for the browser geolocation `POSITION_UNAVAILABLE` failure.
106
+ *
107
+ * @category errors
108
+ * @since 4.0.0
65
109
  */
66
110
  export class PositionUnavailable extends Data.TaggedError("PositionUnavailable")<{
67
111
  readonly cause: unknown
@@ -72,8 +116,10 @@ export class PositionUnavailable extends Data.TaggedError("PositionUnavailable")
72
116
  }
73
117
 
74
118
  /**
75
- * @since 1.0.0
76
- * @category Errors
119
+ * Error reason for the browser geolocation `PERMISSION_DENIED` failure.
120
+ *
121
+ * @category errors
122
+ * @since 4.0.0
77
123
  */
78
124
  export class PermissionDenied extends Data.TaggedError("PermissionDenied")<{
79
125
  readonly cause: unknown
@@ -84,8 +130,10 @@ export class PermissionDenied extends Data.TaggedError("PermissionDenied")<{
84
130
  }
85
131
 
86
132
  /**
87
- * @since 1.0.0
88
- * @category Errors
133
+ * Error reason for the browser geolocation `TIMEOUT` failure.
134
+ *
135
+ * @category errors
136
+ * @since 4.0.0
89
137
  */
90
138
  export class Timeout extends Data.TaggedError("Timeout")<{
91
139
  readonly cause: unknown
@@ -96,8 +144,10 @@ export class Timeout extends Data.TaggedError("Timeout")<{
96
144
  }
97
145
 
98
146
  /**
99
- * @since 1.0.0
100
- * @category Errors
147
+ * Union of browser geolocation error reasons represented by the service.
148
+ *
149
+ * @category errors
150
+ * @since 4.0.0
101
151
  */
102
152
  export type GeolocationErrorReason = PositionUnavailable | PermissionDenied | Timeout
103
153
 
@@ -141,8 +191,10 @@ const makeQueue = (
141
191
  )
142
192
 
143
193
  /**
144
- * @since 1.0.0
145
- * @category Layers
194
+ * Layer that provides `Geolocation` using `navigator.geolocation`, with watched positions buffered in a sliding queue.
195
+ *
196
+ * @category layers
197
+ * @since 4.0.0
146
198
  */
147
199
  export const layer: Layer.Layer<Geolocation> = Layer.succeed(
148
200
  Geolocation,
@@ -162,8 +214,11 @@ export const layer: Layer.Layer<Geolocation> = Layer.succeed(
162
214
  )
163
215
 
164
216
  /**
165
- * @since 1.0.0
166
- * @category Accessors
217
+ * Reads geolocation positions from the `Geolocation` service as a stream, with
218
+ * an optional sliding buffer size.
219
+ *
220
+ * @category accessors
221
+ * @since 4.0.0
167
222
  */
168
223
  export const watchPosition = (
169
224
  options?:
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Browser IndexedDB primitives and key schemas for Effect applications.
3
+ *
4
+ * This module is the low-level bridge used by the platform-browser IndexedDB
5
+ * integration. It provides an `IndexedDb` service around the browser
6
+ * `indexedDB` factory and `IDBKeyRange` constructor, a `layerWindow` layer for
7
+ * wiring those primitives from `window`, and schemas for the key shapes accepted
8
+ * by IndexedDB object stores and indexes.
9
+ *
10
+ * @since 4.0.0
11
+ */
12
+ import * as Context from "effect/Context"
13
+ import * as Effect from "effect/Effect"
14
+ import * as Layer from "effect/Layer"
15
+ import * as Schema from "effect/Schema"
16
+
17
+ const TypeId = "~@effect/platform-browser/IndexedDb"
18
+
19
+ /**
20
+ * Service interface that provides the browser `indexedDB` factory and `IDBKeyRange` constructor.
21
+ *
22
+ * @category models
23
+ * @since 4.0.0
24
+ */
25
+ export interface IndexedDb {
26
+ readonly [TypeId]: typeof TypeId
27
+ readonly indexedDB: globalThis.IDBFactory
28
+ readonly IDBKeyRange: typeof globalThis.IDBKeyRange
29
+ }
30
+
31
+ /**
32
+ * Service tag for browser IndexedDB primitives.
33
+ *
34
+ * @category services
35
+ * @since 4.0.0
36
+ */
37
+ export const IndexedDb: Context.Service<IndexedDb, IndexedDb> = Context.Service<IndexedDb, IndexedDb>(TypeId)
38
+
39
+ /** @internal */
40
+ const IDBFlatKey = Schema.Union([
41
+ Schema.String,
42
+ Schema.Number.check(Schema.makeFilter((input) => !Number.isNaN(input))),
43
+ Schema.DateValid,
44
+ Schema.declare(
45
+ (input): input is BufferSource =>
46
+ input instanceof ArrayBuffer ||
47
+ (ArrayBuffer.isView(input) && input.buffer instanceof ArrayBuffer)
48
+ )
49
+ ])
50
+
51
+ /**
52
+ * Schema for IndexedDB keys: strings, non-NaN numbers, valid dates, buffer sources, or arrays of those flat key values.
53
+ *
54
+ * @category schemas
55
+ * @since 4.0.0
56
+ */
57
+ export const IDBValidKey = Schema.Union([IDBFlatKey, Schema.Array(IDBFlatKey)])
58
+
59
+ /**
60
+ * Schema for auto-incremented IndexedDB keys, accepting integers from 1 through `2 ** 53`.
61
+ *
62
+ * **When to use**
63
+ *
64
+ * Use when you need to define numeric key-path fields for `IndexedDbTable`
65
+ * definitions that use IndexedDB auto-increment keys.
66
+ *
67
+ * **Details**
68
+ *
69
+ * The schema accepts integer values from `1` through `2 ** 53`, matching the
70
+ * range used for generated IndexedDB auto-increment keys.
71
+ *
72
+ * @see {@link IDBValidKey} for the broader IndexedDB key schema
73
+ *
74
+ * @category schemas
75
+ * @since 4.0.0
76
+ */
77
+ export const AutoIncrement = Schema.Int.check(
78
+ Schema.isBetween({ minimum: 1, maximum: 2 ** 53 })
79
+ ).annotate({
80
+ identifier: "AutoIncrement",
81
+ title: "autoIncrement",
82
+ description: "Defines a valid autoIncrement key path for the IndexedDb table"
83
+ })
84
+
85
+ /**
86
+ * Creates an `IndexedDb` service from an `IDBFactory` and `IDBKeyRange` constructor.
87
+ *
88
+ * @category constructors
89
+ * @since 4.0.0
90
+ */
91
+ export const make = (impl: Omit<IndexedDb, typeof TypeId>): IndexedDb => IndexedDb.of({ [TypeId]: TypeId, ...impl })
92
+
93
+ /**
94
+ * Layer that provides `IndexedDb` from `window.indexedDB` and `window.IDBKeyRange`, failing with a config error when they are unavailable.
95
+ *
96
+ * @category constructors
97
+ * @since 4.0.0
98
+ */
99
+ export const layerWindow: Layer.Layer<IndexedDb> = Layer.effect(
100
+ IndexedDb,
101
+ Effect.suspend(() => {
102
+ if (window.indexedDB && window.IDBKeyRange) {
103
+ return Effect.succeed(
104
+ make({
105
+ indexedDB: window.indexedDB,
106
+ IDBKeyRange: window.IDBKeyRange
107
+ })
108
+ )
109
+ } else {
110
+ return Effect.die(new Error("window.indexedDB is not available"))
111
+ }
112
+ })
113
+ )