@effect/platform-browser 0.33.20 → 0.33.22
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/Geolocation/package.json +6 -0
- package/dist/cjs/Geolocation.js +93 -0
- package/dist/cjs/Geolocation.js.map +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/dts/Geolocation.d.ts +68 -0
- package/dist/dts/Geolocation.d.ts.map +1 -0
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/Geolocation.js +59 -0
- package/dist/esm/Geolocation.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +11 -3
- package/src/Geolocation.ts +133 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.watchPosition = exports.layer = exports.TypeId = exports.GeolocationError = exports.Geolocation = exports.ErrorTypeId = void 0;
|
|
7
|
+
var _Error = /*#__PURE__*/require("@effect/platform/Error");
|
|
8
|
+
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Context"));
|
|
9
|
+
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
10
|
+
var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Either"));
|
|
11
|
+
var _Function = /*#__PURE__*/require("effect/Function");
|
|
12
|
+
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
|
|
13
|
+
var Queue = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Queue"));
|
|
14
|
+
var Stream = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Stream"));
|
|
15
|
+
function _getRequireWildcardCache(e) {
|
|
16
|
+
if ("function" != typeof WeakMap) return null;
|
|
17
|
+
var r = new WeakMap(),
|
|
18
|
+
t = new WeakMap();
|
|
19
|
+
return (_getRequireWildcardCache = function (e) {
|
|
20
|
+
return e ? t : r;
|
|
21
|
+
})(e);
|
|
22
|
+
}
|
|
23
|
+
function _interopRequireWildcard(e, r) {
|
|
24
|
+
if (!r && e && e.__esModule) return e;
|
|
25
|
+
if (null === e || "object" != typeof e && "function" != typeof e) return {
|
|
26
|
+
default: e
|
|
27
|
+
};
|
|
28
|
+
var t = _getRequireWildcardCache(r);
|
|
29
|
+
if (t && t.has(e)) return t.get(e);
|
|
30
|
+
var n = {
|
|
31
|
+
__proto__: null
|
|
32
|
+
},
|
|
33
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
34
|
+
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
35
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
36
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
|
|
37
|
+
}
|
|
38
|
+
return n.default = e, t && t.set(e, n), n;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @since 1.0.0
|
|
46
|
+
* @category type ids
|
|
47
|
+
*/
|
|
48
|
+
const TypeId = exports.TypeId = /*#__PURE__*/Symbol.for("@effect/platform-browser/Geolocation");
|
|
49
|
+
/**
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
* @category tags
|
|
52
|
+
*/
|
|
53
|
+
const Geolocation = exports.Geolocation = /*#__PURE__*/Context.GenericTag("@effect/platform-browser/Geolocation");
|
|
54
|
+
/**
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
* @category type ids
|
|
57
|
+
*/
|
|
58
|
+
const ErrorTypeId = exports.ErrorTypeId = /*#__PURE__*/Symbol.for("@effect/platform-browser/Geolocation/GeolocationError");
|
|
59
|
+
/**
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @category errors
|
|
62
|
+
*/
|
|
63
|
+
class GeolocationError extends (0, _Error.RefailError)(ErrorTypeId, "GeolocationError") {}
|
|
64
|
+
exports.GeolocationError = GeolocationError;
|
|
65
|
+
const makeQueue = options => Queue.sliding(options?.bufferSize ?? 16).pipe(Effect.tap(queue => Effect.acquireRelease(Effect.sync(() => navigator.geolocation.watchPosition(position => queue.unsafeOffer(Either.right(position)), error => {
|
|
66
|
+
if (error.code === error.PERMISSION_DENIED) {
|
|
67
|
+
queue.unsafeOffer(Either.left(new GeolocationError({
|
|
68
|
+
reason: "PermissionDenied",
|
|
69
|
+
error
|
|
70
|
+
})));
|
|
71
|
+
} else if (error.code === error.TIMEOUT) {
|
|
72
|
+
queue.unsafeOffer(Either.left(new GeolocationError({
|
|
73
|
+
reason: "Timeout",
|
|
74
|
+
error
|
|
75
|
+
})));
|
|
76
|
+
}
|
|
77
|
+
}, options)), handleId => Effect.sync(() => navigator.geolocation.clearWatch(handleId)))));
|
|
78
|
+
/**
|
|
79
|
+
* @since 1.0.0
|
|
80
|
+
* @category layers
|
|
81
|
+
*/
|
|
82
|
+
const layer = exports.layer = /*#__PURE__*/Layer.succeed(Geolocation, /*#__PURE__*/Geolocation.of({
|
|
83
|
+
[TypeId]: TypeId,
|
|
84
|
+
getCurrentPosition: options => makeQueue(options).pipe(Effect.flatMap(Queue.take), Effect.flatten, Effect.scoped),
|
|
85
|
+
watchPosition: options => makeQueue(options).pipe(Effect.map(Stream.fromQueue), Stream.unwrapScoped, Stream.mapEffect(_Function.identity))
|
|
86
|
+
}));
|
|
87
|
+
/**
|
|
88
|
+
* @since 1.0.0
|
|
89
|
+
* @category accessors
|
|
90
|
+
*/
|
|
91
|
+
const watchPosition = options => Stream.unwrap(Effect.map(Geolocation, geolocation => geolocation.watchPosition(options)));
|
|
92
|
+
exports.watchPosition = watchPosition;
|
|
93
|
+
//# sourceMappingURL=Geolocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Geolocation.js","names":["_Error","require","Context","_interopRequireWildcard","Effect","Either","_Function","Layer","Queue","Stream","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","TypeId","exports","Symbol","for","Geolocation","GenericTag","ErrorTypeId","GeolocationError","RefailError","makeQueue","options","sliding","bufferSize","pipe","tap","queue","acquireRelease","sync","navigator","geolocation","watchPosition","position","unsafeOffer","right","error","code","PERMISSION_DENIED","left","reason","TIMEOUT","handleId","clearWatch","layer","succeed","of","getCurrentPosition","flatMap","take","flatten","scoped","map","fromQueue","unwrapScoped","mapEffect","identity","unwrap"],"sources":["../../src/Geolocation.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,MAAA,gBAAAC,OAAA;AACA,IAAAC,OAAA,gBAAAC,uBAAA,eAAAF,OAAA;AACA,IAAAG,MAAA,gBAAAD,uBAAA,eAAAF,OAAA;AACA,IAAAI,MAAA,gBAAAF,uBAAA,eAAAF,OAAA;AACA,IAAAK,SAAA,gBAAAL,OAAA;AACA,IAAAM,KAAA,gBAAAJ,uBAAA,eAAAF,OAAA;AACA,IAAAO,KAAA,gBAAAL,uBAAA,eAAAF,OAAA;AACA,IAAAQ,MAAA,gBAAAN,uBAAA,eAAAF,OAAA;AAAuC,SAAAS,yBAAAC,CAAA;EAAA,yBAAAC,OAAA;EAAA,IAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAF,wBAAA,YAAAA,CAAAC,CAAA;IAAA,OAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA;EAAA,GAAAF,CAAA;AAAA;AAAA,SAAAR,wBAAAQ,CAAA,EAAAE,CAAA;EAAA,KAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA;EAAA,aAAAA,CAAA,uBA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D,SAAS,CAACC,OAAO,CAAC,CAACG,IAAI,CACrBvC,MAAM,CAAC8D,OAAO,CAAC1D,KAAK,CAAC2D,IAAI,CAAC,EAC1B/D,MAAM,CAACgE,OAAO,EACdhE,MAAM,CAACiE,MAAM,CACd;EACHnB,aAAa,EAAGV,OAAO,IACrBD,SAAS,CAACC,OAAO,CAAC,CAACG,IAAI,CACrBvC,MAAM,CAACkE,GAAG,CAAC7D,MAAM,CAAC8D,SAAS,CAAC,EAC5B9D,MAAM,CAAC+D,YAAY,EACnB/D,MAAM,CAACgE,SAAS,CAACnE,SAAA,CAAAoE,QAAQ,CAAC;CAE/B,CAAC,CACH;AAED;;;;AAIO,MAAMxB,aAAa,GACxBV,OAIa,IAEb/B,MAAM,CAACkE,MAAM,CAACvE,MAAM,CAACkE,GAAG,CAACpC,WAAW,EAAGe,WAAW,IAAKA,WAAW,CAACC,aAAa,CAACV,OAAO,CAAC,CAAC,CAAC;AAAAT,OAAA,CAAAmB,aAAA,GAAAA,aAAA","ignoreList":[]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Clipboard = exports.BrowserWorkerRunner = exports.BrowserWorker = exports.BrowserStream = exports.BrowserRuntime = exports.BrowserKeyValueStore = exports.BrowserHttpClient = exports.BrowerSocket = void 0;
|
|
6
|
+
exports.Geolocation = exports.Clipboard = exports.BrowserWorkerRunner = exports.BrowserWorker = exports.BrowserStream = exports.BrowserRuntime = exports.BrowserKeyValueStore = exports.BrowserHttpClient = exports.BrowerSocket = void 0;
|
|
7
7
|
var _BrowerSocket = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./BrowerSocket.js"));
|
|
8
8
|
exports.BrowerSocket = _BrowerSocket;
|
|
9
9
|
var _BrowserHttpClient = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./BrowserHttpClient.js"));
|
|
@@ -20,6 +20,8 @@ var _BrowserWorkerRunner = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/re
|
|
|
20
20
|
exports.BrowserWorkerRunner = _BrowserWorkerRunner;
|
|
21
21
|
var _Clipboard = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Clipboard.js"));
|
|
22
22
|
exports.Clipboard = _Clipboard;
|
|
23
|
+
var _Geolocation = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Geolocation.js"));
|
|
24
|
+
exports.Geolocation = _Geolocation;
|
|
23
25
|
function _getRequireWildcardCache(e) {
|
|
24
26
|
if ("function" != typeof WeakMap) return null;
|
|
25
27
|
var r = new WeakMap(),
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Stream from "effect/Stream";
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
* @category type ids
|
|
8
|
+
*/
|
|
9
|
+
export declare const TypeId: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
* @category type ids
|
|
13
|
+
*/
|
|
14
|
+
export type TypeId = typeof TypeId;
|
|
15
|
+
/**
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
* @category models
|
|
18
|
+
*/
|
|
19
|
+
export interface Geolocation {
|
|
20
|
+
readonly [TypeId]: TypeId;
|
|
21
|
+
readonly getCurrentPosition: (options?: PositionOptions | undefined) => Effect.Effect<GeolocationPosition, GeolocationError>;
|
|
22
|
+
readonly watchPosition: (options?: PositionOptions & {
|
|
23
|
+
readonly bufferSize?: number | undefined;
|
|
24
|
+
} | undefined) => Stream.Stream<GeolocationPosition, GeolocationError>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
* @category tags
|
|
29
|
+
*/
|
|
30
|
+
export declare const Geolocation: Context.Tag<Geolocation, Geolocation>;
|
|
31
|
+
/**
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
* @category type ids
|
|
34
|
+
*/
|
|
35
|
+
export declare const ErrorTypeId: unique symbol;
|
|
36
|
+
/**
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
* @category type ids
|
|
39
|
+
*/
|
|
40
|
+
export type ErrorTypeId = typeof ErrorTypeId;
|
|
41
|
+
declare const GeolocationError_base: new <A extends Record<string, any>>(args: import("effect/Types").Simplify<A & {
|
|
42
|
+
readonly error: unknown;
|
|
43
|
+
}>) => import("effect/Cause").YieldableError & Record<typeof ErrorTypeId, typeof ErrorTypeId> & {
|
|
44
|
+
readonly _tag: "GeolocationError";
|
|
45
|
+
readonly error: unknown;
|
|
46
|
+
} & Readonly<A>;
|
|
47
|
+
/**
|
|
48
|
+
* @since 1.0.0
|
|
49
|
+
* @category errors
|
|
50
|
+
*/
|
|
51
|
+
export declare class GeolocationError extends GeolocationError_base<{
|
|
52
|
+
readonly reason: "PositionUnavailable" | "PermissionDenied" | "Timeout";
|
|
53
|
+
}> {
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
* @category layers
|
|
58
|
+
*/
|
|
59
|
+
export declare const layer: Layer.Layer<Geolocation>;
|
|
60
|
+
/**
|
|
61
|
+
* @since 1.0.0
|
|
62
|
+
* @category accessors
|
|
63
|
+
*/
|
|
64
|
+
export declare const watchPosition: (options?: (PositionOptions & {
|
|
65
|
+
readonly bufferSize?: number | undefined;
|
|
66
|
+
}) | undefined) => Stream.Stream<GeolocationPosition, GeolocationError, Geolocation>;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=Geolocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Geolocation.d.ts","sourceRoot":"","sources":["../../src/Geolocation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,gBAAgB,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;IAClB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACzC,IACC,SAAS,KACZ,OAAO,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,CAC0B,CAAA"}
|
package/dist/dts/index.d.ts
CHANGED
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;GAEG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAE3D;;GAEG;AACH,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAA;AAEjE;;GAEG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAA;AAE/D;;GAEG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;GAEG;AACH,OAAO,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAE3D;;GAEG;AACH,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAA;AAEjE;;GAEG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAA;AAE/D;;GAEG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import { RefailError } from "@effect/platform/Error";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Either from "effect/Either";
|
|
8
|
+
import { identity } from "effect/Function";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as Queue from "effect/Queue";
|
|
11
|
+
import * as Stream from "effect/Stream";
|
|
12
|
+
/**
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
* @category type ids
|
|
15
|
+
*/
|
|
16
|
+
export const TypeId = /*#__PURE__*/Symbol.for("@effect/platform-browser/Geolocation");
|
|
17
|
+
/**
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
* @category tags
|
|
20
|
+
*/
|
|
21
|
+
export const Geolocation = /*#__PURE__*/Context.GenericTag("@effect/platform-browser/Geolocation");
|
|
22
|
+
/**
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
* @category type ids
|
|
25
|
+
*/
|
|
26
|
+
export const ErrorTypeId = /*#__PURE__*/Symbol.for("@effect/platform-browser/Geolocation/GeolocationError");
|
|
27
|
+
/**
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
* @category errors
|
|
30
|
+
*/
|
|
31
|
+
export class GeolocationError extends RefailError(ErrorTypeId, "GeolocationError") {}
|
|
32
|
+
const makeQueue = options => Queue.sliding(options?.bufferSize ?? 16).pipe(Effect.tap(queue => Effect.acquireRelease(Effect.sync(() => navigator.geolocation.watchPosition(position => queue.unsafeOffer(Either.right(position)), error => {
|
|
33
|
+
if (error.code === error.PERMISSION_DENIED) {
|
|
34
|
+
queue.unsafeOffer(Either.left(new GeolocationError({
|
|
35
|
+
reason: "PermissionDenied",
|
|
36
|
+
error
|
|
37
|
+
})));
|
|
38
|
+
} else if (error.code === error.TIMEOUT) {
|
|
39
|
+
queue.unsafeOffer(Either.left(new GeolocationError({
|
|
40
|
+
reason: "Timeout",
|
|
41
|
+
error
|
|
42
|
+
})));
|
|
43
|
+
}
|
|
44
|
+
}, options)), handleId => Effect.sync(() => navigator.geolocation.clearWatch(handleId)))));
|
|
45
|
+
/**
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
* @category layers
|
|
48
|
+
*/
|
|
49
|
+
export const layer = /*#__PURE__*/Layer.succeed(Geolocation, /*#__PURE__*/Geolocation.of({
|
|
50
|
+
[TypeId]: TypeId,
|
|
51
|
+
getCurrentPosition: options => makeQueue(options).pipe(Effect.flatMap(Queue.take), Effect.flatten, Effect.scoped),
|
|
52
|
+
watchPosition: options => makeQueue(options).pipe(Effect.map(Stream.fromQueue), Stream.unwrapScoped, Stream.mapEffect(identity))
|
|
53
|
+
}));
|
|
54
|
+
/**
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
* @category accessors
|
|
57
|
+
*/
|
|
58
|
+
export const watchPosition = options => Stream.unwrap(Effect.map(Geolocation, geolocation => geolocation.watchPosition(options)));
|
|
59
|
+
//# sourceMappingURL=Geolocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Geolocation.js","names":["RefailError","Context","Effect","Either","identity","Layer","Queue","Stream","TypeId","Symbol","for","Geolocation","GenericTag","ErrorTypeId","GeolocationError","makeQueue","options","sliding","bufferSize","pipe","tap","queue","acquireRelease","sync","navigator","geolocation","watchPosition","position","unsafeOffer","right","error","code","PERMISSION_DENIED","left","reason","TIMEOUT","handleId","clearWatch","layer","succeed","of","getCurrentPosition","flatMap","take","flatten","scoped","map","fromQueue","unwrapScoped","mapEffect","unwrap"],"sources":["../../src/Geolocation.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,SAASA,WAAW,QA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I,KAAKD,KAAK,CAACK,OAAO,EAAE;IACvCd,KAAK,CAACO,WAAW,CAACzB,MAAM,CAAC8B,IAAI,CAAC,IAAInB,gBAAgB,CAAC;MAAEoB,MAAM,EAAE,SAAS;MAAEJ;IAAK,CAAE,CAAC,CAAC,CAAC;EACpF;AACF,CAAC,EACDd,OAAO,CACR,CACF,EACAoB,QAAQ,IAAKlC,MAAM,CAACqB,IAAI,CAAC,MAAMC,SAAS,CAACC,WAAW,CAACY,UAAU,CAACD,QAAQ,CAAC,CAAC,CAC5E,CACF,CACF;AAEH;;;;AAIA,OAAO,MAAME,KAAK,gBAA6BjC,KAAK,CAACkC,OAAO,CAC1D5B,WAAW,eACXA,WAAW,CAAC6B,EAAE,CAAC;EACb,CAAChC,MAAM,GAAGA,MAAM;EAChBiC,kBAAkB,EAAGzB,OAAO,IAC1BD,SAAS,CAACC,OAAO,CAAC,CAACG,IAAI,CACrBjB,MAAM,CAACwC,OAAO,CAACpC,KAAK,CAACqC,IAAI,CAAC,EAC1BzC,MAAM,CAAC0C,OAAO,EACd1C,MAAM,CAAC2C,MAAM,CACd;EACHnB,aAAa,EAAGV,OAAO,IACrBD,SAAS,CAACC,OAAO,CAAC,CAACG,IAAI,CACrBjB,MAAM,CAAC4C,GAAG,CAACvC,MAAM,CAACwC,SAAS,CAAC,EAC5BxC,MAAM,CAACyC,YAAY,EACnBzC,MAAM,CAAC0C,SAAS,CAAC7C,QAAQ,CAAC;CAE/B,CAAC,CACH;AAED;;;;AAIA,OAAO,MAAMsB,aAAa,GACxBV,OAIa,IAEbT,MAAM,CAAC2C,MAAM,CAAChD,MAAM,CAAC4C,GAAG,CAACnC,WAAW,EAAGc,WAAW,IAAKA,WAAW,CAACC,aAAa,CAACV,OAAO,CAAC,CAAC,CAAC","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["BrowerSocket","BrowserHttpClient","BrowserKeyValueStore","BrowserRuntime","BrowserStream","BrowserWorker","BrowserWorkerRunner","Clipboard"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,YAAY,MAAM,mBAAmB;AAEjD;;;AAGA,OAAO,KAAKC,iBAAiB,MAAM,wBAAwB;AAE3D;;;AAGA,OAAO,KAAKC,oBAAoB,MAAM,2BAA2B;AAEjE;;;AAGA,OAAO,KAAKC,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,mBAAmB,MAAM,0BAA0B;AAE/D;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["BrowerSocket","BrowserHttpClient","BrowserKeyValueStore","BrowserRuntime","BrowserStream","BrowserWorker","BrowserWorkerRunner","Clipboard","Geolocation"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,YAAY,MAAM,mBAAmB;AAEjD;;;AAGA,OAAO,KAAKC,iBAAiB,MAAM,wBAAwB;AAE3D;;;AAGA,OAAO,KAAKC,oBAAoB,MAAM,2BAA2B;AAEjE;;;AAGA,OAAO,KAAKC,cAAc,MAAM,qBAAqB;AAErD;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB;AAEnD;;;AAGA,OAAO,KAAKC,mBAAmB,MAAM,0BAA0B;AAE/D;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAKC,WAAW,MAAM,kBAAkB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/platform-browser",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.22",
|
|
4
4
|
"description": "Platform specific implementations for the browser",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"multipasta": "^0.2.1"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@effect/platform": "^0.53.
|
|
17
|
-
"effect": "^3.1.
|
|
16
|
+
"@effect/platform": "^0.53.7",
|
|
17
|
+
"effect": "^3.1.5"
|
|
18
18
|
},
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"provenance": true
|
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
"types": "./dist/dts/Clipboard.d.ts",
|
|
69
69
|
"import": "./dist/esm/Clipboard.js",
|
|
70
70
|
"default": "./dist/cjs/Clipboard.js"
|
|
71
|
+
},
|
|
72
|
+
"./Geolocation": {
|
|
73
|
+
"types": "./dist/dts/Geolocation.d.ts",
|
|
74
|
+
"import": "./dist/esm/Geolocation.js",
|
|
75
|
+
"default": "./dist/cjs/Geolocation.js"
|
|
71
76
|
}
|
|
72
77
|
},
|
|
73
78
|
"typesVersions": {
|
|
@@ -95,6 +100,9 @@
|
|
|
95
100
|
],
|
|
96
101
|
"Clipboard": [
|
|
97
102
|
"./dist/dts/Clipboard.d.ts"
|
|
103
|
+
],
|
|
104
|
+
"Geolocation": [
|
|
105
|
+
"./dist/dts/Geolocation.d.ts"
|
|
98
106
|
]
|
|
99
107
|
}
|
|
100
108
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import { RefailError } from "@effect/platform/Error"
|
|
5
|
+
import * as Context from "effect/Context"
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as Either from "effect/Either"
|
|
8
|
+
import { identity } from "effect/Function"
|
|
9
|
+
import * as Layer from "effect/Layer"
|
|
10
|
+
import * as Queue from "effect/Queue"
|
|
11
|
+
import * as Stream from "effect/Stream"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
* @category type ids
|
|
16
|
+
*/
|
|
17
|
+
export const TypeId: unique symbol = Symbol.for("@effect/platform-browser/Geolocation")
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
* @category type ids
|
|
22
|
+
*/
|
|
23
|
+
export type TypeId = typeof TypeId
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
* @category models
|
|
28
|
+
*/
|
|
29
|
+
export interface Geolocation {
|
|
30
|
+
readonly [TypeId]: TypeId
|
|
31
|
+
readonly getCurrentPosition: (
|
|
32
|
+
options?: PositionOptions | undefined
|
|
33
|
+
) => Effect.Effect<GeolocationPosition, GeolocationError>
|
|
34
|
+
readonly watchPosition: (
|
|
35
|
+
options?:
|
|
36
|
+
| PositionOptions & {
|
|
37
|
+
readonly bufferSize?: number | undefined
|
|
38
|
+
}
|
|
39
|
+
| undefined
|
|
40
|
+
) => Stream.Stream<GeolocationPosition, GeolocationError>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
* @category tags
|
|
46
|
+
*/
|
|
47
|
+
export const Geolocation: Context.Tag<Geolocation, Geolocation> = Context.GenericTag<Geolocation>(
|
|
48
|
+
"@effect/platform-browser/Geolocation"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
* @category type ids
|
|
54
|
+
*/
|
|
55
|
+
export const ErrorTypeId: unique symbol = Symbol.for("@effect/platform-browser/Geolocation/GeolocationError")
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @since 1.0.0
|
|
59
|
+
* @category type ids
|
|
60
|
+
*/
|
|
61
|
+
export type ErrorTypeId = typeof ErrorTypeId
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @since 1.0.0
|
|
65
|
+
* @category errors
|
|
66
|
+
*/
|
|
67
|
+
export class GeolocationError extends RefailError(ErrorTypeId, "GeolocationError")<{
|
|
68
|
+
readonly reason: "PositionUnavailable" | "PermissionDenied" | "Timeout"
|
|
69
|
+
}> {}
|
|
70
|
+
|
|
71
|
+
const makeQueue = (
|
|
72
|
+
options:
|
|
73
|
+
| PositionOptions & {
|
|
74
|
+
readonly bufferSize?: number | undefined
|
|
75
|
+
}
|
|
76
|
+
| undefined
|
|
77
|
+
) =>
|
|
78
|
+
Queue.sliding<Either.Either<GeolocationPosition, GeolocationError>>(options?.bufferSize ?? 16).pipe(
|
|
79
|
+
Effect.tap((queue) =>
|
|
80
|
+
Effect.acquireRelease(
|
|
81
|
+
Effect.sync(() =>
|
|
82
|
+
navigator.geolocation.watchPosition(
|
|
83
|
+
(position) => queue.unsafeOffer(Either.right(position)),
|
|
84
|
+
(error) => {
|
|
85
|
+
if (error.code === error.PERMISSION_DENIED) {
|
|
86
|
+
queue.unsafeOffer(Either.left(new GeolocationError({ reason: "PermissionDenied", error })))
|
|
87
|
+
} else if (error.code === error.TIMEOUT) {
|
|
88
|
+
queue.unsafeOffer(Either.left(new GeolocationError({ reason: "Timeout", error })))
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
options
|
|
92
|
+
)
|
|
93
|
+
),
|
|
94
|
+
(handleId) => Effect.sync(() => navigator.geolocation.clearWatch(handleId))
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @since 1.0.0
|
|
101
|
+
* @category layers
|
|
102
|
+
*/
|
|
103
|
+
export const layer: Layer.Layer<Geolocation> = Layer.succeed(
|
|
104
|
+
Geolocation,
|
|
105
|
+
Geolocation.of({
|
|
106
|
+
[TypeId]: TypeId,
|
|
107
|
+
getCurrentPosition: (options) =>
|
|
108
|
+
makeQueue(options).pipe(
|
|
109
|
+
Effect.flatMap(Queue.take),
|
|
110
|
+
Effect.flatten,
|
|
111
|
+
Effect.scoped
|
|
112
|
+
),
|
|
113
|
+
watchPosition: (options) =>
|
|
114
|
+
makeQueue(options).pipe(
|
|
115
|
+
Effect.map(Stream.fromQueue),
|
|
116
|
+
Stream.unwrapScoped,
|
|
117
|
+
Stream.mapEffect(identity)
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @since 1.0.0
|
|
124
|
+
* @category accessors
|
|
125
|
+
*/
|
|
126
|
+
export const watchPosition = (
|
|
127
|
+
options?:
|
|
128
|
+
| PositionOptions & {
|
|
129
|
+
readonly bufferSize?: number | undefined
|
|
130
|
+
}
|
|
131
|
+
| undefined
|
|
132
|
+
): Stream.Stream<GeolocationPosition, GeolocationError, Geolocation> =>
|
|
133
|
+
Stream.unwrap(Effect.map(Geolocation, (geolocation) => geolocation.watchPosition(options)))
|