@livestore/utils 0.4.0-dev.18 → 0.4.0-dev.19

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 (86) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/browser/Opfs/Opfs.d.ts +51 -0
  3. package/dist/browser/Opfs/Opfs.d.ts.map +1 -0
  4. package/dist/browser/Opfs/Opfs.js +345 -0
  5. package/dist/browser/Opfs/Opfs.js.map +1 -0
  6. package/dist/browser/Opfs/debug-utils.d.ts +20 -0
  7. package/dist/browser/Opfs/debug-utils.d.ts.map +1 -0
  8. package/dist/browser/Opfs/debug-utils.js +94 -0
  9. package/dist/browser/Opfs/debug-utils.js.map +1 -0
  10. package/dist/browser/Opfs/mod.d.ts +4 -0
  11. package/dist/browser/Opfs/mod.d.ts.map +1 -0
  12. package/dist/browser/Opfs/mod.js +4 -0
  13. package/dist/browser/Opfs/mod.js.map +1 -0
  14. package/dist/browser/Opfs/utils.d.ts +68 -0
  15. package/dist/browser/Opfs/utils.d.ts.map +1 -0
  16. package/dist/browser/Opfs/utils.js +206 -0
  17. package/dist/browser/Opfs/utils.js.map +1 -0
  18. package/dist/browser/QuotaExceededError.d.ts +59 -0
  19. package/dist/browser/QuotaExceededError.d.ts.map +1 -0
  20. package/dist/browser/QuotaExceededError.js +2 -0
  21. package/dist/browser/QuotaExceededError.js.map +1 -0
  22. package/dist/browser/WebChannelBrowser.d.ts +22 -0
  23. package/dist/browser/WebChannelBrowser.d.ts.map +1 -0
  24. package/dist/browser/WebChannelBrowser.js +76 -0
  25. package/dist/browser/WebChannelBrowser.js.map +1 -0
  26. package/dist/browser/WebError.d.ts +425 -0
  27. package/dist/browser/WebError.d.ts.map +1 -0
  28. package/dist/browser/WebError.js +414 -0
  29. package/dist/browser/WebError.js.map +1 -0
  30. package/dist/browser/WebError.test.d.ts +2 -0
  31. package/dist/browser/WebError.test.d.ts.map +1 -0
  32. package/dist/browser/WebError.test.js +46 -0
  33. package/dist/browser/WebError.test.js.map +1 -0
  34. package/dist/browser/WebLock.d.ts.map +1 -0
  35. package/dist/browser/WebLock.js.map +1 -0
  36. package/dist/{browser.d.ts → browser/detect.d.ts} +1 -1
  37. package/dist/browser/detect.d.ts.map +1 -0
  38. package/dist/{browser.js → browser/detect.js} +1 -1
  39. package/dist/browser/detect.js.map +1 -0
  40. package/dist/browser/mod.d.ts +8 -0
  41. package/dist/browser/mod.d.ts.map +1 -0
  42. package/dist/browser/mod.js +8 -0
  43. package/dist/browser/mod.js.map +1 -0
  44. package/dist/effect/WebChannel/WebChannel.d.ts +2 -21
  45. package/dist/effect/WebChannel/WebChannel.d.ts.map +1 -1
  46. package/dist/effect/WebChannel/WebChannel.js +3 -75
  47. package/dist/effect/WebChannel/WebChannel.js.map +1 -1
  48. package/dist/effect/WebChannel/WebChannel.test.js +1 -1
  49. package/dist/effect/WebChannel/WebChannel.test.js.map +1 -1
  50. package/dist/effect/{index.d.ts → mod.d.ts} +2 -4
  51. package/dist/effect/mod.d.ts.map +1 -0
  52. package/dist/effect/{index.js → mod.js} +2 -4
  53. package/dist/effect/mod.js.map +1 -0
  54. package/dist/mod.d.ts +1 -1
  55. package/dist/mod.d.ts.map +1 -1
  56. package/dist/mod.js +1 -1
  57. package/dist/mod.js.map +1 -1
  58. package/dist/node/mod.d.ts +1 -1
  59. package/dist/node/mod.d.ts.map +1 -1
  60. package/dist/node/mod.js +1 -1
  61. package/dist/node/mod.js.map +1 -1
  62. package/package.json +27 -19
  63. package/src/browser/Opfs/Opfs.ts +428 -0
  64. package/src/browser/Opfs/debug-utils.ts +151 -0
  65. package/src/browser/Opfs/mod.ts +3 -0
  66. package/src/browser/Opfs/utils.ts +270 -0
  67. package/src/browser/QuotaExceededError.ts +59 -0
  68. package/src/browser/WebChannelBrowser.ts +131 -0
  69. package/src/browser/WebError.test.ts +66 -0
  70. package/src/browser/WebError.ts +599 -0
  71. package/src/browser/mod.ts +8 -0
  72. package/src/effect/WebChannel/WebChannel.test.ts +1 -1
  73. package/src/effect/WebChannel/WebChannel.ts +11 -127
  74. package/src/effect/{index.ts → mod.ts} +1 -2
  75. package/src/mod.ts +1 -1
  76. package/src/node/mod.ts +1 -1
  77. package/dist/browser.d.ts.map +0 -1
  78. package/dist/browser.js.map +0 -1
  79. package/dist/effect/WebLock.d.ts.map +0 -1
  80. package/dist/effect/WebLock.js.map +0 -1
  81. package/dist/effect/index.d.ts.map +0 -1
  82. package/dist/effect/index.js.map +0 -1
  83. /package/dist/{effect → browser}/WebLock.d.ts +0 -0
  84. /package/dist/{effect → browser}/WebLock.js +0 -0
  85. /package/src/{effect → browser}/WebLock.ts +0 -0
  86. /package/src/{browser.ts → browser/detect.ts} +0 -0
