@effect/platform-browser 4.0.0-beta.7 → 4.0.0-beta.71

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 +81 -0
  2. package/dist/BrowserCrypto.d.ts.map +1 -0
  3. package/dist/BrowserCrypto.js +119 -0
  4. package/dist/BrowserCrypto.js.map +1 -0
  5. package/dist/BrowserHttpClient.d.ts +40 -16
  6. package/dist/BrowserHttpClient.d.ts.map +1 -1
  7. package/dist/BrowserHttpClient.js +74 -18
  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 +185 -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 +79 -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 +64 -6
  22. package/dist/BrowserSocket.d.ts.map +1 -1
  23. package/dist/BrowserSocket.js +64 -6
  24. package/dist/BrowserSocket.js.map +1 -1
  25. package/dist/BrowserStream.d.ts +48 -5
  26. package/dist/BrowserStream.d.ts.map +1 -1
  27. package/dist/BrowserStream.js +48 -5
  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 +62 -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 +65 -10
  36. package/dist/BrowserWorkerRunner.js.map +1 -1
  37. package/dist/Clipboard.d.ts +77 -13
  38. package/dist/Clipboard.d.ts.map +1 -1
  39. package/dist/Clipboard.js +57 -11
  40. package/dist/Clipboard.js.map +1 -1
  41. package/dist/Geolocation.d.ts +101 -24
  42. package/dist/Geolocation.d.ts.map +1 -1
  43. package/dist/Geolocation.js +69 -16
  44. package/dist/Geolocation.js.map +1 -1
  45. package/dist/IndexedDb.d.ts +89 -0
  46. package/dist/IndexedDb.d.ts.map +1 -0
  47. package/dist/IndexedDb.js +99 -0
  48. package/dist/IndexedDb.js.map +1 -0
  49. package/dist/IndexedDbDatabase.d.ts +169 -0
  50. package/dist/IndexedDbDatabase.d.ts.map +1 -0
  51. package/dist/IndexedDbDatabase.js +343 -0
  52. package/dist/IndexedDbDatabase.js.map +1 -0
  53. package/dist/IndexedDbQueryBuilder.d.ts +438 -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 +191 -0
  58. package/dist/IndexedDbTable.d.ts.map +1 -0
  59. package/dist/IndexedDbTable.js +96 -0
  60. package/dist/IndexedDbTable.js.map +1 -0
  61. package/dist/IndexedDbVersion.d.ts +94 -0
  62. package/dist/IndexedDbVersion.d.ts.map +1 -0
  63. package/dist/IndexedDbVersion.js +39 -0
  64. package/dist/IndexedDbVersion.js.map +1 -0
  65. package/dist/Permissions.d.ts +76 -16
  66. package/dist/Permissions.d.ts.map +1 -1
  67. package/dist/Permissions.js +66 -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 +129 -0
  75. package/src/BrowserHttpClient.ts +84 -24
  76. package/src/BrowserKeyValueStore.ts +201 -12
  77. package/src/BrowserPersistence.ts +376 -0
  78. package/src/BrowserRuntime.ts +79 -4
  79. package/src/BrowserSocket.ts +64 -6
  80. package/src/BrowserStream.ts +48 -5
  81. package/src/BrowserWorker.ts +62 -6
  82. package/src/BrowserWorkerRunner.ts +65 -10
  83. package/src/Clipboard.ts +74 -13
  84. package/src/Geolocation.ts +97 -20
  85. package/src/IndexedDb.ts +127 -0
  86. package/src/IndexedDbDatabase.ts +664 -0
  87. package/src/IndexedDbQueryBuilder.ts +2048 -0
  88. package/src/IndexedDbTable.ts +285 -0
  89. package/src/IndexedDbVersion.ts +133 -0
  90. package/src/Permissions.ts +71 -14
  91. package/src/index.ts +45 -10
