@effect/platform-browser 4.0.0-beta.8 → 4.0.0-beta.81
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 +49 -0
- package/dist/BrowserCrypto.d.ts.map +1 -0
- package/dist/BrowserCrypto.js +87 -0
- package/dist/BrowserCrypto.js.map +1 -0
- package/dist/BrowserHttpClient.d.ts +48 -19
- package/dist/BrowserHttpClient.d.ts.map +1 -1
- package/dist/BrowserHttpClient.js +62 -21
- package/dist/BrowserHttpClient.js.map +1 -1
- package/dist/BrowserKeyValueStore.d.ts +37 -14
- package/dist/BrowserKeyValueStore.d.ts.map +1 -1
- package/dist/BrowserKeyValueStore.js +144 -10
- package/dist/BrowserKeyValueStore.js.map +1 -1
- package/dist/BrowserPersistence.d.ts +40 -0
- package/dist/BrowserPersistence.d.ts.map +1 -0
- package/dist/BrowserPersistence.js +207 -0
- package/dist/BrowserPersistence.js.map +1 -0
- package/dist/BrowserRuntime.d.ts +64 -4
- package/dist/BrowserRuntime.d.ts.map +1 -1
- package/dist/BrowserRuntime.js +19 -1
- package/dist/BrowserRuntime.js.map +1 -1
- package/dist/BrowserSocket.d.ts +33 -6
- package/dist/BrowserSocket.d.ts.map +1 -1
- package/dist/BrowserSocket.js +33 -6
- package/dist/BrowserSocket.js.map +1 -1
- package/dist/BrowserStream.d.ts +19 -7
- package/dist/BrowserStream.d.ts.map +1 -1
- package/dist/BrowserStream.js +19 -7
- package/dist/BrowserStream.js.map +1 -1
- package/dist/BrowserWorker.d.ts +25 -4
- package/dist/BrowserWorker.d.ts.map +1 -1
- package/dist/BrowserWorker.js +34 -6
- package/dist/BrowserWorker.js.map +1 -1
- package/dist/BrowserWorkerRunner.d.ts +31 -6
- package/dist/BrowserWorkerRunner.d.ts.map +1 -1
- package/dist/BrowserWorkerRunner.js +43 -10
- package/dist/BrowserWorkerRunner.js.map +1 -1
- package/dist/Clipboard.d.ts +59 -14
- package/dist/Clipboard.d.ts.map +1 -1
- package/dist/Clipboard.js +34 -12
- package/dist/Clipboard.js.map +1 -1
- package/dist/Geolocation.d.ts +80 -25
- package/dist/Geolocation.d.ts.map +1 -1
- package/dist/Geolocation.js +48 -17
- package/dist/Geolocation.js.map +1 -1
- package/dist/IndexedDb.d.ts +75 -0
- package/dist/IndexedDb.d.ts.map +1 -0
- package/dist/IndexedDb.js +85 -0
- package/dist/IndexedDb.js.map +1 -0
- package/dist/IndexedDbDatabase.d.ts +153 -0
- package/dist/IndexedDbDatabase.d.ts.map +1 -0
- package/dist/IndexedDbDatabase.js +327 -0
- package/dist/IndexedDbDatabase.js.map +1 -0
- package/dist/IndexedDbQueryBuilder.d.ts +422 -0
- package/dist/IndexedDbQueryBuilder.d.ts.map +1 -0
- package/dist/IndexedDbQueryBuilder.js +935 -0
- package/dist/IndexedDbQueryBuilder.js.map +1 -0
- package/dist/IndexedDbTable.d.ts +166 -0
- package/dist/IndexedDbTable.d.ts.map +1 -0
- package/dist/IndexedDbTable.js +71 -0
- package/dist/IndexedDbTable.js.map +1 -0
- package/dist/IndexedDbVersion.d.ts +99 -0
- package/dist/IndexedDbVersion.d.ts.map +1 -0
- package/dist/IndexedDbVersion.js +44 -0
- package/dist/IndexedDbVersion.js.map +1 -0
- package/dist/Permissions.d.ts +52 -16
- package/dist/Permissions.d.ts.map +1 -1
- package/dist/Permissions.js +42 -11
- package/dist/Permissions.js.map +1 -1
- package/dist/index.d.ts +38 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/BrowserCrypto.ts +97 -0
- package/src/BrowserHttpClient.ts +72 -27
- package/src/BrowserKeyValueStore.ts +160 -12
- package/src/BrowserPersistence.ts +334 -0
- package/src/BrowserRuntime.ts +64 -4
- package/src/BrowserSocket.ts +33 -6
- package/src/BrowserStream.ts +19 -7
- package/src/BrowserWorker.ts +34 -6
- package/src/BrowserWorkerRunner.ts +43 -10
- package/src/Clipboard.ts +56 -14
- package/src/Geolocation.ts +76 -21
- package/src/IndexedDb.ts +113 -0
- package/src/IndexedDbDatabase.ts +648 -0
- package/src/IndexedDbQueryBuilder.ts +2032 -0
- package/src/IndexedDbTable.ts +260 -0
- package/src/IndexedDbVersion.ts +138 -0
- package/src/Permissions.ts +47 -14
- package/src/index.ts +45 -10
package/dist/Clipboard.js
CHANGED
|
@@ -1,27 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
const TypeId = "~@effect/platform-browser/Clipboard";
|
|
9
17
|
const ErrorTypeId = "~@effect/platform-browser/Clipboard/ClipboardError";
|
|
10
18
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
19
|
+
* Tagged error raised when a browser clipboard operation fails.
|
|
20
|
+
*
|
|
21
|
+
* @category errors
|
|
22
|
+
* @since 4.0.0
|
|
13
23
|
*/
|
|
14
24
|
export class ClipboardError extends /*#__PURE__*/Data.TaggedError("ClipboardError") {
|
|
15
25
|
[ErrorTypeId] = ErrorTypeId;
|
|
16
26
|
}
|
|
17
27
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
28
|
+
* Service tag for browser clipboard capabilities.
|
|
29
|
+
*
|
|
30
|
+
* **When to use**
|
|
31
|
+
*
|
|
32
|
+
* Use when you need to require or provide clipboard capabilities through
|
|
33
|
+
* Effect's context.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link make} for building a custom clipboard service
|
|
36
|
+
* @see {@link layer} for providing the browser-backed clipboard service
|
|
37
|
+
*
|
|
38
|
+
* @category services
|
|
39
|
+
* @since 4.0.0
|
|
20
40
|
*/
|
|
21
|
-
export const Clipboard = /*#__PURE__*/
|
|
41
|
+
export const Clipboard = /*#__PURE__*/Context.Service(TypeId);
|
|
22
42
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
43
|
+
* Builds a `Clipboard` service from primitive read and write operations, deriving `clear` and `writeBlob` helpers.
|
|
44
|
+
*
|
|
45
|
+
* @category constructors
|
|
46
|
+
* @since 4.0.0
|
|
25
47
|
*/
|
|
26
48
|
export const make = impl => Clipboard.of({
|
|
27
49
|
...impl,
|
|
@@ -32,10 +54,10 @@ export const make = impl => Clipboard.of({
|
|
|
32
54
|
})])
|
|
33
55
|
});
|
|
34
56
|
/**
|
|
35
|
-
*
|
|
57
|
+
* Layer that directly interfaces with the browser Clipboard API.
|
|
36
58
|
*
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
59
|
+
* @category layers
|
|
60
|
+
* @since 4.0.0
|
|
39
61
|
*/
|
|
40
62
|
export const layer = /*#__PURE__*/Layer.succeed(Clipboard, /*#__PURE__*/make({
|
|
41
63
|
read: /*#__PURE__*/Effect.tryPromise({
|
package/dist/Clipboard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Clipboard.js","names":["Data","Effect","Layer","
|
|
1
|
+
{"version":3,"file":"Clipboard.js","names":["Context","Data","Effect","Layer","TypeId","ErrorTypeId","ClipboardError","TaggedError","Clipboard","Service","make","impl","of","clear","writeString","writeBlob","blob","write","ClipboardItem","type","layer","succeed","read","tryPromise","try","navigator","clipboard","catch","cause","s","readString","readText","text","writeText"],"sources":["../src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A,KAAMC,SAAS,CAACC,SAAS,CAACT,KAAK,CAACY,CAAC,CAAC;IACvCF,KAAK,EAAGC,KAAK,IACX,IAAItB,cAAc,CAAC;MACjBsB,KAAK;MACL,SAAS,EAAE;KACZ;GACJ,CAAC;EACJE,UAAU,eAAE5B,MAAM,CAACqB,UAAU,CAAC;IAC5BC,GAAG,EAAEA,CAAA,KAAMC,SAAS,CAACC,SAAS,CAACK,QAAQ,EAAE;IACzCJ,KAAK,EAAGC,KAAK,IACX,IAAItB,cAAc,CAAC;MACjBsB,KAAK;MACL,SAAS,EAAE;KACZ;GACJ,CAAC;EACFd,WAAW,EAAGkB,IAAY,IACxB9B,MAAM,CAACqB,UAAU,CAAC;IAChBC,GAAG,EAAEA,CAAA,KAAMC,SAAS,CAACC,SAAS,CAACO,SAAS,CAACD,IAAI,CAAC;IAC9CL,KAAK,EAAGC,KAAK,IACX,IAAItB,cAAc,CAAC;MACjBsB,KAAK;MACL,SAAS,EAAE;KACZ;GACJ;CACJ,CAAC,CACH","ignoreList":[]}
|
package/dist/Geolocation.d.ts
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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 Effect from "effect/Effect";
|
|
6
16
|
import * as Layer from "effect/Layer";
|
|
7
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
8
17
|
import * as Stream from "effect/Stream";
|
|
9
18
|
declare const TypeId = "~@effect/platform-browser/Geolocation";
|
|
10
19
|
declare const ErrorTypeId = "~@effect/platform-browser/Geolocation/GeolocationError";
|
|
11
20
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
21
|
+
* Defines the service interface for browser geolocation, providing effects for the current position and streams of watched positions.
|
|
22
|
+
*
|
|
23
|
+
* **When to use**
|
|
24
|
+
*
|
|
25
|
+
* Use when browser code needs a typed Effect service for one-shot location
|
|
26
|
+
* reads or streamed location updates.
|
|
27
|
+
*
|
|
28
|
+
* **Details**
|
|
29
|
+
*
|
|
30
|
+
* `getCurrentPosition` returns one position effect. `watchPosition` returns a
|
|
31
|
+
* stream and accepts the browser `PositionOptions` plus an optional sliding
|
|
32
|
+
* `bufferSize`.
|
|
33
|
+
*
|
|
34
|
+
* **Gotchas**
|
|
35
|
+
*
|
|
36
|
+
* Browser permission prompts, denied permissions, timeouts, unavailable
|
|
37
|
+
* position data, secure-context restrictions, and policy restrictions are
|
|
38
|
+
* surfaced as `GeolocationError`.
|
|
39
|
+
*
|
|
40
|
+
* @see {@link GeolocationError} for represented browser geolocation failures
|
|
41
|
+
* @see {@link layer} for the browser-backed service implementation
|
|
42
|
+
*
|
|
43
|
+
* @category models
|
|
44
|
+
* @since 4.0.0
|
|
14
45
|
*/
|
|
15
46
|
export interface Geolocation {
|
|
16
47
|
readonly [TypeId]: typeof TypeId;
|
|
@@ -20,16 +51,27 @@ export interface Geolocation {
|
|
|
20
51
|
} | undefined) => Stream.Stream<GeolocationPosition, GeolocationError>;
|
|
21
52
|
}
|
|
22
53
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
54
|
+
* Service tag for browser geolocation capabilities.
|
|
55
|
+
*
|
|
56
|
+
* **When to use**
|
|
57
|
+
*
|
|
58
|
+
* Use when you need to access or provide geolocation capabilities through
|
|
59
|
+
* Effect's context.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link layer} for providing the browser-backed geolocation service
|
|
62
|
+
*
|
|
63
|
+
* @category services
|
|
64
|
+
* @since 4.0.0
|
|
25
65
|
*/
|
|
26
|
-
export declare const Geolocation:
|
|
27
|
-
declare const GeolocationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
66
|
+
export declare const Geolocation: Context.Service<Geolocation, Geolocation>;
|
|
67
|
+
declare const GeolocationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
28
68
|
readonly _tag: "GeolocationError";
|
|
29
69
|
} & Readonly<A>;
|
|
30
70
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
71
|
+
* Tagged error wrapping a browser geolocation failure reason.
|
|
72
|
+
*
|
|
73
|
+
* @category errors
|
|
74
|
+
* @since 4.0.0
|
|
33
75
|
*/
|
|
34
76
|
export declare class GeolocationError extends GeolocationError_base<{
|
|
35
77
|
readonly reason: GeolocationErrorReason;
|
|
@@ -40,36 +82,42 @@ export declare class GeolocationError extends GeolocationError_base<{
|
|
|
40
82
|
readonly [ErrorTypeId] = "~@effect/platform-browser/Geolocation/GeolocationError";
|
|
41
83
|
get message(): string;
|
|
42
84
|
}
|
|
43
|
-
declare const PositionUnavailable_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
85
|
+
declare const PositionUnavailable_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
44
86
|
readonly _tag: "PositionUnavailable";
|
|
45
87
|
} & Readonly<A>;
|
|
46
88
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
89
|
+
* Error reason for the browser geolocation `POSITION_UNAVAILABLE` failure.
|
|
90
|
+
*
|
|
91
|
+
* @category errors
|
|
92
|
+
* @since 4.0.0
|
|
49
93
|
*/
|
|
50
94
|
export declare class PositionUnavailable extends PositionUnavailable_base<{
|
|
51
95
|
readonly cause: unknown;
|
|
52
96
|
}> {
|
|
53
97
|
get message(): string;
|
|
54
98
|
}
|
|
55
|
-
declare const PermissionDenied_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
99
|
+
declare const PermissionDenied_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
56
100
|
readonly _tag: "PermissionDenied";
|
|
57
101
|
} & Readonly<A>;
|
|
58
102
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
103
|
+
* Error reason for the browser geolocation `PERMISSION_DENIED` failure.
|
|
104
|
+
*
|
|
105
|
+
* @category errors
|
|
106
|
+
* @since 4.0.0
|
|
61
107
|
*/
|
|
62
108
|
export declare class PermissionDenied extends PermissionDenied_base<{
|
|
63
109
|
readonly cause: unknown;
|
|
64
110
|
}> {
|
|
65
111
|
get message(): string;
|
|
66
112
|
}
|
|
67
|
-
declare const Timeout_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
113
|
+
declare const Timeout_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
68
114
|
readonly _tag: "Timeout";
|
|
69
115
|
} & Readonly<A>;
|
|
70
116
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
117
|
+
* Error reason for the browser geolocation `TIMEOUT` failure.
|
|
118
|
+
*
|
|
119
|
+
* @category errors
|
|
120
|
+
* @since 4.0.0
|
|
73
121
|
*/
|
|
74
122
|
export declare class Timeout extends Timeout_base<{
|
|
75
123
|
readonly cause: unknown;
|
|
@@ -77,18 +125,25 @@ export declare class Timeout extends Timeout_base<{
|
|
|
77
125
|
get message(): string;
|
|
78
126
|
}
|
|
79
127
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
128
|
+
* Union of browser geolocation error reasons represented by the service.
|
|
129
|
+
*
|
|
130
|
+
* @category errors
|
|
131
|
+
* @since 4.0.0
|
|
82
132
|
*/
|
|
83
133
|
export type GeolocationErrorReason = PositionUnavailable | PermissionDenied | Timeout;
|
|
84
134
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
135
|
+
* Layer that provides `Geolocation` using `navigator.geolocation`, with watched positions buffered in a sliding queue.
|
|
136
|
+
*
|
|
137
|
+
* @category layers
|
|
138
|
+
* @since 4.0.0
|
|
87
139
|
*/
|
|
88
140
|
export declare const layer: Layer.Layer<Geolocation>;
|
|
89
141
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
142
|
+
* Reads geolocation positions from the `Geolocation` service as a stream, with
|
|
143
|
+
* an optional sliding buffer size.
|
|
144
|
+
*
|
|
145
|
+
* @category accessors
|
|
146
|
+
* @since 4.0.0
|
|
92
147
|
*/
|
|
93
148
|
export declare const watchPosition: (options?: (PositionOptions & {
|
|
94
149
|
readonly bufferSize?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Geolocation.d.ts","sourceRoot":"","sources":["../src/Geolocation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Geolocation.d.ts","sourceRoot":"","sources":["../src/Geolocation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,QAAA,MAAM,MAAM,0CAA0C,CAAA;AACtD,QAAA,MAAM,WAAW,2DAA2D,CAAA;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,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E7B;CACF;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,GAAG,gBAAgB,GAAG,OAAO,CAAA;AAyCrF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAe1C,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GACxB,UACE,CAAE,eAAe,GAAG;IAClB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACzC,IACC,SAAS,KACZ,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,CAI/D,CAAA"}
|
package/dist/Geolocation.js
CHANGED
|
@@ -1,23 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
const TypeId = "~@effect/platform-browser/Geolocation";
|
|
12
21
|
const ErrorTypeId = "~@effect/platform-browser/Geolocation/GeolocationError";
|
|
13
22
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
23
|
+
* Service tag for browser geolocation capabilities.
|
|
24
|
+
*
|
|
25
|
+
* **When to use**
|
|
26
|
+
*
|
|
27
|
+
* Use when you need to access or provide geolocation capabilities through
|
|
28
|
+
* Effect's context.
|
|
29
|
+
*
|
|
30
|
+
* @see {@link layer} for providing the browser-backed geolocation service
|
|
31
|
+
*
|
|
32
|
+
* @category services
|
|
33
|
+
* @since 4.0.0
|
|
16
34
|
*/
|
|
17
|
-
export const Geolocation = /*#__PURE__*/
|
|
35
|
+
export const Geolocation = /*#__PURE__*/Context.Service(TypeId);
|
|
18
36
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
37
|
+
* Tagged error wrapping a browser geolocation failure reason.
|
|
38
|
+
*
|
|
39
|
+
* @category errors
|
|
40
|
+
* @since 4.0.0
|
|
21
41
|
*/
|
|
22
42
|
export class GeolocationError extends /*#__PURE__*/Data.TaggedError("GeolocationError") {
|
|
23
43
|
constructor(props) {
|
|
@@ -32,8 +52,10 @@ export class GeolocationError extends /*#__PURE__*/Data.TaggedError("Geolocation
|
|
|
32
52
|
}
|
|
33
53
|
}
|
|
34
54
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
55
|
+
* Error reason for the browser geolocation `POSITION_UNAVAILABLE` failure.
|
|
56
|
+
*
|
|
57
|
+
* @category errors
|
|
58
|
+
* @since 4.0.0
|
|
37
59
|
*/
|
|
38
60
|
export class PositionUnavailable extends /*#__PURE__*/Data.TaggedError("PositionUnavailable") {
|
|
39
61
|
get message() {
|
|
@@ -41,8 +63,10 @@ export class PositionUnavailable extends /*#__PURE__*/Data.TaggedError("Position
|
|
|
41
63
|
}
|
|
42
64
|
}
|
|
43
65
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
66
|
+
* Error reason for the browser geolocation `PERMISSION_DENIED` failure.
|
|
67
|
+
*
|
|
68
|
+
* @category errors
|
|
69
|
+
* @since 4.0.0
|
|
46
70
|
*/
|
|
47
71
|
export class PermissionDenied extends /*#__PURE__*/Data.TaggedError("PermissionDenied") {
|
|
48
72
|
get message() {
|
|
@@ -50,8 +74,10 @@ export class PermissionDenied extends /*#__PURE__*/Data.TaggedError("PermissionD
|
|
|
50
74
|
}
|
|
51
75
|
}
|
|
52
76
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
77
|
+
* Error reason for the browser geolocation `TIMEOUT` failure.
|
|
78
|
+
*
|
|
79
|
+
* @category errors
|
|
80
|
+
* @since 4.0.0
|
|
55
81
|
*/
|
|
56
82
|
export class Timeout extends /*#__PURE__*/Data.TaggedError("Timeout") {
|
|
57
83
|
get message() {
|
|
@@ -83,8 +109,10 @@ const makeQueue = options => Queue.sliding(options?.bufferSize ?? 16).pipe(Effec
|
|
|
83
109
|
}
|
|
84
110
|
}, options)), handleId => Effect.sync(() => navigator.geolocation.clearWatch(handleId)))));
|
|
85
111
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
112
|
+
* Layer that provides `Geolocation` using `navigator.geolocation`, with watched positions buffered in a sliding queue.
|
|
113
|
+
*
|
|
114
|
+
* @category layers
|
|
115
|
+
* @since 4.0.0
|
|
88
116
|
*/
|
|
89
117
|
export const layer = /*#__PURE__*/Layer.succeed(Geolocation, /*#__PURE__*/Geolocation.of({
|
|
90
118
|
[TypeId]: TypeId,
|
|
@@ -92,8 +120,11 @@ export const layer = /*#__PURE__*/Layer.succeed(Geolocation, /*#__PURE__*/Geoloc
|
|
|
92
120
|
watchPosition: options => makeQueue(options).pipe(Effect.map(Stream.fromQueue), Stream.unwrap)
|
|
93
121
|
}));
|
|
94
122
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
123
|
+
* Reads geolocation positions from the `Geolocation` service as a stream, with
|
|
124
|
+
* an optional sliding buffer size.
|
|
125
|
+
*
|
|
126
|
+
* @category accessors
|
|
127
|
+
* @since 4.0.0
|
|
97
128
|
*/
|
|
98
129
|
export const watchPosition = options => Stream.unwrap(Effect.map(Effect.service(Geolocation), geolocation => geolocation.watchPosition(options)));
|
|
99
130
|
//# sourceMappingURL=Geolocation.js.map
|
package/dist/Geolocation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Geolocation.js","names":["Cause","Data","Effect","Layer","Queue","
|
|
1
|
+
{"version":3,"file":"Geolocation.js","names":["Cause","Context","Data","Effect","Layer","Queue","Stream","TypeId","ErrorTypeId","Geolocation","Service","GeolocationError","TaggedError","constructor","props","cause","reason","message","PositionUnavailable","_tag","PermissionDenied","Timeout","makeQueue","options","sliding","bufferSize","pipe","tap","queue","acquireRelease","sync","navigator","geolocation","watchPosition","position","offerUnsafe","code","PERMISSION_DENIED","error","failCauseUnsafe","fail","TIMEOUT","POSITION_UNAVAILABLE","handleId","clearWatch","layer","succeed","of","getCurrentPosition","flatMap","take","scoped","map","fromQueue","unwrap","service"],"sources":["../src/Geolocation.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;AAYA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,MAAMC,MAAM,GAAG,uCAAuC;AACtD,MAAMC,WAAW,GAAG,wDAAwD;AA0C5E;;;;;;;;;;;;;AAaA,OAAO,MAAMC,WAAW,gBAA8CR,OAAO,CAACS,OAAO,CAAcH,MAAM,CAAC;AAE1G;;;;;;AAMA,OAAM,MAAOI,gBAAiB,sBAAQT,IAAI,CAACU,WAAW,CAAC,kBAAkB,CAEvE;EACAC,YAAYC,KAEX;IACC,KAAK,CAAC;MACJ,GAAGA,KAAK;MACRC,KAAK,EAAED,KAAK,CAACE,MAAM,CAACD;KACd,CAAC;EACX;EAES,CAACP,WAAW,IAA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,IAEbjB,MAAM,CAACgD,MAAM,CAACnD,MAAM,CAACiD,GAAG,CACtBjD,MAAM,CAACoD,OAAO,CAAC9C,WAAW,CAAC,EAC1BuB,WAAW,IAAKA,WAAW,CAACC,aAAa,CAACV,OAAO,CAAC,CACpD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 Layer from "effect/Layer";
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
declare const TypeId = "~@effect/platform-browser/IndexedDb";
|
|
16
|
+
/**
|
|
17
|
+
* Service interface that provides the browser `indexedDB` factory and `IDBKeyRange` constructor.
|
|
18
|
+
*
|
|
19
|
+
* @category models
|
|
20
|
+
* @since 4.0.0
|
|
21
|
+
*/
|
|
22
|
+
export interface IndexedDb {
|
|
23
|
+
readonly [TypeId]: typeof TypeId;
|
|
24
|
+
readonly indexedDB: globalThis.IDBFactory;
|
|
25
|
+
readonly IDBKeyRange: typeof globalThis.IDBKeyRange;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Service tag for browser IndexedDB primitives.
|
|
29
|
+
*
|
|
30
|
+
* @category services
|
|
31
|
+
* @since 4.0.0
|
|
32
|
+
*/
|
|
33
|
+
export declare const IndexedDb: Context.Service<IndexedDb, IndexedDb>;
|
|
34
|
+
/**
|
|
35
|
+
* Schema for IndexedDB keys: strings, non-NaN numbers, valid dates, buffer sources, or arrays of those flat key values.
|
|
36
|
+
*
|
|
37
|
+
* @category schemas
|
|
38
|
+
* @since 4.0.0
|
|
39
|
+
*/
|
|
40
|
+
export declare const IDBValidKey: Schema.Union<readonly [Schema.Union<readonly [Schema.String, Schema.Number, Schema.DateValid, Schema.declare<BufferSource, unknown>]>, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number, Schema.DateValid, Schema.declare<BufferSource, unknown>]>>]>;
|
|
41
|
+
/**
|
|
42
|
+
* Schema for auto-incremented IndexedDB keys, accepting integers from 1 through `2 ** 53`.
|
|
43
|
+
*
|
|
44
|
+
* **When to use**
|
|
45
|
+
*
|
|
46
|
+
* Use when you need to define numeric key-path fields for `IndexedDbTable`
|
|
47
|
+
* definitions that use IndexedDB auto-increment keys.
|
|
48
|
+
*
|
|
49
|
+
* **Details**
|
|
50
|
+
*
|
|
51
|
+
* The schema accepts integer values from `1` through `2 ** 53`, matching the
|
|
52
|
+
* range used for generated IndexedDB auto-increment keys.
|
|
53
|
+
*
|
|
54
|
+
* @see {@link IDBValidKey} for the broader IndexedDB key schema
|
|
55
|
+
*
|
|
56
|
+
* @category schemas
|
|
57
|
+
* @since 4.0.0
|
|
58
|
+
*/
|
|
59
|
+
export declare const AutoIncrement: Schema.Int;
|
|
60
|
+
/**
|
|
61
|
+
* Creates an `IndexedDb` service from an `IDBFactory` and `IDBKeyRange` constructor.
|
|
62
|
+
*
|
|
63
|
+
* @category constructors
|
|
64
|
+
* @since 4.0.0
|
|
65
|
+
*/
|
|
66
|
+
export declare const make: (impl: Omit<IndexedDb, typeof TypeId>) => IndexedDb;
|
|
67
|
+
/**
|
|
68
|
+
* Layer that provides `IndexedDb` from `window.indexedDB` and `window.IDBKeyRange`, failing with a config error when they are unavailable.
|
|
69
|
+
*
|
|
70
|
+
* @category constructors
|
|
71
|
+
* @since 4.0.0
|
|
72
|
+
*/
|
|
73
|
+
export declare const layerWindow: Layer.Layer<IndexedDb>;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=IndexedDb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexedDb.d.ts","sourceRoot":"","sources":["../src/IndexedDb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,QAAA,MAAM,MAAM,wCAAwC,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,MAAM,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,UAAU,CAAA;IACzC,QAAQ,CAAC,WAAW,EAAE,OAAO,UAAU,CAAC,WAAW,CAAA;CACpD;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAiD,CAAA;AAc7G;;;;;GAKG;AACH,eAAO,MAAM,WAAW,wQAAuD,CAAA;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,YAMxB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,MAAM,IAAI,CAAC,SAAS,EAAE,OAAO,MAAM,CAAC,KAAG,SAAwD,CAAA;AAEpH;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAc9C,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
const TypeId = "~@effect/platform-browser/IndexedDb";
|
|
17
|
+
/**
|
|
18
|
+
* Service tag for browser IndexedDB primitives.
|
|
19
|
+
*
|
|
20
|
+
* @category services
|
|
21
|
+
* @since 4.0.0
|
|
22
|
+
*/
|
|
23
|
+
export const IndexedDb = /*#__PURE__*/Context.Service(TypeId);
|
|
24
|
+
/** @internal */
|
|
25
|
+
const IDBFlatKey = /*#__PURE__*/Schema.Union([Schema.String, /*#__PURE__*/Schema.Number.check(/*#__PURE__*/Schema.makeFilter(input => !Number.isNaN(input))), Schema.DateValid, /*#__PURE__*/Schema.declare(input => input instanceof ArrayBuffer || ArrayBuffer.isView(input) && input.buffer instanceof ArrayBuffer)]);
|
|
26
|
+
/**
|
|
27
|
+
* Schema for IndexedDB keys: strings, non-NaN numbers, valid dates, buffer sources, or arrays of those flat key values.
|
|
28
|
+
*
|
|
29
|
+
* @category schemas
|
|
30
|
+
* @since 4.0.0
|
|
31
|
+
*/
|
|
32
|
+
export const IDBValidKey = /*#__PURE__*/Schema.Union([IDBFlatKey, /*#__PURE__*/Schema.Array(IDBFlatKey)]);
|
|
33
|
+
/**
|
|
34
|
+
* Schema for auto-incremented IndexedDB keys, accepting integers from 1 through `2 ** 53`.
|
|
35
|
+
*
|
|
36
|
+
* **When to use**
|
|
37
|
+
*
|
|
38
|
+
* Use when you need to define numeric key-path fields for `IndexedDbTable`
|
|
39
|
+
* definitions that use IndexedDB auto-increment keys.
|
|
40
|
+
*
|
|
41
|
+
* **Details**
|
|
42
|
+
*
|
|
43
|
+
* The schema accepts integer values from `1` through `2 ** 53`, matching the
|
|
44
|
+
* range used for generated IndexedDB auto-increment keys.
|
|
45
|
+
*
|
|
46
|
+
* @see {@link IDBValidKey} for the broader IndexedDB key schema
|
|
47
|
+
*
|
|
48
|
+
* @category schemas
|
|
49
|
+
* @since 4.0.0
|
|
50
|
+
*/
|
|
51
|
+
export const AutoIncrement = /*#__PURE__*/Schema.Int.check(Schema.isBetween({
|
|
52
|
+
minimum: 1,
|
|
53
|
+
maximum: 2 ** 53
|
|
54
|
+
})).annotate({
|
|
55
|
+
identifier: "AutoIncrement",
|
|
56
|
+
title: "autoIncrement",
|
|
57
|
+
description: "Defines a valid autoIncrement key path for the IndexedDb table"
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Creates an `IndexedDb` service from an `IDBFactory` and `IDBKeyRange` constructor.
|
|
61
|
+
*
|
|
62
|
+
* @category constructors
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
export const make = impl => IndexedDb.of({
|
|
66
|
+
[TypeId]: TypeId,
|
|
67
|
+
...impl
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Layer that provides `IndexedDb` from `window.indexedDB` and `window.IDBKeyRange`, failing with a config error when they are unavailable.
|
|
71
|
+
*
|
|
72
|
+
* @category constructors
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
export const layerWindow = /*#__PURE__*/Layer.effect(IndexedDb, /*#__PURE__*/Effect.suspend(() => {
|
|
76
|
+
if (window.indexedDB && window.IDBKeyRange) {
|
|
77
|
+
return Effect.succeed(make({
|
|
78
|
+
indexedDB: window.indexedDB,
|
|
79
|
+
IDBKeyRange: window.IDBKeyRange
|
|
80
|
+
}));
|
|
81
|
+
} else {
|
|
82
|
+
return Effect.die(new Error("window.indexedDB is not available"));
|
|
83
|
+
}
|
|
84
|
+
}));
|
|
85
|
+
//# sourceMappingURL=IndexedDb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexedDb.js","names":["Context","Effect","Layer","Schema","TypeId","IndexedDb","Service","IDBFlatKey","Union","String","Number","check","makeFilter","input","isNaN","DateValid","declare","ArrayBuffer","isView","buffer","IDBValidKey","Array","AutoIncrement","Int","isBetween","minimum","maximum","annotate","identifier","title","description","make","impl","of","layerWindow","effect","suspend","window","indexedDB","IDBKeyRange","succeed","die","Error"],"sources":["../src/IndexedDb.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;AAWA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,MAAMC,MAAM,GAAG,qCAAqC;AAcpD;;;;;;AAMA,OAAO,MAAMC,SAAS,gBAA0CL,OAAO,CAACM,OAAO,CAAuBF,MAAM,CAAC;AAE7G;AACA,MAAMG,UAAU,gBAAGJ,MAAM,CAACK,KAAK,CAAC,CAC9BL,MAAM,CAACM,MAAM,eACbN,MAAM,CAACO,MAAM,CAACC,KAAK,cAACR,MAAM,CAACS,UAAU,CAAEC,KAAK,IAAK,CAACH,MAAM,CAACI,KAAK,CAACD,KAAK,CAAC,CAAC,CAAC,EACvEV,MAAM,CAACY,SAAS,eAChBZ,MAAM,CAACa,OAAO,CACXH,KAAK,IACJA,KAAK,YAAYI,WAAW,IAC3BA,WAAW,CAACC,MAAM,CAACL,KAAK,CAAC,IAAIA,KAAK,CAACM,MAAM,YAAYF,WAAY,CACrE,CACF,CAAC;AAEF;;;;;;AAMA,OAAO,MAAMG,WAAW,gBAAGjB,MAAM,CAACK,KAAK,CAAC,CAACD,UAAU,eAAEJ,MAAM,CAACkB,KAAK,CAACd,UAAU,CAAC,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;AAkBA,OAAO,MAAMe,aAAa,gBAAGnB,MAAM,CAACoB,GAAG,CAACZ,KAAK,CAC3CR,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