@@ -0,0 +1,51 @@
1
+ import { Effect, Option, Schema, Stream } from 'effect';
2
+ import * as WebError from '../WebError.ts';
3
+ declare const Opfs_base: Effect.Service.Class<Opfs, "@livestore/utils/Opfs", {
4
+ readonly sync: () => {
5
+ readonly getRootDirectoryHandle: Effect.Effect<FileSystemDirectoryHandle, WebError.SecurityError | WebError.UnknownError, never>;
6
+ readonly getFileHandle: (parent: FileSystemDirectoryHandle, name: string, options?: FileSystemGetFileOptions) => Effect.Effect<FileSystemFileHandle, WebError.TypeError | WebError.NotFoundError | WebError.NotAllowedError | WebError.TypeMismatchError | WebError.UnknownError, never>;
7
+ readonly getDirectoryHandle: (parent: FileSystemDirectoryHandle, name: string, options?: FileSystemGetDirectoryOptions) => Effect.Effect<FileSystemDirectoryHandle, WebError.TypeError | WebError.NotFoundError | WebError.NotAllowedError | WebError.TypeMismatchError | WebError.UnknownError, never>;
8
+ readonly removeEntry: (parent: FileSystemDirectoryHandle, name: string, options?: FileSystemRemoveOptions) => Effect.Effect<void, WebError.TypeError | WebError.NoModificationAllowedError | WebError.NotFoundError | WebError.NotAllowedError | WebError.InvalidModificationError | WebError.UnknownError, never>;
9
+ readonly values: (directory: FileSystemDirectoryHandle) => Stream.Stream<FileSystemDirectoryHandle | FileSystemFileHandle, WebError.NotFoundError | WebError.NotAllowedError | WebError.UnknownError, never>;
10
+ readonly resolve: (parent: FileSystemDirectoryHandle, child: FileSystemHandle) => Effect.Effect<Option.None<string[]> | Option.Some<string[]>, WebError.WebError, never>;
11
+ readonly getFile: (handle: FileSystemFileHandle) => Effect.Effect<File, WebError.NotFoundError | WebError.NotAllowedError | WebError.UnknownError, never>;
12
+ readonly writeFile: (handle: FileSystemFileHandle, data: FileSystemWriteChunkType, options?: FileSystemCreateWritableOptions) => Effect.Effect<void, WebError.TypeError | WebError.NoModificationAllowedError | WebError.NotFoundError | WebError.NotAllowedError | WebError.AbortError | WebError.QuotaExceededError | WebError.UnknownError, never>;
13
+ readonly appendToFile: (handle: FileSystemFileHandle, data: FileSystemWriteChunkType) => Effect.Effect<void, WebError.TypeError | WebError.NoModificationAllowedError | WebError.NotFoundError | WebError.NotAllowedError | WebError.AbortError | WebError.QuotaExceededError | WebError.UnknownError, never>;
14
+ readonly truncateFile: (handle: FileSystemFileHandle, size: number) => Effect.Effect<void, WebError.TypeError | WebError.NoModificationAllowedError | WebError.NotFoundError | WebError.NotAllowedError | WebError.AbortError | WebError.QuotaExceededError | WebError.UnknownError, never>;
15
+ readonly createSyncAccessHandle: (handle: FileSystemFileHandle) => Effect.Effect<FileSystemSyncAccessHandle, WebError.NoModificationAllowedError | WebError.NotFoundError | WebError.NotAllowedError | WebError.InvalidStateError | WebError.UnknownError, import("effect/Scope").Scope>;
16
+ readonly syncRead: (handle: FileSystemSyncAccessHandle, buffer: ArrayBuffer | ArrayBufferView, options?: FileSystemReadWriteOptions) => Effect.Effect<number, WebError.RangeError | WebError.TypeError | WebError.InvalidStateError | WebError.UnknownError, never>;
17
+ readonly syncWrite: (handle: FileSystemSyncAccessHandle, buffer: AllowSharedBufferSource, options?: FileSystemReadWriteOptions) => Effect.Effect<number, WebError.WebError, never>;
18
+ readonly syncTruncate: (handle: FileSystemSyncAccessHandle, size: number) => Effect.Effect<void, WebError.WebError, never>;
19
+ readonly syncGetSize: (handle: FileSystemSyncAccessHandle) => Effect.Effect<number, WebError.WebError, never>;
20
+ readonly syncFlush: (handle: FileSystemSyncAccessHandle) => Effect.Effect<void, WebError.WebError, never>;
21
+ };
22
+ readonly accessors: true;
23
+ }>;
24
+ /**
25
+ * Effect service that exposes ergonomic wrappers around Origin Private File System (OPFS) operations.
26
+ *
27
+ * @remarks
28
+ * - Helpers mirror the File System Access API where possible and parse web exceptions into Effect errors.
29
+ * - Sync access handle helpers can only be used in dedicated workers; invoking them in other contexts fails at runtime.
30
+ *
31
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Origin_private_file_system | MDN Reference}
32
+ */
33
+ export declare class Opfs extends Opfs_base {
34
+ }
35
+ /**
36
+ * A no-op Opfs service that can be used for testing.
37
+ */
38
+ export declare const noopOpfs: Opfs;
39
+ declare const OpfsError_base: Schema.TaggedErrorClass<OpfsError, "@livestore/utils/Opfs/Error", {
40
+ readonly _tag: Schema.tag<"@livestore/utils/Opfs/Error">;
41
+ } & {
42
+ message: typeof Schema.String;
43
+ cause: Schema.optional<typeof Schema.Defect>;
44
+ }>;
45
+ /**
46
+ * Error raised when OPFS operations fail.
47
+ */
48
+ export declare class OpfsError extends OpfsError_base {
49
+ }
50
+ export {};
51
+ //# sourceMappingURL=Opfs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Opfs.d.ts","sourceRoot":"","sources":["../../../src/browser/Opfs/Opfs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvD,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;;;;yCAkCP,yBAAyB,QAAQ,MAAM,YAAY,wBAAwB;8CAsBhG,yBAAyB,QAC3B,MAAM,YACF,6BAA6B;uCAsBZ,yBAAyB,QAAQ,MAAM,YAAY,uBAAuB;qCAqB5E,yBAAyB;mCAc3B,yBAAyB,SAAS,gBAAgB;mCAalD,oBAAoB;qCAgBnC,oBAAoB,QACtB,wBAAwB,YACpB,+BAA+B;wCAkCb,oBAAoB,QAAQ,wBAAwB;wCAwCpD,oBAAoB,QAAQ,MAAM;kDAqCxB,oBAAoB;oCA6BlD,0BAA0B,UAC1B,WAAW,GAAG,eAAe,YAC3B,0BAA0B;qCAqB5B,0BAA0B,UAC1B,uBAAuB,YACrB,0BAA0B;wCAkBR,0BAA0B,QAAQ,MAAM;uCAiBzC,0BAA0B;qCAgB5B,0BAA0B;;;;AAxWzD;;;;;;;;GAQG;AACH,qBAAa,IAAK,SAAQ,SAyXxB;CAAG;AAQL;;GAEG;AACH,eAAO,MAAM,QAAQ,MAiBnB,CAAA;;;;;;;AAEF;;GAEG;AACH,qBAAa,SAAU,SAAQ,cAG7B;CAAG"}
@@ -0,0 +1,345 @@
1
+ /// <reference lib="webworker" />
2
+ import { Effect, Option, Schema, Stream } from 'effect';
3
+ import * as WebError from "../WebError.js";
4
+ /**
5
+ * Effect service that exposes ergonomic wrappers around Origin Private File System (OPFS) operations.
6
+ *
7
+ * @remarks
8
+ * - Helpers mirror the File System Access API where possible and parse web exceptions into Effect errors.
9
+ * - Sync access handle helpers can only be used in dedicated workers; invoking them in other contexts fails at runtime.
10
+ *
11
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Origin_private_file_system | MDN Reference}
12
+ */
13
+ export class Opfs extends Effect.Service()('@livestore/utils/Opfs', {
14
+ sync: () => {
15
+ /**
16
+ * Acquire the OPFS root directory handle.
17
+ *
18
+ * @returns Root directory handle for the current origin.
19
+ *
20
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/getDirectory | MDN Reference}
21
+ */
22
+ const getRootDirectoryHandle = Effect.tryPromise({
23
+ try: () => navigator.storage.getDirectory(),
24
+ catch: (u) => WebError.parseWebError(u, [WebError.SecurityError]),
25
+ });
26
+ /**
27
+ * Resolve (and optionally create) a file handle relative to a directory.
28
+ *
29
+ * @param parent - Directory to search.
30
+ * @param name - Target file name.
31
+ * @param options - Forwarded `getFileHandle` options such as `{ create: true }`.
32
+ *
33
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getFileHandle | MDN Reference}
34
+ */
35
+ const getFileHandle = (parent, name, options) => Effect.tryPromise({
36
+ try: () => parent.getFileHandle(name, options),
37
+ catch: (u) => WebError.parseWebError(u, [
38
+ WebError.NotAllowedError,
39
+ WebError.TypeError,
40
+ WebError.TypeMismatchError,
41
+ WebError.NotFoundError,
42
+ ]),
43
+ });
44
+ /**
45
+ * Resolve (and optionally create) a directory handle relative to another directory.
46
+ *
47
+ * @param parent - Directory to search.
48
+ * @param name - Target directory name.
49
+ * @param options - Forwarded `getDirectoryHandle` options such as `{ create: true }`.
50
+ *
51
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle | MDN Reference}
52
+ */
53
+ const getDirectoryHandle = (parent, name, options) => Effect.tryPromise({
54
+ try: () => parent.getDirectoryHandle(name, options),
55
+ catch: (u) => WebError.parseWebError(u, [
56
+ WebError.NotAllowedError,
57
+ WebError.TypeError,
58
+ WebError.TypeMismatchError,
59
+ WebError.NotFoundError,
60
+ ]),
61
+ });
62
+ /**
63
+ * Remove a file-system entry (file or directory) from its parent directory.
64
+ *
65
+ * @param parent - Directory containing the entry.
66
+ * @param name - Entry name.
67
+ * @param options - Removal behavior (for example `{ recursive: true }`).
68
+ *
69
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/removeEntry | MDN Reference}
70
+ */
71
+ const removeEntry = (parent, name, options) => Effect.tryPromise({
72
+ try: () => parent.removeEntry(name, options),
73
+ catch: (u) => WebError.parseWebError(u, [
74
+ WebError.TypeError,
75
+ WebError.NotAllowedError,
76
+ WebError.InvalidModificationError,
77
+ WebError.NotFoundError,
78
+ WebError.NoModificationAllowedError,
79
+ ]),
80
+ });
81
+ /**
82
+ * Return a stream of child file-system handles for a directory.
83
+ *
84
+ * @param directory - Directory whose children are to be streamed
85
+ * @returns `Stream` of `FileSystemHandle`
86
+ *
87
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values | MDN Reference}
88
+ */
89
+ const values = (directory) => Stream.fromAsyncIterable(directory.values(), (u) => WebError.parseWebError(u, [WebError.NotAllowedError, WebError.NotFoundError]));
90
+ /**
91
+ * Resolve the relative path from a parent directory to a descendant handle.
92
+ *
93
+ * @param parent - Reference directory.
94
+ * @param child - File or directory handle within the parent hierarchy.
95
+ * @returns `Option.some(pathSegments)` when reachable, otherwise `Option.none()`.
96
+ *
97
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve | MDN Reference}
98
+ */
99
+ const resolve = (parent, child) => Effect.tryPromise({
100
+ try: () => parent.resolve(child),
101
+ catch: (u) => WebError.parseWebError(u),
102
+ }).pipe(Effect.map((path) => (path === null ? Option.none() : Option.some(path))));
103
+ /**
104
+ * Read the underlying `File` for a file handle.
105
+ *
106
+ * @param handle - Handle referencing the target file.
107
+ *
108
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/getFile | MDN Reference}
109
+ */
110
+ const getFile = (handle) => Effect.tryPromise({
111
+ try: () => handle.getFile(),
112
+ catch: (u) => WebError.parseWebError(u, [WebError.NotAllowedError, WebError.NotFoundError]),
113
+ });
114
+ /**
115
+ * Overwrite the contents of a file with the provided data.
116
+ *
117
+ * @param handle - File to write to.
118
+ * @param data - Chunk(s) accepted by `FileSystemWritableFileStream.write`.
119
+ * @param options - Stream creation options (for example `{ keepExistingData: false }`).
120
+ *
121
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable | MDN Reference}
122
+ */
123
+ const writeFile = (handle, data, options) => Effect.acquireUseRelease(Effect.tryPromise({
124
+ try: () => handle.createWritable(options),
125
+ catch: (u) => WebError.parseWebError(u, [
126
+ WebError.NotAllowedError,
127
+ WebError.NotFoundError,
128
+ WebError.NoModificationAllowedError,
129
+ WebError.AbortError,
130
+ ]),
131
+ }), (stream) => Effect.tryPromise({
132
+ try: () => stream.write(data),
133
+ catch: (u) => WebError.parseWebError(u, [WebError.NotAllowedError, WebError.QuotaExceededError, WebError.TypeError]),
134
+ }), (stream) => Effect.tryPromise({
135
+ try: () => stream.close(),
136
+ catch: (u) => WebError.parseWebError(u, [WebError.TypeError]),
137
+ }).pipe(Effect.orElse(() => Effect.void)));
138
+ /**
139
+ * Append data to the end of an existing file.
140
+ *
141
+ * @param handle - File to extend.
142
+ * @param data - Data to append.
143
+ *
144
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/write | MDN Reference}
145
+ */
146
+ const appendToFile = (handle, data) => Effect.acquireUseRelease(Effect.tryPromise({
147
+ try: () => handle.createWritable({ keepExistingData: true }),
148
+ catch: (u) => WebError.parseWebError(u, [
149
+ WebError.NotAllowedError,
150
+ WebError.NotFoundError,
151
+ WebError.NoModificationAllowedError,
152
+ WebError.AbortError,
153
+ ]),
154
+ }), (stream) => Effect.gen(function* () {
155
+ const file = yield* getFile(handle);
156
+ yield* Effect.tryPromise({
157
+ try: () => stream.seek(file.size),
158
+ catch: (u) => WebError.parseWebError(u, [WebError.NotAllowedError, WebError.TypeError]),
159
+ });
160
+ yield* Effect.tryPromise({
161
+ try: () => stream.write(data),
162
+ catch: (u) => WebError.parseWebError(u, [WebError.NotAllowedError, WebError.QuotaExceededError, WebError.TypeError]),
163
+ });
164
+ }), (stream) => Effect.tryPromise({
165
+ try: () => stream.close(),
166
+ catch: (u) => WebError.parseWebError(u, [WebError.TypeError]),
167
+ }).pipe(Effect.orElse(() => Effect.void)));
168
+ /**
169
+ * Truncate a file to the specified size in bytes.
170
+ *
171
+ * @param handle - File to shrink or pad.
172
+ * @param size - Target byte length.
173
+ *
174
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate | MDN Reference}
175
+ */
176
+ const truncateFile = (handle, size) => Effect.acquireUseRelease(Effect.tryPromise({
177
+ try: () => handle.createWritable({ keepExistingData: true }),
178
+ catch: (u) => WebError.parseWebError(u, [
179
+ WebError.NotAllowedError,
180
+ WebError.NotFoundError,
181
+ WebError.NoModificationAllowedError,
182
+ WebError.AbortError,
183
+ ]),
184
+ }), (stream) => Effect.tryPromise({
185
+ try: () => stream.truncate(size),
186
+ catch: (u) => WebError.parseWebError(u, [WebError.NotAllowedError, WebError.TypeError, WebError.QuotaExceededError]),
187
+ }), (stream) => Effect.tryPromise({
188
+ try: () => stream.close(),
189
+ catch: (u) => WebError.parseWebError(u, [WebError.TypeError]),
190
+ }).pipe(Effect.orElse(() => Effect.void)));
191
+ /**
192
+ * Create a synchronous access handle for a file.
193
+ *
194
+ * @param handle - File handle to open.
195
+ * @returns A managed handle that is automatically closed when released.
196
+ *
197
+ * @remarks
198
+ * - Only available in Dedicated Web Workers.
199
+ * - This method is asynchronous even though the `FileSystemSyncAccessHandle` APIs are synchronous.
200
+ *
201
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle | MDN Reference}
202
+ */
203
+ const createSyncAccessHandle = (handle) => Effect.acquireRelease(Effect.tryPromise({
204
+ try: () => handle.createSyncAccessHandle(),
205
+ catch: (u) => WebError.parseWebError(u, [
206
+ WebError.NotAllowedError,
207
+ WebError.InvalidStateError,
208
+ WebError.NotFoundError,
209
+ WebError.NoModificationAllowedError,
210
+ ]),
211
+ }), (syncHandle) => Effect.sync(() => syncHandle.close()));
212
+ /**
213
+ * Perform a synchronous read into the provided buffer from a sync access handle.
214
+ *
215
+ * @param handle - Sync access handle to read from.
216
+ * @param buffer - Destination buffer (can be a specific view like Uint8Array).
217
+ * @param options - Read position options.
218
+ * @returns Number of bytes read.
219
+ *
220
+ * @remarks
221
+ * Only available in Dedicated Web Workers.
222
+ *
223
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/read | MDN Reference}
224
+ */
225
+ const syncRead = (handle, buffer, options) => Effect.try({
226
+ try: () => handle.read(buffer, options),
227
+ catch: (u) => WebError.parseWebError(u, [WebError.RangeError, WebError.InvalidStateError, WebError.TypeError]),
228
+ });
229
+ /**
230
+ * Perform a synchronous write from the provided buffer into the file.
231
+ *
232
+ * @param handle - Sync access handle to write to.
233
+ * @param buffer - Source data.
234
+ * @param options - Write position options.
235
+ * @returns Number of bytes written.
236
+ *
237
+ * @remarks
238
+ * Only available in Dedicated Web Workers.
239
+ *
240
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/write | MDN Reference}
241
+ */
242
+ const syncWrite = (handle, buffer, options) => Effect.try({
243
+ try: () => handle.write(buffer, options),
244
+ catch: (u) => WebError.parseWebError(u),
245
+ });
246
+ /**
247
+ * Truncate the file associated with a sync access handle to the specified size.
248
+ *
249
+ * @param handle - Sync access handle to mutate.
250
+ * @param size - Desired byte length.
251
+ *
252
+ * @remarks
253
+ * Only available in Dedicated Web Workers.
254
+ *
255
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/truncate | MDN Reference}
256
+ */
257
+ const syncTruncate = (handle, size) => Effect.try({
258
+ try: () => handle.truncate(size),
259
+ catch: (u) => WebError.parseWebError(u),
260
+ });
261
+ /**
262
+ * Retrieve the current size of a file via its sync access handle.
263
+ *
264
+ * @param handle - Sync access handle.
265
+ * @returns File size in bytes.
266
+ *
267
+ * @remarks
268
+ * Only available in Dedicated Web Workers.
269
+ *
270
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/getSize | MDN Reference}
271
+ */
272
+ const syncGetSize = (handle) => Effect.try({
273
+ try: () => handle.getSize(),
274
+ catch: (u) => WebError.parseWebError(u),
275
+ });
276
+ /**
277
+ * Flush pending synchronous writes to durable storage.
278
+ *
279
+ * @param handle - Sync access handle to flush.
280
+ *
281
+ * @remarks
282
+ * Only available in Dedicated Web Workers.
283
+ *
284
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/flush | MDN Reference}
285
+ */
286
+ const syncFlush = (handle) => Effect.try({
287
+ try: () => handle.flush(),
288
+ catch: (u) => WebError.parseWebError(u),
289
+ });
290
+ return {
291
+ getRootDirectoryHandle,
292
+ getFileHandle,
293
+ getDirectoryHandle,
294
+ removeEntry,
295
+ values,
296
+ resolve,
297
+ getFile,
298
+ writeFile,
299
+ appendToFile,
300
+ truncateFile,
301
+ createSyncAccessHandle,
302
+ syncRead,
303
+ syncWrite,
304
+ syncTruncate,
305
+ syncGetSize,
306
+ syncFlush,
307
+ };
308
+ },
309
+ accessors: true,
310
+ }) {
311
+ }
312
+ const notFoundError = new WebError.NotFoundError({
313
+ cause: new DOMException('The object can not be found here.', 'NotFoundError'),
314
+ });
315
+ const unknownError = (message) => new WebError.UnknownError({ description: message });
316
+ /**
317
+ * A no-op Opfs service that can be used for testing.
318
+ */
319
+ export const noopOpfs = new Opfs({
320
+ getRootDirectoryHandle: Effect.fail(unknownError('OPFS is not supported in this environment')),
321
+ getFileHandle: () => Effect.fail(notFoundError),
322
+ getDirectoryHandle: () => Effect.fail(notFoundError),
323
+ removeEntry: () => Effect.fail(notFoundError),
324
+ values: () => Effect.fail(notFoundError),
325
+ resolve: () => Effect.succeed(Option.none()),
326
+ getFile: () => Effect.fail(notFoundError),
327
+ writeFile: () => Effect.fail(notFoundError),
328
+ appendToFile: () => Effect.fail(notFoundError),
329
+ truncateFile: () => Effect.fail(notFoundError),
330
+ createSyncAccessHandle: () => Effect.fail(unknownError('OPFS is not supported in this environment')),
331
+ syncRead: () => Effect.fail(unknownError('OPFS is not supported in this environment')),
332
+ syncWrite: () => Effect.fail(unknownError('OPFS is not supported in this environment')),
333
+ syncTruncate: () => Effect.fail(unknownError('OPFS is not supported in this environment')),
334
+ syncGetSize: () => Effect.fail(unknownError('OPFS is not supported in this environment')),
335
+ syncFlush: () => Effect.fail(unknownError('OPFS is not supported in this environment')),
336
+ });
337
+ /**
338
+ * Error raised when OPFS operations fail.
339
+ */
340
+ export class OpfsError extends Schema.TaggedError()('@livestore/utils/Opfs/Error', {
341
+ message: Schema.String,
342
+ cause: Schema.optional(Schema.Defect),
343
+ }) {
344
+ }
345
+ //# sourceMappingURL=Opfs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Opfs.js","sourceRoot":"","sources":["../../../src/browser/Opfs/Opfs.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvD,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,OAAO,IAAK,SAAQ,MAAM,CAAC,OAAO,EAAQ,CAAC,uBAAuB,EAAE;IACxE,IAAI,EAAE,GAAG,EAAE;QACT;;;;;;WAMG;QACH,MAAM,sBAAsB,GAAG,MAAM,CAAC,UAAU,CAAC;YAC/C,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE;YAC3C,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;SAClE,CAAC,CAAA;QAEF;;;;;;;;WAQG;QACH,MAAM,aAAa,GAAG,CAAC,MAAiC,EAAE,IAAY,EAAE,OAAkC,EAAE,EAAE,CAC5G,MAAM,CAAC,UAAU,CAAC;YAChB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC;YAC9C,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CACX,QAAQ,CAAC,aAAa,CAAC,CAAC,EAAE;gBACxB,QAAQ,CAAC,eAAe;gBACxB,QAAQ,CAAC,SAAS;gBAClB,Q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AAI,CAAC,YAAY,CAAC,2CAA2C,CAAC,CAAC;CACxF,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,MAAM,CAAC,WAAW,EAAa,CAAC,6BAA6B,EAAE;IAC5F,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;CACtC,CAAC;CAAG"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Debug utilities for OPFS (Origin Private File System) inspection and manipulation.
3
+ * These functions are designed for use in browser devtools console to help debug
4
+ * and inspect the OPFS structure during development.
5
+ */
6
+ export declare const debugUtils: {
7
+ /**
8
+ * Print the entire OPFS tree structure to the console in an ASCII format.
9
+ */
10
+ readonly printTree: () => Promise<void>;
11
+ /**
12
+ * Reset the entire OPFS tree by removing all files and directories.
13
+ */
14
+ readonly resetTree: () => Promise<void>;
15
+ /**
16
+ * Get a directory handle for a given path, useful for inspecting or manipulating specific directories.
17
+ */
18
+ readonly getDirHandle: (path: string, options?: FileSystemGetDirectoryOptions) => Promise<FileSystemDirectoryHandle>;
19
+ };
20
+ //# sourceMappingURL=debug-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-utils.d.ts","sourceRoot":"","sources":["../../../src/browser/Opfs/debug-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqIH,eAAO,MAAM,UAAU;IACrB;;OAEG;8BACY,OAAO,CAAC,IAAI,CAAC;IAC5B;;OAEG;8BACY,OAAO,CAAC,IAAI,CAAC;IAC5B;;OAEG;kCACkB,MAAM,YAAY,6BAA6B;CAC5D,CAAA"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Debug utilities for OPFS (Origin Private File System) inspection and manipulation.
3
+ * These functions are designed for use in browser devtools console to help debug
4
+ * and inspect the OPFS structure during development.
5
+ */
6
+ import { Effect, Stream } from 'effect';
7
+ import prettyBytes from 'pretty-bytes';
8
+ import { Opfs } from "./Opfs.js";
9
+ import { getDirectoryHandleByPath, getMetadata, remove } from "./utils.js";
10
+ const ROOT_NAME = '/';
11
+ /**
12
+ * Materialize the entire OPFS tree starting from the origin root.
13
+ */
14
+ const buildTree = Effect.fn('@livestore/utils:Opfs.buildTree')(function* () {
15
+ const rootHandle = yield* Opfs.getRootDirectoryHandle;
16
+ const collectDirectory = (handle, pathSegments) => Effect.gen(function* () {
17
+ const handlesStream = yield* Opfs.values(handle);
18
+ const handles = yield* handlesStream.pipe(Stream.runCollect, Effect.map((chunk) => Array.from(chunk).sort((a, b) => a.name.localeCompare(b.name))));
19
+ const children = yield* Effect.forEach(handles, (childHandle) => Effect.gen(function* () {
20
+ const nextSegments = [...pathSegments, childHandle.name];
21
+ const path = formatPath(nextSegments);
22
+ if (childHandle.kind === 'directory') {
23
+ return yield* collectDirectory(childHandle, nextSegments);
24
+ }
25
+ const metadata = yield* getMetadata(childHandle);
26
+ return {
27
+ metadata: {
28
+ name: childHandle.name,
29
+ path,
30
+ kind: 'file',
31
+ size: metadata.size,
32
+ lastModified: metadata.lastModified,
33
+ },
34
+ };
35
+ }), { concurrency: 'unbounded' });
36
+ return {
37
+ metadata: {
38
+ name: pathSegments.length === 0 ? ROOT_NAME : pathSegments[pathSegments.length - 1],
39
+ path: formatPath(pathSegments),
40
+ kind: 'directory',
41
+ },
42
+ children,
43
+ };
44
+ });
45
+ return yield* collectDirectory(rootHandle, []);
46
+ });
47
+ const formatPath = (segments) => (segments.length === 0 ? ROOT_NAME : `/${segments.join('/')}`);
48
+ const formatLabel = ({ name, kind, size, lastModified }) => {
49
+ let label = name;
50
+ if (kind === 'file' && lastModified !== undefined) {
51
+ const date = new Date(lastModified);
52
+ label += ` │ ${date.toISOString().split('T')[0]} ${date.toTimeString().split(' ')[0]}`;
53
+ if (size !== undefined) {
54
+ label += ` │ ${prettyBytes(size)}`;
55
+ }
56
+ }
57
+ return label;
58
+ };
59
+ const logAsciiTree = (node) => logAsciiNode(node, { prefix: '', isLast: true, isRoot: true });
60
+ const logAsciiNode = (node, options) => Effect.gen(function* () {
61
+ const label = formatLabel(node.metadata);
62
+ const branch = options.isRoot ? '' : `${options.prefix}${options.isLast ? '└── ' : '├── '}`;
63
+ const nextPrefix = options.isRoot ? '' : `${options.prefix}${options.isLast ? ' ' : '│ '}`;
64
+ console.log(`${branch}${label}`);
65
+ if (node.children === undefined || node.children.length === 0)
66
+ return;
67
+ for (let index = 0; index < node.children.length; index++) {
68
+ const child = node.children[index];
69
+ const isLastChild = index === node.children.length - 1;
70
+ yield* logAsciiNode(child, { prefix: nextPrefix, isLast: isLastChild });
71
+ }
72
+ });
73
+ const printTree = Effect.gen(function* () {
74
+ const tree = yield* buildTree();
75
+ yield* logAsciiTree(tree);
76
+ });
77
+ const resetTree = remove('/');
78
+ const getDirHandle = (path, options) => getDirectoryHandleByPath(path, options);
79
+ const runOpfsEffect = (effect) => effect.pipe(Effect.provide(Opfs.Default), Effect.runPromise);
80
+ export const debugUtils = {
81
+ /**
82
+ * Print the entire OPFS tree structure to the console in an ASCII format.
83
+ */
84
+ printTree: () => runOpfsEffect(printTree),
85
+ /**
86
+ * Reset the entire OPFS tree by removing all files and directories.
87
+ */
88
+ resetTree: () => runOpfsEffect(resetTree),
89
+ /**
90
+ * Get a directory handle for a given path, useful for inspecting or manipulating specific directories.
91
+ */
92
+ getDirHandle: (path, options) => runOpfsEffect(getDirHandle(path, options)),
93
+ };
94
+ //# sourceMappingURL=debug-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-utils.js","sourceRoot":"","sources":["../../../src/browser/Opfs/debug-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,EAAE,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';
2
+ export * from './Opfs.ts';
3
+ export * from './utils.ts';
4
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/browser/Opfs/mod.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from "./debug-utils.js";
2
+ export * from "./Opfs.js";
3
+ export * from "./utils.js";
4
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../src/browser/Opfs/mod.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
@@ -0,0 +1,68 @@
1
+ import { Effect } from 'effect';
2
+ import { Opfs, OpfsError } from './Opfs.ts';
3
+ /**
4
+ * Resolve a directory handle using a slash-delimited OPFS path.
5
+ *
6
+ * @param path - Directory path relative to the OPFS root.
7
+ * @param options - Options forwarded to `getDirectoryHandle` when traversing segments.
8
+ * @returns Directory handle for the final segment.
9
+ */
10
+ export declare const getDirectoryHandleByPath: (path: string, options?: FileSystemGetDirectoryOptions | undefined) => Effect.Effect<FileSystemDirectoryHandle, import("../WebError.ts").TypeError | import("../WebError.ts").NotFoundError | import("../WebError.ts").NotAllowedError | import("../WebError.ts").TypeMismatchError | import("../WebError.ts").SecurityError | import("../WebError.ts").UnknownError | OpfsError, Opfs>;
11
+ /**
12
+ * Remove a file or directory identified by an OPFS path.
13
+ *
14
+ * @param path - Slash-delimited path to delete.
15
+ * @param options.recursive - When `true`, recursively delete directory contents; defaults to `false`.
16
+ */
17
+ export declare const remove: (path: string, options?: {
18
+ readonly recursive?: boolean;
19
+ } | undefined) => Effect.Effect<void, import("../WebError.ts").TypeError | import("../WebError.ts").NoModificationAllowedError | import("../WebError.ts").NotFoundError | import("../WebError.ts").NotAllowedError | import("../WebError.ts").TypeMismatchError | import("../WebError.ts").InvalidModificationError | import("../WebError.ts").SecurityError | import("../WebError.ts").UnknownError | OpfsError, Opfs>;
20
+ /**
21
+ * Determine whether a file or directory exists at the given OPFS path.
22
+ *
23
+ * @param path - Slash-delimited path to inspect.
24
+ * @returns `true` if the path resolves to a file or directory, otherwise `false`.
25
+ */
26
+ export declare const exists: (path: string) => Effect.Effect<boolean, import("../WebError.ts").TypeError | import("../WebError.ts").NotAllowedError | import("../WebError.ts").TypeMismatchError | import("../WebError.ts").SecurityError | import("../WebError.ts").UnknownError | OpfsError, Opfs>;
27
+ /**
28
+ * Create a directory at the provided path, optionally creating parents recursively.
29
+ *
30
+ * @param path - Slash-delimited directory path.
31
+ * @param options.recursive - When `true`, create all missing parent segments; defaults to `false`.
32
+ */
33
+ export declare const makeDirectory: (path: string, options?: {
34
+ readonly recursive?: boolean;
35
+ } | undefined) => Effect.Effect<void, import("../WebError.ts").TypeError | import("../WebError.ts").NotFoundError | import("../WebError.ts").NotAllowedError | import("../WebError.ts").TypeMismatchError | import("../WebError.ts").SecurityError | import("../WebError.ts").UnknownError | OpfsError, Opfs>;
36
+ /**
37
+ * Extract basic metadata for a given file handle.
38
+ *
39
+ * @param handle - File handle whose metadata should be read.
40
+ * @returns Object containing name, size, MIME type, and last modification timestamp.
41
+ */
42
+ export declare const getMetadata: (handle: FileSystemFileHandle) => Effect.Effect<{
43
+ name: string;
44
+ size: number;
45
+ type: string;
46
+ lastModified: number;
47
+ }, import("../WebError.ts").NotFoundError | import("../WebError.ts").NotAllowedError | import("../WebError.ts").UnknownError, Opfs>;
48
+ /**
49
+ * Write bytes to an OPFS path, creating or replacing the target file.
50
+ *
51
+ * @param path - Slash-delimited file path.
52
+ * @param data - Bytes to persist.
53
+ */
54
+ export declare const writeFile: (path: string, data: Uint8Array<ArrayBufferLike>) => Effect.Effect<void, import("../WebError.ts").TypeError | import("../WebError.ts").NoModificationAllowedError | import("../WebError.ts").NotFoundError | import("../WebError.ts").NotAllowedError | import("../WebError.ts").TypeMismatchError | import("../WebError.ts").AbortError | import("../WebError.ts").SecurityError | import("../WebError.ts").QuotaExceededError | import("../WebError.ts").UnknownError | OpfsError, Opfs>;
55
+ /**
56
+ * Synchronously write bytes to the target file handle, truncating any existing content.
57
+ *
58
+ * @param handle - Sync access handle to overwrite.
59
+ * @param buffer - Raw data to persist.
60
+ * @returns Effect that resolves once every byte is flushed to durable storage.
61
+ *
62
+ * @remarks
63
+ * - Only available in Dedicated Web Workers.
64
+ * - Crash safety: not atomic. A crash mid-write can leave the file truncated or partially written.
65
+ * For atomic replacement, prefer `writeFile` or a temp-file pattern with two prepared handles.
66
+ */
67
+ export declare const syncWriteFile: (handle: FileSystemSyncAccessHandle, buffer: AllowSharedBufferSource) => Effect.Effect<undefined, import("../WebError.ts").WebError | OpfsError, Opfs>;
68
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/browser/Opfs/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAoG3C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,yXAQnC,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,MAAM;yBAEgB,OAAO;uZAkBxC,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,MAAM,yQAiBjB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa;yBAES,OAAO;6SASxC,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;;mIAStB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,4dAoBpB,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,wJAsBxB,CAAA"}