@@ -1,20 +1,195 @@
1
- import * as KeyValueStore from "effect/unstable/persistence/KeyValueStore";
2
1
  /**
3
- * Creates a `KeyValueStore` layer that uses the browser's `localStorage` api.
2
+ * Browser-backed `KeyValueStore` layers for client-side Effect programs.
3
+ *
4
+ * This module provides browser implementations of the unstable persistence
5
+ * `KeyValueStore` service. Use {@link layerLocalStorage} for small
6
+ * origin-scoped values that should survive reloads and browser restarts, use
7
+ * {@link layerSessionStorage} for tab / page-session state, and use
8
+ * {@link layerIndexedDb} when the store should be asynchronous and backed by
9
+ * IndexedDB.
10
+ *
11
+ * ## Mental model
12
+ *
13
+ * All exports provide the same `KeyValueStore.KeyValueStore` service; the layer
14
+ * chooses the browser storage backend. The Web Storage layers delegate to
15
+ * `globalThis.localStorage` or `globalThis.sessionStorage` and adapt the
16
+ * string-only API, encoding `Uint8Array` values as base64. The IndexedDB layer
17
+ * stores strings and `Uint8Array` values in an object store and requires the
18
+ * browser `IndexedDb` service to open the database.
19
+ *
20
+ * ## Common tasks
21
+ *
22
+ * - Persist user preferences, lightweight caches, or drafts with
23
+ * {@link layerLocalStorage}.
24
+ * - Keep tab-scoped workflow state with {@link layerSessionStorage}.
25
+ * - Avoid blocking the main thread for larger client-side stores by using
26
+ * {@link layerIndexedDb}.
27
+ *
28
+ * ## Gotchas
4
29
  *
5
- * Values are stored between sessions.
30
+ * These layers only work where browser storage APIs are available. Browsers may
31
+ * deny storage in private modes, sandboxed frames, disabled-storage settings, or
32
+ * quota-limited contexts. Web Storage is synchronous and origin-scoped, so keep
33
+ * payloads small and do not use it as a secure store for secrets. IndexedDB is
34
+ * asynchronous but can still be blocked by permissions, quota limits, version
35
+ * upgrades, or other open tabs.
6
36
  *
7
- * @since 1.0.0
8
- * @category Layers
37
+ * **Example** (Provide localStorage to a program)
38
+ *
39
+ * ```ts
40
+ * import { BrowserKeyValueStore } from "@effect/platform-browser"
41
+ * import { Effect } from "effect"
42
+ * import { KeyValueStore } from "effect/unstable/persistence"
43
+ *
44
+ * const program = Effect.gen(function*() {
45
+ * const store = yield* KeyValueStore.KeyValueStore
46
+ * yield* store.set("theme", "dark")
47
+ * return yield* store.get("theme")
48
+ * }).pipe(
49
+ * Effect.provide(BrowserKeyValueStore.layerLocalStorage)
50
+ * )
51
+ * ```
52
+ *
53
+ * @since 4.0.0
9
54
  */
10
- export const layerLocalStorage = /*#__PURE__*/KeyValueStore.layerStorage(() => globalThis.localStorage);
55
+ import * as Effect from "effect/Effect";
56
+ import * as Layer from "effect/Layer";
57
+ import * as KeyValueStore from "effect/unstable/persistence/KeyValueStore";
58
+ import { IndexedDb } from "./IndexedDb.js";
11
59
  /**
12
- * Creates a `KeyValueStore` layer that uses the browser's `sessionStorage` api.
60
+ * Creates a `KeyValueStore` layer that uses the browser's `localStorage` API and stores values between browser sessions.
13
61
  *
14
- * Values are stored only for the current session.
62
+ * @category layers
63
+ * @since 4.0.0
64
+ */
65
+ export const layerLocalStorage = /*#__PURE__*/KeyValueStore.layerStorage(() => globalThis.localStorage);
66
+ /**
67
+ * Creates a `KeyValueStore` layer that uses the browser's `sessionStorage` API and stores values only for the current session.
15
68
  *
16
- * @since 1.0.0
17
- * @category Layers
69
+ * @category layers
70
+ * @since 4.0.0
18
71
  */
19
72
  export const layerSessionStorage = /*#__PURE__*/KeyValueStore.layerStorage(() => globalThis.sessionStorage);
