@effect/platform-browser 0.1.0

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 (63) hide show
  1. package/Effectify.d.ts +19 -0
  2. package/Effectify.d.ts.map +1 -0
  3. package/Effectify.js +13 -0
  4. package/Effectify.js.map +1 -0
  5. package/Error.d.ts +30 -0
  6. package/Error.d.ts.map +1 -0
  7. package/Error.js +25 -0
  8. package/Error.js.map +1 -0
  9. package/HttpClient.d.ts +61 -0
  10. package/HttpClient.d.ts.map +1 -0
  11. package/HttpClient.js +23 -0
  12. package/HttpClient.js.map +1 -0
  13. package/KeyValueStore.d.ts +16 -0
  14. package/KeyValueStore.d.ts.map +1 -0
  15. package/KeyValueStore.js +48 -0
  16. package/KeyValueStore.js.map +1 -0
  17. package/LICENSE +21 -0
  18. package/Path.d.ts +7 -0
  19. package/Path.d.ts.map +1 -0
  20. package/Path.js +17 -0
  21. package/Path.js.map +1 -0
  22. package/README.md +3 -0
  23. package/Runtime.d.ts +10 -0
  24. package/Runtime.d.ts.map +1 -0
  25. package/Runtime.js +16 -0
  26. package/Runtime.js.map +1 -0
  27. package/internal/keyValueStore.d.ts +2 -0
  28. package/internal/keyValueStore.d.ts.map +1 -0
  29. package/internal/keyValueStore.js +107 -0
  30. package/internal/keyValueStore.js.map +1 -0
  31. package/internal/runtime.d.ts +2 -0
  32. package/internal/runtime.d.ts.map +1 -0
  33. package/internal/runtime.js +23 -0
  34. package/internal/runtime.js.map +1 -0
  35. package/mjs/Effectify.mjs +10 -0
  36. package/mjs/Effectify.mjs.map +1 -0
  37. package/mjs/Error.mjs +20 -0
  38. package/mjs/Error.mjs.map +1 -0
  39. package/mjs/HttpClient.mjs +61 -0
  40. package/mjs/HttpClient.mjs.map +1 -0
  41. package/mjs/KeyValueStore.mjs +22 -0
  42. package/mjs/KeyValueStore.mjs.map +1 -0
  43. package/mjs/Path.mjs +7 -0
  44. package/mjs/Path.mjs.map +1 -0
  45. package/mjs/Runtime.mjs +7 -0
  46. package/mjs/Runtime.mjs.map +1 -0
  47. package/mjs/internal/keyValueStore.mjs +97 -0
  48. package/mjs/internal/keyValueStore.mjs.map +1 -0
  49. package/mjs/internal/runtime.mjs +14 -0
  50. package/mjs/internal/runtime.mjs.map +1 -0
  51. package/package.json +32 -0
  52. package/src/Effectify.ts +22 -0
  53. package/src/Error.ts +31 -0
  54. package/src/HttpClient.ts +62 -0
  55. package/src/KeyValueStore.ts +24 -0
  56. package/src/Path.ts +7 -0
  57. package/src/Runtime.ts +11 -0
  58. package/src/internal/keyValueStore.ts +130 -0
  59. package/src/internal/runtime.ts +24 -0
  60. package/tsconfig.build.json +11 -0
  61. package/tsconfig.examples.json +12 -0
  62. package/tsconfig.json +11 -0
  63. package/tsconfig.test.json +17 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as body from "@effect/platform/Http/Body";