73
+ /**
74
+ * Creates a `KeyValueStore` layer backed by IndexedDB.
75
+ *
76
+ * **When to use**
77
+ *
78
+ * Use when a browser `KeyValueStore` needs persistent asynchronous IndexedDB
79
+ * storage instead of the synchronous Web Storage APIs.
80
+ *
81
+ * **Details**
82
+ *
83
+ * The database name defaults to `"effect_key_value_store"`. The layer requires
84
+ * the `IndexedDb` service and stores string and `Uint8Array` values in the same
85
+ * backing object store.
86
+ *
87
+ * **Gotchas**
88
+ *
89
+ * IndexedDB may be unavailable or blocked by browser settings, private browsing,
90
+ * quota limits, or restricted contexts. The string and `Uint8Array` accessors do
91
+ * not coerce values stored with the other representation.
92
+ *
93
+ * @see {@link layerLocalStorage} for synchronous persistent Web Storage
94
+ * @see {@link layerSessionStorage} for synchronous tab-session Web Storage
95
+ *
96
+ * @category layers
97
+ * @since 4.0.0
98
+ */
99
+ export const layerIndexedDb = options => Layer.effect(KeyValueStore.KeyValueStore)(Effect.gen(function* () {
100
+ const db = yield* Effect.acquireRelease(openDatabase(options?.database ?? "effect_key_value_store"), db => Effect.sync(() => db.close())).pipe(Effect.orDie);
101
+ return KeyValueStore.make({
102
+ clear: Effect.suspend(() => {
103
+ const store = getKvsEntriesStore(db, "readwrite");
104
+ return idbRequest({
105
+ method: "clear",
106
+ message: "Failed to clear backing store"
107
+ }, () => store.clear());
108
+ }),
109
+ get: key => Effect.map(Effect.suspend(() => {
110
+ const store = getKvsEntriesStore(db, "readonly");
111
+ return idbRequest({
112
+ method: "get",
113
+ message: "Failed to get value from backing store",
114
+ key
115
+ }, () => store.get(key));
116
+ }), found => typeof found?.value === "string" ? found.value : undefined),
117
+ getUint8Array: key => Effect.map(Effect.suspend(() => {
118
+ const store = getKvsEntriesStore(db, "readonly");
119
+ return idbRequest({
120
+ method: "getUint8Array",
121
+ message: "Failed to get value from backing store",
122
+ key
123
+ }, () => store.get(key));
124
+ }), found => found?.value && found.value instanceof Uint8Array ? found.value : undefined),
125
+ set: (key, value) => Effect.asVoid(Effect.suspend(() => {
126
+ const store = getKvsEntriesStore(db, "readwrite");
127
+ return idbRequest({
128
+ method: "set",
129
+ message: "Failed to set value in backing store",
130
+ key
131
+ }, () => store.put({
132
+ key,
133
+ value
134
+ }));
135
+ })),
136
+ size: Effect.suspend(() => {
137
+ const store = getKvsEntriesStore(db, "readonly");
138
+ return idbRequest({
139
+ method: "size",
140
+ message: "Failed to get backing store size"
141
+ }, () => store.count());
142
+ }),
143
+ remove: key => Effect.asVoid(Effect.suspend(() => {
144
+ const store = getKvsEntriesStore(db, "readwrite");
145
+ return idbRequest({
146
+ method: "remove",
147
+ message: "Failed to remove value from backing store",
148
+ key
149
+ }, () => store.delete(key));
150
+ }))
151
+ });
152
+ }));
153
+ const databaseVersion = 1;
154
+ const entriesStoreName = "entries";
155
+ const openDatabase = /*#__PURE__*/Effect.fnUntraced(function* (database) {
156
+ const idb = (yield* IndexedDb).indexedDB;
157
+ const openRequest = yield* Effect.try({
158
+ try: () => idb.open(database, databaseVersion),
159
+ catch: cause => new KeyValueStore.KeyValueStoreError({
160
+ method: "open",
161
+ message: "Failed to open backing store database",
162
+ cause
163
+ })
164
+ });
165
+ openRequest.onupgradeneeded = () => {
166
+ const db = openRequest.result;
167
+ if (!db.objectStoreNames.contains(entriesStoreName)) {
168
+ db.createObjectStore(entriesStoreName, {
169
+ keyPath: "key"
170
+ });
171
+ }
172
+ };
173
+ return yield* idbRequest({
174
+ method: "open",
175
+ message: "Failed to open backing store database"
176
+ }, () => openRequest);
177
+ });
178
+ const idbRequest = (failArgs, evaluate) => Effect.callback(resume => {
179
+ const request = evaluate();
180
+ if (request.readyState === "done") {
181
+ return resume(Effect.succeed(request.result));
182
+ }
183
+ request.onsuccess = () => {
184
+ resume(Effect.succeed(request.result));
185
+ };
186
+ request.onerror = () => resume(Effect.fail(new KeyValueStore.KeyValueStoreError({
187
+ ...failArgs,
188
+ cause: request.error
189
+ })));
190
+ });
191
+ const getKvsEntriesStore = (db, mode) => {
192
+ const transaction = db.transaction(entriesStoreName, mode);
193
+ return transaction.objectStore(entriesStoreName);
194
+ };
20
195
  //# sourceMappingURL=BrowserKeyValueStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserKeyValueStore.js","names":["KeyValueStore","layerLocalStorage","layerStorage","globalThis","localStorage","layerSessionStorage","sessionStorage"],"sources":["../src/BrowserKeyValueStore.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,aAAa,MAAM,2CAA2C;AAE1E;;;;;;;;AAQA,OAAO,MAAMC,iBAAiB,gBAA6CD,aAAa,CAACE,YAAY,CAAC,MACpGC,UAAU,CAACC,YAAY,CACxB;AAED;;;;;;;;AAQA,OAAO,MAAMC,mBAAmB,gBAA6CL,aAAa,CAACE,YAAY,CAAC,MACtGC,UAAU,CAACG,cAAc,CAC1B","ignoreList":[]}
1
+ {"version":3,"file":"BrowserKeyValueStore.js","names":["Effect","Layer","KeyValueStore","IndexedDb","layerLocalStorage","layerStorage","globalThis","localStorage","layerSessionStorage","sessionStorage","layerIndexedDb","options","effect","gen","db","acquireRelease","openDatabase","database","sync","close","pipe","orDie","make","clear","suspend","store","getKvsEntriesStore","idbRequest","method","message","get","key","map","found","value","undefined","getUint8Array","Uint8Array","set","asVoid","put","size","count","remove","delete","databaseVersion","entriesStoreName","fnUntraced","idb","indexedDB","openRequest","try","open","catch","cause","KeyValueStoreError","onupgradeneeded","result","objectStoreNames","contains","createObjectStore","keyPath","failArgs","evaluate","callback","resume","request","readyState","succeed","onsuccess","onerror","fail","error","mode","transaction","objectStore"],"sources":["../src/BrowserKeyValueStore.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,aAAa,MAAM,2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AuC,CAAE,EAAE,MAAMqB,WAAW,CAAC;AACnH,CAAC,CAAC;AAEF,MAAMvB,UAAU,GAAGA,CACjBmC,QAA2D,EAC3DC,QAA6B,KAE7B/D,MAAM,CAACgE,QAAQ,CAAuCC,MAAM,IAAI;EAC9D,MAAMC,OAAO,GAAGH,QAAQ,EAAE;EAC1B,IAAIG,OAAO,CAACC,UAAU,KAAK,MAAM,EAAE;IACjC,OAAOF,MAAM,CAACjE,MAAM,CAACoE,OAAO,CAACF,OAAO,CAACT,MAAM,CAAC,CAAC;EAC/C;EACAS,OAAO,CAACG,SAAS,GAAG,MAAK;IACvBJ,MAAM,CAACjE,MAAM,CAACoE,OAAO,CAACF,OAAO,CAACT,MAAM,CAAC,CAAC;EACxC,CAAC;EACDS,OAAO,CAACI,OAAO,GAAG,MAChBL,MAAM,CAACjE,MAAM,CAACuE,IAAI,CAChB,IAAIrE,aAAa,CAACqD,kBAAkB,CAAC;IACnC,GAAGO,QAAQ;IACXR,KAAK,EAAEY,OAAO,CAACM;GAChB,CAAC,CACH,CAAC;AACN,CAAC,CAAC;AAEJ,MAAM9C,kBAAkB,GAAGA,CAACZ,EAAe,EAAE2D,IAAwB,KAAI;EACvE,MAAMC,WAAW,GAAG5D,EAAE,CAAC4D,WAAW,CAAC5B,gBAAgB,EAAE2B,IAAI,CAAC;EAC1D,OAAOC,WAAW,CAACC,WAAW,CAAC7B,gBAAgB,CAAC;AAClD,CAAC","ignoreList":[]}
@@ -0,0 +1,40 @@
1
+ import * as Layer from "effect/Layer";
2
+ import * as Persistence from "effect/unstable/persistence/Persistence";
3
+ /**
4
+ * Creates a `BackingPersistence` layer backed by IndexedDB, optionally using the provided database name.
5
+ *
6
+ * **When to use**
7
+ *
8
+ * Use when composing persistence manually and the lower-level
9
+ * `BackingPersistence` service should be backed by browser IndexedDB.
10
+ *
11
+ * **Details**
12
+ *
13
+ * The database name defaults to `"effect_persistence"`. Entries are stored by
14
+ * persistence store id and key in a shared object store, and TTL expiration is
15
+ * checked when values are read.
16
+ *
17
+ * **Gotchas**
18
+ *
19
+ * Opening the database is defected during layer acquisition if IndexedDB is
20
+ * unavailable or cannot be opened. Store operations report `PersistenceError`
21
+ * for IndexedDB request, transaction, quota, and structured-clone failures.
22
+ *
23
+ * @see {@link layerIndexedDb} for providing the higher-level `Persistence` service
24
+ *
25
+ * @category layers
26
+ * @since 4.0.0
27
+ */
28
+ export declare const layerBackingIndexedDb: (options?: {
29
+ readonly database?: string | undefined;
30
+ }) => Layer.Layer<Persistence.BackingPersistence>;
31
+ /**
32
+ * Creates a `Persistence` layer backed by IndexedDB, optionally using the provided database name.
33
+ *
34
+ * @category layers
35
+ * @since 4.0.0
36
+ */
37
+ export declare const layerIndexedDb: (options?: {
38
+ readonly database?: string | undefined;
39
+ }) => Layer.Layer<Persistence.Persistence>;
40
+ //# sourceMappingURL=BrowserPersistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserPersistence.d.ts","sourceRoot":"","sources":["../src/BrowserPersistence.ts"],"names":[],"mappings":"AAyDA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,WAAW,MAAM,yCAAyC,CAAA;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU;IAC9C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACvC,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,kBAAkB,CAoBzC,CAAA;AAOL;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACvC,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAGpC,CAAA"}
@@ -0,0 +1,207 @@
1
+ import * as Clock from "effect/Clock";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Persistence from "effect/unstable/persistence/Persistence";
5
+ /**
6
+ * Creates a `BackingPersistence` layer backed by IndexedDB, optionally using the provided database name.
7
+ *
8
+ * **When to use**
9
+ *
10
+ * Use when composing persistence manually and the lower-level
11
+ * `BackingPersistence` service should be backed by browser IndexedDB.
12
+ *
13
+ * **Details**
14
+ *
15
+ * The database name defaults to `"effect_persistence"`. Entries are stored by
16
+ * persistence store id and key in a shared object store, and TTL expiration is
17
+ * checked when values are read.
18
+ *
19
+ * **Gotchas**
20
+ *
21
+ * Opening the database is defected during layer acquisition if IndexedDB is
22
+ * unavailable or cannot be opened. Store operations report `PersistenceError`
23
+ * for IndexedDB request, transaction, quota, and structured-clone failures.
24
+ *
25
+ * @see {@link layerIndexedDb} for providing the higher-level `Persistence` service
26
+ *
27
+ * @category layers
28
+ * @since 4.0.0
29
+ */
30
+ export const layerBackingIndexedDb = options => Layer.effect(Persistence.BackingPersistence)(Effect.gen(function* () {
31
+ const db = yield* Effect.acquireRelease(openDatabase(options?.database ?? defaultDatabase), db => Effect.sync(() => db.close())).pipe(Effect.orDie);
32
+ return Persistence.BackingPersistence.of({
33
+ make: Effect.fnUntraced(function* (storeId) {
34
+ const clock = yield* Clock.Clock;
35
+ return {
36
+ get: key => get(db, clock, storeId, key),
37
+ getMany: keys => getMany(db, clock, storeId, keys),
38
+ set: (key, value, ttl) => set(db, clock, storeId, key, value, ttl),
39
+ setMany: entries => setMany(db, clock, storeId, entries),
40
+ remove: key => remove(db, storeId, key),
41
+ clear: clear(db, storeId)
42
+ };
43
+ })
44
+ });
45
+ }));
46
+ const defaultDatabase = "effect_persistence";
47
+ const databaseVersion = 1;
48
+ const entriesStoreName = "entries";
49
+ const storeIdIndexName = "storeId";
50
+ /**
51
+ * Creates a `Persistence` layer backed by IndexedDB, optionally using the provided database name.
52
+ *
53
+ * @category layers
54
+ * @since 4.0.0
55
+ */
56
+ export const layerIndexedDb = options => Persistence.layer.pipe(Layer.provide(layerBackingIndexedDb(options)));
57
+ const openDatabase = database => Effect.gen(function* () {
58
+ const openRequest = yield* Effect.try({
59
+ try: () => globalThis.indexedDB.open(database, databaseVersion),
60
+ catch: cause => new Persistence.PersistenceError({
61
+ message: "Failed to open backing store database",
62
+ cause
63
+ })
64
+ });
65
+ openRequest.onupgradeneeded = () => {
66
+ const db = openRequest.result;
67
+ const entries = db.objectStoreNames.contains(entriesStoreName) ? openRequest.transaction?.objectStore(entriesStoreName) : db.createObjectStore(entriesStoreName, {
68
+ keyPath: ["storeId", "id"]
69
+ });
70
+ if (entries && !entries.indexNames.contains(storeIdIndexName)) {
71
+ entries.createIndex(storeIdIndexName, storeIdIndexName, {
72
+ unique: false
73
+ });
74
+ }
75
+ };
76
+ return yield* idbRequest("Failed to open backing store database", () => openRequest);
77
+ });
78
+ const isExpired = (row, now) => row.expires !== null && row.expires <= now;
79
+ const get = (db, clock, storeId, key) => withEntriesTransaction(db, "readwrite", `Failed to get key ${key} from backing store`, (entries, setResult, fail) => {
80
+ const now = clock.currentTimeMillisUnsafe();
81
+ const id = [storeId, key];
82
+ const request = entries.get(id);
83
+ request.onerror = () => fail(request.error);
84
+ request.onsuccess = () => {
85
+ const row = request.result;
86
+ if (!row || !isExpired(row, now)) {
87
+ setResult(row?.value);
88
+ return;
89
+ }
90
+ const deleteRequest = entries.delete(id);
91
+ deleteRequest.onerror = () => fail(deleteRequest.error);
92
+ deleteRequest.onsuccess = () => setResult(undefined);
93
+ };
94
+ });
95
+ const getMany = (db, clock, storeId, keys) => withEntriesTransaction(db, "readwrite", "Failed to getMany from backing store", (entries, setResult, fail) => {
96
+ const now = clock.currentTimeMillisUnsafe();
97
+ const results = new Array(keys.length);
98
+ setResult(results);
99
+ for (let i = 0; i < keys.length; i++) {
100
+ const key = keys[i];
101
+ const keyPath = [storeId, key];
102
+ const request = entries.get(keyPath);
103
+ request.onerror = () => fail(request.error);
104
+ request.onsuccess = () => {
105
+ const row = request.result;
106
+ if (!row) return;else if (!isExpired(row, now)) {
107
+ results[i] = row.value;
108
+ return;
109
+ }
110
+ const deleteRequest = entries.delete(keyPath);
111
+ deleteRequest.onerror = () => fail(deleteRequest.error);
112
+ };
113
+ }
114
+ });
115
+ const set = (db, clock, storeId, key, value, ttl) => withEntriesTransaction(db, "readwrite", `Failed to set key ${key} in backing store`, (entries, setResult, fail) => {
116
+ const request = entries.put({
117
+ storeId,
118
+ id: key,
119
+ value,
120
+ expires: Persistence.unsafeTtlToExpires(clock, ttl)
121
+ });
122
+ request.onerror = () => fail(request.error);
123
+ request.onsuccess = () => setResult(undefined);
124
+ });
125
+ const setMany = (db, clock, storeId, entries) => withEntriesTransaction(db, "readwrite", "Failed to setMany in backing store", (store, setResult, fail) => {
126
+ for (const [key, value, ttl] of entries) {
127
+ const request = store.put({
128
+ storeId,
129
+ id: key,
130
+ value,
131
+ expires: Persistence.unsafeTtlToExpires(clock, ttl)
132
+ });
133
+ request.onerror = () => fail(request.error);
134
+ request.onsuccess = () => setResult(undefined);
135
+ }
136
+ });
137
+ const remove = (db, storeId, key) => withEntriesTransaction(db, "readwrite", `Failed to remove key ${key} from backing store`, (entries, setResult, fail) => {
138
+ const request = entries.delete([storeId, key]);
139
+ request.onerror = () => fail(request.error);
140
+ request.onsuccess = () => setResult(undefined);
141
+ });
142
+ const clear = (db, storeId) => withEntriesTransaction(db, "readwrite", "Failed to clear backing store", (entries, setResult, fail) => {
143
+ const index = entries.index(storeIdIndexName);
144
+ const cursorRequest = index.openCursor(storeId);
145
+ cursorRequest.onerror = () => fail(cursorRequest.error);
146
+ cursorRequest.onsuccess = () => {
147
+ const cursor = cursorRequest.result;
148
+ if (!cursor) {
149
+ setResult(undefined);
150
+ return;
151
+ }
152
+ const deleteRequest = cursor.delete();
153
+ deleteRequest.onerror = () => fail(deleteRequest.error);
154
+ deleteRequest.onsuccess = () => cursor.continue();
155
+ };
156
+ });
157
+ const withEntriesTransaction = (db, mode, message, run) => Effect.callback(resume => {
158
+ const tx = db.transaction(entriesStoreName, mode);
159
+ const entries = tx.objectStore(entriesStoreName);
160
+ let result;
161
+ let setResult = false;
162
+ let done = false;
163
+ const fail = cause => {
164
+ done = true;
165
+ resume(Effect.fail(new Persistence.PersistenceError({
166
+ message,
167
+ cause
168
+ })));
169
+ };
170
+ tx.oncomplete = () => {
171
+ done = true;
172
+ if (setResult) resume(Effect.succeed(result));
173
+ };
174
+ tx.onerror = () => {
175
+ done = true;
176
+ fail(tx.error);
177
+ };
178
+ tx.onabort = () => {
179
+ done = true;
180
+ fail(tx.error);
181
+ };
182
+ run(entries, next => {
183
+ if (done) return resume(Effect.succeed(next));
184
+ setResult = true;
185
+ result = next;
186
+ }, fail);
187
+ return Effect.sync(() => {
188
+ tx.abort();
189
+ });
190
+ });
191
+ const idbRequest = (message, evaluate) => Effect.callback(resume => {
192
+ const request = evaluate();
193
+ const fail = cause => {
194
+ resume(Effect.fail(new Persistence.PersistenceError({
195
+ message,
196
+ cause
197
+ })));
198
+ };
199
+ if (request.readyState === "done") {
200
+ resume(Effect.succeed(request.result));
201
+ }
202
+ request.onsuccess = () => {
203
+ resume(Effect.succeed(request.result));
204
+ };
205
+ request.onerror = () => fail(request.error);
206
+ });
207
+ //# sourceMappingURL=BrowserPersistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserPersistence.js","names":["Clock","Effect","Layer","Persistence","layerBackingIndexedDb","options","effect","BackingPersistence","gen","db","acquireRelease","openDatabase","database","defaultDatabase","sync","close","pipe","orDie","of","make","fnUntraced","storeId","clock","get","key","getMany","keys","set","value","ttl","setMany","entries","remove","clear","databaseVersion","entriesStoreName","storeIdIndexName","layerIndexedDb","layer","provide","openRequest","try","globalThis","indexedDB","open","catch","cause","PersistenceError","message","onupgradeneeded","result","objectStoreNames","contains","transaction","objectStore","createObjectStore","keyPath","indexNames","createIndex","unique","idbRequest","isExpired","row","now","expires","withEntriesTransaction","setResult","fail","currentTimeMillisUnsafe","id","request","onerror","error","onsuccess","deleteRequest","delete","undefined","results","Array","length","i","put","unsafeTtlToExpires","store","index","cursorRequest","openCursor","cursor","continue","mode","run","callback","resume","tx","done","oncomplete","succeed","onabort","next","abort","evaluate","readyState"],"sources":["../src/BrowserPersistence.ts"],"sourcesContent":[null],"mappings":"AAsDA,OAAO,KAAKA,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,WAAW,MAAM,yCAAyC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,MAAMC,qBAAqB,GAAIC,OAErC,IACCH,KAAK,CAACI,MAAM,CAACH,WAAW,CAACI,kBAAkB,CAAC,CAACN,MAAM,CAACO,GAAG,CAAC,aAAS;EAC/D,MAAMC,EAAE,GAAG,OAAOR,MAAM,CAACS,cAAc,CACrCC,YAAY,CAACN,OAAO,EAAEO,QAAQ,IAAIC,eAAe,CAAC,EACjDJ,EAAE,IAAKR,MAAM,CAACa,IAAI,CAAC,MAAML,EAAE,CAACM,KAAK,EAAE,CAAC,CACtC,CAACC,IAAI,CAACf,MAAM,CAACgB,KAAK,CAAC;EAEpB,OAAOd,WAAW,CAACI,kBAAkB,CAACW,EAAE,CAAC;IACvCC,IAAI,EAAElB,MAAM,CAACmB,UAAU,CAAC,WAAUC,OAAO;MACvC,MAAMC,KAAK,GAAG,OAAOtB,KAAK,CAACA,KAAK;MAChC,OAAO;QACLuB,GAAG,EAAGC,GAAG,IAAKD,GAAG,CAACd,EAAE,EAAEa,KAAK,EAAED,OAAO,EAAEG,GAAG,CAAC;QAC1CC,OAAO,EAAGC,IAAI,IAAKD,OAAO,CAAChB,EAAE,EAAEa,KAAK,EAAED,OAAO,EAAEK,IAAI,CAAC;QACpDC,GAAG,EAAEA,CAACH,GAAG,EAAEI,KAAK,EAAEC,GAAG,KAAKF,GAAG,CAAClB,EAAE,EAAEa,KAAK,EAAED,OAAO,EAAEG,GAAG,EAAEI,KAAK,EAAEC,GAAG,CAAC;QAClEC,OAA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E/B,IAAI,CAAC;EAER,OAAOlE,MAAM,CAACa,IAAI,CAAC,MAAK;IACtB+E,EAAE,CAACM,KAAK,EAAE;EACZ,CAAC,CAAC;AACJ,CAAC,CAAC;AAEJ,MAAMvC,UAAU,GAAGA,CACjBZ,OAAe,EACfoD,QAA6B,KAE7BnG,MAAM,CAAC0F,QAAQ,CAAmCC,MAAM,IAAI;EAC1D,MAAMtB,OAAO,GAAG8B,QAAQ,EAAE;EAC1B,MAAMjC,IAAI,GAAIrB,KAAc,IAAI;IAC9B8C,MAAM,CAAC3F,MAAM,CAACkE,IAAI,CAAC,IAAIhE,WAAW,CAAC4C,gBAAgB,CAAC;MAAEC,OAAO;MAAEF;IAAK,CAAE,CAAC,CAAC,CAAC;EAC3E,CAAC;EACD,IAAIwB,OAAO,CAAC+B,UAAU,KAAK,MAAM,EAAE;IACjCT,MAAM,CAAC3F,MAAM,CAAC+F,OAAO,CAAC1B,OAAO,CAACpB,MAAM,CAAC,CAAC;EACxC;EACAoB,OAAO,CAACG,SAAS,GAAG,MAAK;IACvBmB,MAAM,CAAC3F,MAAM,CAAC+F,OAAO,CAAC1B,OAAO,CAACpB,MAAM,CAAC,CAAC;EACxC,CAAC;EACDoB,OAAO,CAACC,OAAO,GAAG,MAAMJ,IAAI,CAACG,OAAO,CAACE,KAAK,CAAC;AAC7C,CAAC,CAAC","ignoreList":[]}
@@ -1,24 +1,99 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Browser entry-point helpers for running Effect programs.
3
+ *
4
+ * This module exposes `runMain`, a browser-oriented main runner for launching
5
+ * an Effect as the root program of a page, single-page application, demo, or
6
+ * browser test harness. It delegates execution to the core Effect runtime while
7
+ * adding the browser lifecycle hook needed to interrupt the main fiber when the
8
+ * page receives `beforeunload`.
9
+ *
10
+ * `BrowserRuntime` does not provide application services by itself. Provide
11
+ * any required layers, such as browser HTTP, storage, worker, geolocation, or
12
+ * permission services, before passing the effect to `runMain`. Keep long-lived
13
+ * browser resources scoped so interruption can run their finalizers while the
14
+ * page is still active.
15
+ *
16
+ * Browser unload is more constrained than a process signal. Finalizers that
17
+ * need the network, timers, prompts, or long asynchronous work may not complete
18
+ * once navigation or tab close has started, and browsers do not expose a
19
+ * process exit status. Use `runMain` to connect the page lifecycle to Effect
20
+ * interruption, and use browser-specific persistence or delivery APIs for work
21
+ * that must survive page teardown.
22
+ *
23
+ * @since 4.0.0
3
24
  */
4
25
  import type * as Effect from "effect/Effect";
5
26
  import { type Teardown } from "effect/Runtime";
6
27
  /**
7
- * @since 1.0.0
28
+ * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
29
+ *
30
+ * **When to use**
31
+ *
32
+ * Use to launch a browser page, single-page application, demo, or browser test
33
+ * harness as a root Effect program.
34
+ *
35
+ * **Details**
36
+ *
37
+ * Supports both direct and curried call forms. Options are forwarded to
38
+ * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
39
+ * behavior.
40
+ *
41
+ * **Gotchas**
42
+ *
43
+ * The `beforeunload` interruption is best-effort. Browser teardown may prevent
44
+ * asynchronous finalizers, network work, timers, or prompts from completing.
45
+ *
8
46
  * @category Runtime
47
+ * @since 4.0.0
9
48
  */
10
49
  export declare const runMain: {
11
50
  /**
12
- * @since 1.0.0
51
+ * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
52
+ *
53
+ * **When to use**
54
+ *
55
+ * Use to launch a browser page, single-page application, demo, or browser test
56
+ * harness as a root Effect program.
57
+ *
58
+ * **Details**
59
+ *
60
+ * Supports both direct and curried call forms. Options are forwarded to
61
+ * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
62
+ * behavior.
63
+ *
64
+ * **Gotchas**
65
+ *
66
+ * The `beforeunload` interruption is best-effort. Browser teardown may prevent
67
+ * asynchronous finalizers, network work, timers, or prompts from completing.
68
+ *
13
69
  * @category Runtime
70
+ * @since 4.0.0
14
71
  */
15
72
  (options?: {
16
73
  readonly disableErrorReporting?: boolean | undefined;
17
74
  readonly teardown?: Teardown | undefined;
18
75
  }): <E, A>(effect: Effect.Effect<A, E>) => void;
19
76
  /**
20
- * @since 1.0.0
77
+ * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
78
+ *
79
+ * **When to use**
80
+ *
81
+ * Use to launch a browser page, single-page application, demo, or browser test
82
+ * harness as a root Effect program.
83
+ *
84
+ * **Details**
85
+ *
86
+ * Supports both direct and curried call forms. Options are forwarded to
87
+ * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
88
+ * behavior.
89
+ *
90
+ * **Gotchas**
91
+ *
92
+ * The `beforeunload` interruption is best-effort. Browser teardown may prevent
93
+ * asynchronous finalizers, network work, timers, or prompts from completing.
94
+ *
21
95
  * @category Runtime
96
+ * @since 4.0.0
22
97
  */
23
98
  <E, A>(effect: Effect.Effect<A, E>, options?: {
24
99
  readonly disableErrorReporting?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserRuntime.d.ts","sourceRoot":"","sources":["../src/BrowserRuntime.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE3D;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE;IACpB;;;OAGG;IACH,CACE,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAA;IAC9C;;;OAGG;IACH,CAAC,CAAC,EAAE,CAAC,EACH,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,IAAI,CAAA;CAKP,CAAA"}
1
+ {"version":3,"file":"BrowserRuntime.d.ts","sourceRoot":"","sources":["../src/BrowserRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,OAAO,EAAE;IACpB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,CACE,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAA;IAC9C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,CAAC,CAAC,EAAE,CAAC,EACH,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;KACzC,GACA,IAAI,CAAA;CAKP,CAAA"}
@@ -1,7 +1,25 @@
1
1
  import { makeRunMain } from "effect/Runtime";
2
2
  /**
3
- * @since 1.0.0
3
+ * Runs an effect as the browser main program and interrupts its fiber when the page receives a `beforeunload` event.
4
+ *
5
+ * **When to use**
6
+ *
7
+ * Use to launch a browser page, single-page application, demo, or browser test
8
+ * harness as a root Effect program.
9
+ *
10
+ * **Details**
11
+ *
12
+ * Supports both direct and curried call forms. Options are forwarded to
13
+ * `makeRunMain`, including `disableErrorReporting` and custom `teardown`
14
+ * behavior.
15
+ *
16
+ * **Gotchas**
17
+ *
18
+ * The `beforeunload` interruption is best-effort. Browser teardown may prevent
19
+ * asynchronous finalizers, network work, timers, or prompts from completing.
20
+ *
4
21
  * @category Runtime
22
+ * @since 4.0.0
5
23
  */
6
24
  export const runMain = /*#__PURE__*/makeRunMain(({
7
25
  fiber
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserRuntime.js","names":["makeRunMain","runMain","fiber","globalThis","addEventListener","interruptUnsafe","id"],"sources":["../src/BrowserRuntime.ts"],"sourcesContent":[null],"mappings":"AAIA,SAASA,WAAW,QAAuB,gBAAgB;AAE3D;;;;AAIA,OAAO,MAAMC,OAAO,gBAsBhBD,WAAW,CAAC,CAAC;EAAEE;AAAK,CAAE,KAAI;EAC5BC,UAAU,CAACC,gBAAgB,CAAC,cAAc,EAAE,MAAK;IAC/CF,KAAK,CAACG,eAAe,CAACH,KAAK,CAACI,EAAE,CAAC;EACjC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"BrowserRuntime.js","names":["makeRunMain","runMain","fiber","globalThis","addEventListener","interruptUnsafe","id"],"sources":["../src/BrowserRuntime.ts"],"sourcesContent":[null],"mappings":"AAyBA,SAASA,WAAW,QAAuB,gBAAgB;AAE3D;;;;;;;;;;;;;;;;;;;;;;AAsBA,OAAO,MAAMC,OAAO,gBA0DhBD,WAAW,CAAC,CAAC;EAAEE;AAAK,CAAE,KAAI;EAC5BC,UAAU,CAACC,gBAAgB,CAAC,cAAc,EAAE,MAAK;IAC/CF,KAAK,CAACG,eAAe,CAACH,KAAK,CAACI,EAAE,CAAC;EACjC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}