5
+ import * as client from "@effect/platform/Http/Client";
6
+ import * as error from "@effect/platform/Http/ClientError";
7
+ import * as request from "@effect/platform/Http/ClientRequest";
8
+ import * as response from "@effect/platform/Http/ClientResponse";
9
+ import * as headers from "@effect/platform/Http/Headers";
10
+ import * as urlParams from "@effect/platform/Http/UrlParams";
11
+ export {
12
+ /**
13
+ * @since 1.0.0
14
+ *
15
+ * - Docs: [Http/Body](https://effect-ts.github.io/platform/platform/Http/Body.ts.html)
16
+ * - Module: `@effect/platform/Http/Body`
17
+ */
18
+ body,
19
+ /**
20
+ * @since 1.0.0
21
+ *
22
+ * - Docs: [Http/Client](https://effect-ts.github.io/platform/platform/Http/Client.ts.html)
23
+ * - Module: `@effect/platform/Http/Client`
24
+ */
25
+ client,
26
+ /**
27
+ * @since 1.0.0
28
+ *
29
+ * - Docs: [Http/ClientError](https://effect-ts.github.io/platform/platform/Http/ClientError.ts.html)
30
+ * - Module: `@effect/platform/Http/ClientError`
31
+ */
32
+ error,
33
+ /**
34
+ * @since 1.0.0
35
+ *
36
+ * - Docs: [Http/Headers](https://effect-ts.github.io/platform/platform/Http/Headers.ts.html)
37
+ * - Module: `@effect/platform/Http/Headers`
38
+ */
39
+ headers,
40
+ /**
41
+ * @since 1.0.0
42
+ *
43
+ * - Docs: [Http/ClientRequest](https://effect-ts.github.io/platform/platform/Http/ClientRequest.ts.html)
44
+ * - Module: `@effect/platform/Http/ClientRequest`
45
+ */
46
+ request,
47
+ /**
48
+ * @since 1.0.0
49
+ *
50
+ * - Docs: [Http/ClientResponse](https://effect-ts.github.io/platform/platform/Http/ClientResponse.ts.html)
51
+ * - Module: `@effect/platform/Http/ClientResponse`
52
+ */
53
+ response,
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * - Docs: [Http/UrlParams](https://effect-ts.github.io/platform/platform/Http/UrlParams.ts.html)
58
+ * - Module: `@effect/platform/Http/UrlParams`
59
+ */
60
+ urlParams };
61
+ //# sourceMappingURL=HttpClient.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClient.mjs","names":["body","client","error","request","response","headers","urlParams"],"sources":["../src/HttpClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,4BAA4B;AAClD,OAAO,KAAKC,MAAM,MAAM,8BAA8B;AACtD,OAAO,KAAKC,KAAK,MAAM,mCAAmC;AAC1D,OAAO,KAAKC,OAAO,MAAM,qCAAqC;AAC9D,OAAO,KAAKC,QAAQ,MAAM,sCAAsC;AAChE,OAAO,KAAKC,OAAO,MAAM,+BAA+B;AACxD,OAAO,KAAKC,SAAS,MAAM,iCAAiC;AAE5D;AACE;;;;;;AAMAN,IAAI;AACJ;;;;;;AAMAC,MAAM;AACN;;;;;;AAMAC,KAAK;AACL;;;;;;AAMAG,OAAO;AACP;;;;;;AAMAF,OAAO;AACP;;;;;;AAMAC,QAAQ;AACR;;;;;;AAMAE,SAAS"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @since 1.0.0
3
+ *
4
+ * Also includes exports from [`@effect/platform/KeyValueStore`](https://effect-ts.github.io/platform/platform/KeyValueStore.ts.html).
5
+ */
6
+ import * as internal from "@effect/platform-browser/internal/keyValueStore";
7
+ export * from "@effect/platform/KeyValueStore";
8
+ /**
9
+ * Creates a KeyValueStore layer that uses the browser's localStorage api. Values are stored between sessions.
10
+ *
11
+ * @since 1.0.0
12
+ * @category models
13
+ */
14
+ export const layerLocalStorage = internal.layerLocalStorage;
15
+ /**
16
+ * Creates a KeyValueStore layer that uses the browser's sessionStorage api. Values are stored only for the current session.
17
+ *
18
+ * @since 1.0.0
19
+ * @category models
20
+ */
21
+ export const layerSessionStorage = internal.layerSessionStorage;
22
+ //# sourceMappingURL=KeyValueStore.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueStore.mjs","names":["internal","layerLocalStorage","layerSessionStorage"],"sources":["../src/KeyValueStore.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAKA,QAAQ,MAAM,iDAAiD;AAE3E,cAAc,gCAAgC;AAE9C;;;;;;AAMA,OAAO,MAAMC,iBAAiB,GAAGD,QAAQ,CAACC,iBAAiB;AAE3D;;;;;;AAMA,OAAO,MAAMC,mBAAmB,GAAGF,QAAQ,CAACE,mBAAmB"}
package/mjs/Path.mjs ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @since 1.0.0
3
+ *
4
+ * Also includes exports from [`@effect/platform/Path`](https://effect-ts.github.io/platform/platform/Path.ts.html).
5
+ */
6
+ export * from "@effect/platform/Path";
7
+ //# sourceMappingURL=Path.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Path.mjs","names":[],"sources":["../src/Path.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAMA,cAAc,uBAAuB"}
@@ -0,0 +1,7 @@
1
+ import * as internal from "@effect/platform-browser/internal/runtime";
2
+ /**
3
+ * @since 1.0.0
4
+ * @category runtime
5
+ */
6
+ export const runMain = internal.runMain;
7
+ //# sourceMappingURL=Runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Runtime.mjs","names":["internal","runMain"],"sources":["../src/Runtime.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,QAAQ,MAAM,2CAA2C;AAErE;;;;AAIA,OAAO,MAAMC,OAAO,GAAuDD,QAAQ,CAACC,OAAO"}
@@ -0,0 +1,97 @@
1
+ import * as Option from "@effect/data/Option";
2
+ import * as Effect from "@effect/io/Effect";
3
+ import * as Layer from "@effect/io/Layer";
4
+ import * as PlatformError from "@effect/platform/Error";
5
+ import * as KeyValueStore from "@effect/platform/KeyValueStore";
6
+ const storageError = props => PlatformError.SystemError({
7
+ reason: "PermissionDenied",
8
+ module: "KeyValueStore",
9
+ ...props
10
+ });
11
+ /** @internal */
12
+ export const layerLocalStorage = /*#__PURE__*/Layer.succeed(KeyValueStore.KeyValueStore, /*#__PURE__*/KeyValueStore.make({
13
+ get: key => Effect.try({
14
+ try: () => Option.fromNullable(localStorage.getItem(key)),
15
+ catch: () => storageError({
16
+ pathOrDescriptor: "layerLocalStorage",
17
+ method: "get",
18
+ message: `Unable to get item with key ${key}`
19
+ })
20
+ }),
21
+ set: (key, value) => Effect.try({
22
+ try: () => localStorage.setItem(key, value),
23
+ catch: () => storageError({
24
+ pathOrDescriptor: "layerLocalStorage",
25
+ method: "set",
26
+ message: `Unable to set item with key ${key}`
27
+ })
28
+ }),
29
+ remove: key => Effect.try({
30
+ try: () => localStorage.removeItem(key),
31
+ catch: () => storageError({
32
+ pathOrDescriptor: "layerLocalStorage",
33
+ method: "remove",
34
+ message: `Unable to remove item with key ${key}`
35
+ })
36
+ }),
37
+ clear: /*#__PURE__*/Effect.try({
38
+ try: () => localStorage.clear(),
39
+ catch: () => storageError({
40
+ pathOrDescriptor: "layerLocalStorage",
41
+ method: "clear",
42
+ message: `Unable to clear storage`
43
+ })
44
+ }),
45
+ size: /*#__PURE__*/Effect.try({
46
+ try: () => localStorage.length,
47
+ catch: () => storageError({
48
+ pathOrDescriptor: "layerLocalStorage",
49
+ method: "size",
50
+ message: `Unable to get size`
51
+ })
52
+ })
53
+ }));
54
+ /** @internal */
55
+ export const layerSessionStorage = /*#__PURE__*/Layer.succeed(KeyValueStore.KeyValueStore, /*#__PURE__*/KeyValueStore.make({
56
+ get: key => Effect.try({
57
+ try: () => Option.fromNullable(sessionStorage.getItem(key)),
58
+ catch: () => storageError({
59
+ pathOrDescriptor: "layerSessionStorage",
60
+ method: "get",
61
+ message: `Unable to get item with key ${key}`
62
+ })
63
+ }),
64
+ set: (key, value) => Effect.try({
65
+ try: () => sessionStorage.setItem(key, value),
66
+ catch: () => storageError({
67
+ pathOrDescriptor: "layerSessionStorage",
68
+ method: "set",
69
+ message: `Unable to set item with key ${key}`
70
+ })
71
+ }),
72
+ remove: key => Effect.try({
73
+ try: () => sessionStorage.removeItem(key),
74
+ catch: () => storageError({
75
+ pathOrDescriptor: "layerSessionStorage",
76
+ method: "remove",
77
+ message: `Unable to remove item with key ${key}`
78
+ })
79
+ }),
80
+ clear: /*#__PURE__*/Effect.try({
81
+ try: () => sessionStorage.clear(),
82
+ catch: () => storageError({
83
+ pathOrDescriptor: "layerSessionStorage",
84
+ method: "clear",
85
+ message: `Unable to clear storage`
86
+ })
87
+ }),
88
+ size: /*#__PURE__*/Effect.try({
89
+ try: () => sessionStorage.length,
90
+ catch: () => storageError({
91
+ pathOrDescriptor: "layerSessionStorage",
92
+ method: "size",
93
+ message: `Unable to get size`
94
+ })
95
+ })
96
+ }));
97
+ //# sourceMappingURL=keyValueStore.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyValueStore.mjs","names":["Option","Effect","Layer","PlatformError","KeyValueStore","storageError","props","SystemError","reason","module","layerLocalStorage","succeed","make","get","key","try","fromNullable","localStorage","getItem","catch","pathOrDescriptor","method","message","set","value","setItem","remove","removeItem","clear","size","length","layerSessionStorage","sessionStorage"],"sources":["../../src/internal/keyValueStore.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAA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CAAC;MACXe,gBAAgB,EAAE,qBAAqB;MACvCC,MAAM,EAAE,KAAK;MACbC,OAAO,EAAE,+BAA+BR,GAAG;KAC5C;GACJ,CAAC;EAEJY,MAAM,EAAGZ,GAAW,IAClBb,MAAM,CAACc,GAAG,CAAC;IACTA,GAAG,EAAEA,CAAA,KAAMiB,cAAc,CAACL,UAAU,CAACb,GAAG,CAAC;IACzCK,KAAK,EAAEA,CAAA,KACLd,YAAY,CAAC;MACXe,gBAAgB,EAAE,qBAAqB;MACvCC,MAAM,EAAE,QAAQ;MAChBC,OAAO,EAAE,kCAAkCR,GAAG;KAC/C;GACJ,CAAC;EAEJc,KAAK,eAAE3B,MAAM,CAACc,GAAG,CAAC;IAChBA,GAAG,EAAEA,CAAA,KAAMiB,cAAc,CAACJ,KAAK,EAAE;IACjCT,KAAK,EAAEA,CAAA,KACLd,YAAY,CAAC;MACXe,gBAAgB,EAAE,qBAAqB;MACvCC,MAAM,EAAE,OAAO;MACfC,OAAO,EAAE;KACV;GACJ,CAAC;EAEFO,IAAI,eAAE5B,MAAM,CAACc,GAAG,CAAC;IACfA,GAAG,EAAEA,CAAA,KAAMiB,cAAc,CAACF,MAAM;IAChCX,KAAK,EAAEA,CAAA,KACLd,YAAY,CAAC;MACXe,gBAAgB,EAAE,qBAAqB;MACvCC,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE;KACV;GACJ;CACF,CAAC,CACH"}
@@ -0,0 +1,14 @@
1
+ import * as Effect from "@effect/io/Effect";
2
+ import * as Fiber from "@effect/io/Fiber";
3
+ /** @internal */
4
+ export const runMain = effect => {
5
+ const fiber = Effect.runFork(effect);
6
+ fiber.unsafeAddObserver(() => {
7
+ Effect.runFork(interruptAll(fiber.id()));
8
+ });
9
+ addEventListener("beforeunload", () => {
10
+ Effect.runFork(fiber.interruptAsFork(fiber.id()));
11
+ });
12
+ };
13
+ const interruptAll = id => Effect.flatMap(Fiber.roots, roots => Fiber.interruptAllAs(roots, id));
14
+ //# sourceMappingURL=runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.mjs","names":["Effect","Fiber","runMain","effect","fiber","runFork","unsafeAddObserver","interruptAll","id","addEventListener","interruptAsFork","flatMap","roots","interruptAllAs"],"sources":["../../src/internal/runtime.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,MAAM,MAAM,mBAAmB;AAC3C,OAAO,KAAKC,KAAK,MAAM,kBAAkB;AAGzC;AACA,OAAO,MAAMC,OAAO,GAClBC,MAAkC,IAChC;EACF,MAAMC,KAAK,GAAGJ,MAAM,CAACK,OAAO,CAACF,MAAM,CAAC;EAEpCC,KAAK,CAACE,iBAAiB,CAAC,MAAK;IAC3BN,MAAM,CAACK,OAAO,CAACE,YAAY,CAACH,KAAK,CAACI,EAAE,EAAE,CAAC,CAAC;EAC1C,CAAC,CAAC;EAEFC,gBAAgB,CAAC,cAAc,EAAE,MAAK;IACpCT,MAAM,CAACK,OAAO,CAACD,KAAK,CAACM,eAAe,CAACN,KAAK,CAACI,EAAE,EAAE,CAAC,CAAC;EACnD,CAAC,CAAC;AACJ,CAAC;AAED,MAAMD,YAAY,GAAIC,EAAmB,IACvCR,MAAM,CAACW,OAAO,CACZV,KAAK,CAACW,KAAK,EACVA,KAAK,IAAKX,KAAK,CAACY,cAAc,CAACD,KAAK,EAAEJ,EAAE,CAAC,CAC3C"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@effect/platform-browser",
3
+ "version": "0.1.0",
4
+ "description": "Unified interfaces for common platform-specific services",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/effect-ts/platform.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "exports": {
14
+ "./*": {
15
+ "import": {
16
+ "types": "./*.d.ts",
17
+ "default": "./mjs/*.mjs"
18
+ },
19
+ "require": {
20
+ "types": "./*.d.ts",
21
+ "default": "./*.js"
22
+ }
23
+ }
24
+ },
25
+ "sideEffects": [],
26
+ "author": "Effect contributors",
27
+ "peerDependencies": {
28
+ "@effect/data": "^0.17.5",
29
+ "@effect/io": "^0.38.2",
30
+ "@effect/platform": "^0.13.14"
31
+ }
32
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ export type {
6
+ /**
7
+ * @since 1.0.0
8
+ */
9
+ Effectify,
10
+ /**
11
+ * @since 1.0.0
12
+ */
13
+ EffectifyError
14
+ } from "@effect/platform/Effectify"
15
+
16
+ export {
17
+ /**
18
+ * @since 1.0.0
19
+ * @category constructor
20
+ */
21
+ effectify
22
+ } from "@effect/platform/Effectify"
package/src/Error.ts ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+
5
+ export {
6
+ /**
7
+ * @since 1.0.0
8
+ * @category error
9
+ */
10
+ BadArgument,
11
+ /**
12
+ * @since 1.0.0
13
+ * @category error
14
+ */
15
+ PlatformError,
16
+ /**
17
+ * @since 1.0.0
18
+ * @category type id
19
+ */
20
+ PlatformErrorTypeId,
21
+ /**
22
+ * @since 1.0.0
23
+ * @category error
24
+ */
25
+ SystemError,
26
+ /**
27
+ * @since 1.0.0
28
+ * @category model
29
+ */
30
+ SystemErrorReason
31
+ } from "@effect/platform/Error"
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as body from "@effect/platform/Http/Body"
5
+ import * as client from "@effect/platform/Http/Client"
6
+ import * as error from "@effect/platform/Http/ClientError"
7
+ import * as request from "@effect/platform/Http/ClientRequest"
8
+ import * as response from "@effect/platform/Http/ClientResponse"
9
+ import * as headers from "@effect/platform/Http/Headers"
10
+ import * as urlParams from "@effect/platform/Http/UrlParams"
11
+
12
+ export {
13
+ /**
14
+ * @since 1.0.0
15
+ *
16
+ * - Docs: [Http/Body](https://effect-ts.github.io/platform/platform/Http/Body.ts.html)
17
+ * - Module: `@effect/platform/Http/Body`
18
+ */
19
+ body,
20
+ /**
21
+ * @since 1.0.0
22
+ *
23
+ * - Docs: [Http/Client](https://effect-ts.github.io/platform/platform/Http/Client.ts.html)
24
+ * - Module: `@effect/platform/Http/Client`
25
+ */
26
+ client,
27
+ /**
28
+ * @since 1.0.0
29
+ *
30
+ * - Docs: [Http/ClientError](https://effect-ts.github.io/platform/platform/Http/ClientError.ts.html)
31
+ * - Module: `@effect/platform/Http/ClientError`
32
+ */
33
+ error,
34
+ /**
35
+ * @since 1.0.0
36
+ *
37
+ * - Docs: [Http/Headers](https://effect-ts.github.io/platform/platform/Http/Headers.ts.html)
38
+ * - Module: `@effect/platform/Http/Headers`
39
+ */
40
+ headers,
41
+ /**
42
+ * @since 1.0.0
43
+ *
44
+ * - Docs: [Http/ClientRequest](https://effect-ts.github.io/platform/platform/Http/ClientRequest.ts.html)
45
+ * - Module: `@effect/platform/Http/ClientRequest`
46
+ */
47
+ request,
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * - Docs: [Http/ClientResponse](https://effect-ts.github.io/platform/platform/Http/ClientResponse.ts.html)
52
+ * - Module: `@effect/platform/Http/ClientResponse`
53
+ */
54
+ response,
55
+ /**
56
+ * @since 1.0.0
57
+ *
58
+ * - Docs: [Http/UrlParams](https://effect-ts.github.io/platform/platform/Http/UrlParams.ts.html)
59
+ * - Module: `@effect/platform/Http/UrlParams`
60
+ */
61
+ urlParams
62
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @since 1.0.0
3
+ *
4
+ * Also includes exports from [`@effect/platform/KeyValueStore`](https://effect-ts.github.io/platform/platform/KeyValueStore.ts.html).
5
+ */
6
+ import * as internal from "@effect/platform-browser/internal/keyValueStore"
7
+
8
+ export * from "@effect/platform/KeyValueStore"
9
+
10
+ /**
11
+ * Creates a KeyValueStore layer that uses the browser's localStorage api. Values are stored between sessions.
12
+ *
13
+ * @since 1.0.0
14
+ * @category models
15
+ */
16
+ export const layerLocalStorage = internal.layerLocalStorage
17
+
18
+ /**
19
+ * Creates a KeyValueStore layer that uses the browser's sessionStorage api. Values are stored only for the current session.
20
+ *
21
+ * @since 1.0.0
22
+ * @category models
23
+ */
24
+ export const layerSessionStorage = internal.layerSessionStorage
package/src/Path.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @since 1.0.0
3
+ *
4
+ * Also includes exports from [`@effect/platform/Path`](https://effect-ts.github.io/platform/platform/Path.ts.html).
5
+ */
6
+
7
+ export * from "@effect/platform/Path"
package/src/Runtime.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type * as Effect from "@effect/io/Effect"
5
+ import * as internal from "@effect/platform-browser/internal/runtime"
6
+
7
+ /**
8
+ * @since 1.0.0
9
+ * @category runtime
10
+ */
11
+ export const runMain: <E, A>(effect: Effect.Effect<never, E, A>) => void = internal.runMain
@@ -0,0 +1,130 @@
1
+ import * as Option from "@effect/data/Option"
2
+ import * as Effect from "@effect/io/Effect"
3
+ import * as Layer from "@effect/io/Layer"
4
+ import * as PlatformError from "@effect/platform/Error"
5
+ import * as KeyValueStore from "@effect/platform/KeyValueStore"
6
+
7
+ const storageError = (props: Omit<Parameters<typeof PlatformError.SystemError>[0], "reason" | "module">) =>
8
+ PlatformError.SystemError({
9
+ reason: "PermissionDenied",
10
+ module: "KeyValueStore",
11
+ ...props
12
+ })
13
+
14
+ /** @internal */
15
+ export const layerLocalStorage = Layer.succeed(
16
+ KeyValueStore.KeyValueStore,
17
+ KeyValueStore.make({
18
+ get: (key: string) =>
19
+ Effect.try({
20
+ try: () => Option.fromNullable(localStorage.getItem(key)),
21
+ catch: () =>
22
+ storageError({
23
+ pathOrDescriptor: "layerLocalStorage",
24
+ method: "get",
25
+ message: `Unable to get item with key ${key}`
26
+ })
27
+ }),
28
+
29
+ set: (key: string, value: string) =>
30
+ Effect.try({
31
+ try: () => localStorage.setItem(key, value),
32
+ catch: () =>
33
+ storageError({
34
+ pathOrDescriptor: "layerLocalStorage",
35
+ method: "set",
36
+ message: `Unable to set item with key ${key}`
37
+ })
38
+ }),
39
+
40
+ remove: (key: string) =>
41
+ Effect.try({
42
+ try: () => localStorage.removeItem(key),
43
+ catch: () =>
44
+ storageError({
45
+ pathOrDescriptor: "layerLocalStorage",
46
+ method: "remove",
47
+ message: `Unable to remove item with key ${key}`
48
+ })
49
+ }),
50
+
51
+ clear: Effect.try({
52
+ try: () => localStorage.clear(),
53
+ catch: () =>
54
+ storageError({
55
+ pathOrDescriptor: "layerLocalStorage",
56
+ method: "clear",
57
+ message: `Unable to clear storage`
58
+ })
59
+ }),
60
+
61
+ size: Effect.try({
62
+ try: () => localStorage.length,
63
+ catch: () =>
64
+ storageError({
65
+ pathOrDescriptor: "layerLocalStorage",
66
+ method: "size",
67
+ message: `Unable to get size`
68
+ })
69
+ })
70
+ })
71
+ )
72
+
73
+ /** @internal */
74
+ export const layerSessionStorage = Layer.succeed(
75
+ KeyValueStore.KeyValueStore,
76
+ KeyValueStore.make({
77
+ get: (key: string) =>
78
+ Effect.try({
79
+ try: () => Option.fromNullable(sessionStorage.getItem(key)),
80
+ catch: () =>
81
+ storageError({
82
+ pathOrDescriptor: "layerSessionStorage",
83
+ method: "get",
84
+ message: `Unable to get item with key ${key}`
85
+ })
86
+ }),
87
+
88
+ set: (key: string, value: string) =>
89
+ Effect.try({
90
+ try: () => sessionStorage.setItem(key, value),
91
+ catch: () =>
92
+ storageError({
93
+ pathOrDescriptor: "layerSessionStorage",
94
+ method: "set",
95
+ message: `Unable to set item with key ${key}`
96
+ })
97
+ }),
98
+
99
+ remove: (key: string) =>
100
+ Effect.try({
101
+ try: () => sessionStorage.removeItem(key),
102
+ catch: () =>
103
+ storageError({
104
+ pathOrDescriptor: "layerSessionStorage",
105
+ method: "remove",
106
+ message: `Unable to remove item with key ${key}`
107
+ })
108
+ }),
109
+
110
+ clear: Effect.try({
111
+ try: () => sessionStorage.clear(),
112
+ catch: () =>
113
+ storageError({
114
+ pathOrDescriptor: "layerSessionStorage",
115
+ method: "clear",
116
+ message: `Unable to clear storage`
117
+ })
118
+ }),
119
+
120
+ size: Effect.try({
121
+ try: () => sessionStorage.length,
122
+ catch: () =>
123
+ storageError({
124
+ pathOrDescriptor: "layerSessionStorage",
125
+ method: "size",
126
+ message: `Unable to get size`
127
+ })
128
+ })
129
+ })
130
+ )
@@ -0,0 +1,24 @@
1
+ import * as Effect from "@effect/io/Effect"
2
+ import * as Fiber from "@effect/io/Fiber"
3
+ import type * as FiberId from "@effect/io/Fiber/Id"
4
+
5
+ /** @internal */
6
+ export const runMain = <E, A>(
7
+ effect: Effect.Effect<never, E, A>
8
+ ) => {
9
+ const fiber = Effect.runFork(effect)
10
+
11
+ fiber.unsafeAddObserver(() => {
12
+ Effect.runFork(interruptAll(fiber.id()))
13
+ })
14
+
15
+ addEventListener("beforeunload", () => {
16
+ Effect.runFork(fiber.interruptAsFork(fiber.id()))
17
+ })
18
+ }
19
+
20
+ const interruptAll = (id: FiberId.FiberId) =>
21
+ Effect.flatMap(
22
+ Fiber.roots,
23
+ (roots) => Fiber.interruptAllAs(roots, id)
24
+ )
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/esm",
5
+ "declarationDir": "build/dts",
6
+ "tsBuildInfoFile": "build/tsbuildinfo/esm.tsbuildinfo",
7
+ "rootDir": "src"
8
+ },
9
+ "include": ["src/**/*.ts"],
10
+ "references": [{ "path": "../platform"}]
11
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "tsBuildInfoFile": "build/tsbuildinfo/examples.tsbuildinfo",
5
+ "rootDir": "examples",
6
+ "module": "CommonJS",
7
+ "outDir": "build/examples"
8
+ },
9
+ "include": ["examples/**/*.ts"],
10
+ "references": [{ "path": "./tsconfig.build.json" },
11
+ ]
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "tsBuildInfoFile": "build/tsbuildinfo/tsconfig.tsbuildinfo"
5
+ },
6
+ "references": [
7
+ { "path": "./tsconfig.build.json" },
8
+ { "path": "./tsconfig.test.json" },
9
+ { "path": "./tsconfig.examples.json" }
10
+ ]
11
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "build/test",
5
+ "declarationDir": "build/test-dts",
6
+ "tsBuildInfoFile": "build/tsbuildinfo/test.tsbuildinfo",
7
+ "rootDir": "test",
8
+ "noEmit": true,
9
+ "types": ["vitest/globals"]
10
+ },
11
+ "include": ["test/**/*.ts"],
12
+ "references": [
13
+ {
14
+ "path": "./tsconfig.build.json"
15
+ }
16
+ ]
17
+ }