@livestore/utils 0.4.0-dev.17 → 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.
- package/dist/.tsbuildinfo.json +1 -1
- package/dist/browser/Opfs/Opfs.d.ts +51 -0
- package/dist/browser/Opfs/Opfs.d.ts.map +1 -0
- package/dist/browser/Opfs/Opfs.js +345 -0
- package/dist/browser/Opfs/Opfs.js.map +1 -0
- package/dist/browser/Opfs/debug-utils.d.ts +20 -0
- package/dist/browser/Opfs/debug-utils.d.ts.map +1 -0
- package/dist/browser/Opfs/debug-utils.js +94 -0
- package/dist/browser/Opfs/debug-utils.js.map +1 -0
- package/dist/browser/Opfs/mod.d.ts +4 -0
- package/dist/browser/Opfs/mod.d.ts.map +1 -0
- package/dist/browser/Opfs/mod.js +4 -0
- package/dist/browser/Opfs/mod.js.map +1 -0
- package/dist/browser/Opfs/utils.d.ts +68 -0
- package/dist/browser/Opfs/utils.d.ts.map +1 -0
- package/dist/browser/Opfs/utils.js +206 -0
- package/dist/browser/Opfs/utils.js.map +1 -0
- package/dist/browser/QuotaExceededError.d.ts +59 -0
- package/dist/browser/QuotaExceededError.d.ts.map +1 -0
- package/dist/browser/QuotaExceededError.js +2 -0
- package/dist/browser/QuotaExceededError.js.map +1 -0
- package/dist/browser/WebChannelBrowser.d.ts +22 -0
- package/dist/browser/WebChannelBrowser.d.ts.map +1 -0
- package/dist/browser/WebChannelBrowser.js +76 -0
- package/dist/browser/WebChannelBrowser.js.map +1 -0
- package/dist/browser/WebError.d.ts +425 -0
- package/dist/browser/WebError.d.ts.map +1 -0
- package/dist/browser/WebError.js +414 -0
- package/dist/browser/WebError.js.map +1 -0
- package/dist/browser/WebError.test.d.ts +2 -0
- package/dist/browser/WebError.test.d.ts.map +1 -0
- package/dist/browser/WebError.test.js +46 -0
- package/dist/browser/WebError.test.js.map +1 -0
- package/dist/browser/WebLock.d.ts.map +1 -0
- package/dist/browser/WebLock.js.map +1 -0
- package/dist/{browser.d.ts → browser/detect.d.ts} +1 -1
- package/dist/browser/detect.d.ts.map +1 -0
- package/dist/{browser.js → browser/detect.js} +1 -1
- package/dist/browser/detect.js.map +1 -0
- package/dist/browser/mod.d.ts +8 -0
- package/dist/browser/mod.d.ts.map +1 -0
- package/dist/browser/mod.js +8 -0
- package/dist/browser/mod.js.map +1 -0
- package/dist/effect/WebChannel/WebChannel.d.ts +2 -21
- package/dist/effect/WebChannel/WebChannel.d.ts.map +1 -1
- package/dist/effect/WebChannel/WebChannel.js +3 -75
- package/dist/effect/WebChannel/WebChannel.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.test.js +1 -1
- package/dist/effect/WebChannel/WebChannel.test.js.map +1 -1
- package/dist/effect/{index.d.ts → mod.d.ts} +2 -4
- package/dist/effect/mod.d.ts.map +1 -0
- package/dist/effect/{index.js → mod.js} +2 -4
- package/dist/effect/mod.js.map +1 -0
- package/dist/mod.d.ts +1 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +1 -1
- package/dist/node/mod.d.ts +1 -1
- package/dist/node/mod.d.ts.map +1 -1
- package/dist/node/mod.js +1 -1
- package/dist/node/mod.js.map +1 -1
- package/package.json +27 -19
- package/src/browser/Opfs/Opfs.ts +428 -0
- package/src/browser/Opfs/debug-utils.ts +151 -0
- package/src/browser/Opfs/mod.ts +3 -0
- package/src/browser/Opfs/utils.ts +270 -0
- package/src/browser/QuotaExceededError.ts +59 -0
- package/src/browser/WebChannelBrowser.ts +131 -0
- package/src/browser/WebError.test.ts +66 -0
- package/src/browser/WebError.ts +599 -0
- package/src/browser/mod.ts +8 -0
- package/src/effect/WebChannel/WebChannel.test.ts +1 -1
- package/src/effect/WebChannel/WebChannel.ts +11 -127
- package/src/effect/{index.ts → mod.ts} +1 -2
- package/src/mod.ts +1 -1
- package/src/node/mod.ts +1 -1
- package/dist/browser.d.ts.map +0 -1
- package/dist/browser.js.map +0 -1
- package/dist/effect/WebLock.d.ts.map +0 -1
- package/dist/effect/WebLock.js.map +0 -1
- package/dist/effect/index.d.ts.map +0 -1
- package/dist/effect/index.js.map +0 -1
- /package/dist/{effect → browser}/WebLock.d.ts +0 -0
- /package/dist/{effect → browser}/WebLock.js +0 -0
- /package/src/{effect → browser}/WebLock.ts +0 -0
- /package/src/{browser.ts → browser/detect.ts} +0 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import './QuotaExceededError.ts';
|
|
2
|
+
import { Schema } from 'effect';
|
|
3
|
+
/**
|
|
4
|
+
* Unique identifier for web errors.
|
|
5
|
+
*/
|
|
6
|
+
export declare const TypeId = "@livestore/utils/WebError";
|
|
7
|
+
/**
|
|
8
|
+
* Type-level representation of the web error identifier.
|
|
9
|
+
*/
|
|
10
|
+
export type TypeId = typeof TypeId;
|
|
11
|
+
/**
|
|
12
|
+
* Type guard to check if a value is a web error.
|
|
13
|
+
*
|
|
14
|
+
* @param u - The value to check
|
|
15
|
+
* @returns `true` if the value is an `WebError`, `false` otherwise
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { WebError } from "@livestore/utils/effect"
|
|
20
|
+
*
|
|
21
|
+
* const someError = new Error("generic error")
|
|
22
|
+
* const webError = new WebError.UnknownError({
|
|
23
|
+
* module: "Test",
|
|
24
|
+
* method: "example"
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* console.log(WebError.isWebError(someError)) // false
|
|
28
|
+
* console.log(WebError.isWebError(webError)) // true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const isWebError: (u: unknown) => u is WebError;
|
|
32
|
+
declare const EvalError_base: Schema.TaggedErrorClass<EvalError, "@livestore/utils/Web/EvalError", {
|
|
33
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/EvalError">;
|
|
34
|
+
} & {
|
|
35
|
+
cause: Schema.instanceOf<Error>;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Error for the web standard "EvalError" simple exception.
|
|
39
|
+
*
|
|
40
|
+
* Thrown when the `eval` function is used in a way that violates its usage restrictions.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Evalerror | MDN Reference}
|
|
43
|
+
* @see {@link https://webidl.spec.whatwg.org/#exceptiondef-evalerror | Specification}
|
|
44
|
+
*/
|
|
45
|
+
export declare class EvalError extends EvalError_base {
|
|
46
|
+
readonly [TypeId]: TypeId;
|
|
47
|
+
}
|
|
48
|
+
declare const RangeError_base: Schema.TaggedErrorClass<RangeError, "@livestore/utils/Web/RangeError", {
|
|
49
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/RangeError">;
|
|
50
|
+
} & {
|
|
51
|
+
cause: Schema.instanceOf<Error>;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Error for the web standard "RangeError" simple exception.
|
|
55
|
+
*
|
|
56
|
+
* Indicates that a numeric value is outside the permitted range.
|
|
57
|
+
*
|
|
58
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Rangeerror | MDN Reference}
|
|
59
|
+
* @see {@link https://webidl.spec.whatwg.org/#exceptiondef-rangeerror | Specification}
|
|
60
|
+
*/
|
|
61
|
+
export declare class RangeError extends RangeError_base {
|
|
62
|
+
readonly [TypeId]: TypeId;
|
|
63
|
+
}
|
|
64
|
+
declare const ReferenceError_base: Schema.TaggedErrorClass<ReferenceError, "@livestore/utils/Web/ReferenceError", {
|
|
65
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/ReferenceError">;
|
|
66
|
+
} & {
|
|
67
|
+
cause: Schema.instanceOf<Error>;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Error for the web standard "ReferenceError" simple exception.
|
|
71
|
+
*
|
|
72
|
+
* Raised when code references an identifier that has not been defined.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Referenceerror | MDN Reference}
|
|
75
|
+
* @see {@link https://webidl.spec.whatwg.org/#exceptiondef-referenceerror | Specification}
|
|
76
|
+
*/
|
|
77
|
+
export declare class ReferenceError extends ReferenceError_base {
|
|
78
|
+
readonly [TypeId]: TypeId;
|
|
79
|
+
}
|
|
80
|
+
declare const TypeError_base: Schema.TaggedErrorClass<TypeError, "@livestore/utils/Web/TypeError", {
|
|
81
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/TypeError">;
|
|
82
|
+
} & {
|
|
83
|
+
cause: Schema.instanceOf<Error>;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Error for the web standard "TypeError" simple exception.
|
|
87
|
+
*
|
|
88
|
+
* Occurs when an operation is applied to a value of an inappropriate type.
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Typeerror | MDN Reference}
|
|
91
|
+
* @see {@link https://webidl.spec.whatwg.org/#exceptiondef-typeerror | Specification}
|
|
92
|
+
*/
|
|
93
|
+
export declare class TypeError extends TypeError_base {
|
|
94
|
+
readonly [TypeId]: TypeId;
|
|
95
|
+
}
|
|
96
|
+
declare const URIError_base: Schema.TaggedErrorClass<URIError, "@livestore/utils/Web/URIError", {
|
|
97
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/URIError">;
|
|
98
|
+
} & {
|
|
99
|
+
cause: Schema.instanceOf<Error>;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Error for the web standard "URIError" simple exception.
|
|
103
|
+
*
|
|
104
|
+
* Signals incorrect usage of global URI handling functions such as `decodeURI` or `encodeURI`.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIerror | MDN Reference}
|
|
107
|
+
* @see {@link https://webidl.spec.whatwg.org/#exceptiondef-urierror | Specification}
|
|
108
|
+
*/
|
|
109
|
+
export declare class URIError extends URIError_base {
|
|
110
|
+
readonly [TypeId]: TypeId;
|
|
111
|
+
}
|
|
112
|
+
declare const QuotaExceededError_base: Schema.TaggedErrorClass<QuotaExceededError, "@livestore/utils/Web/QuotaExceededError", {
|
|
113
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/QuotaExceededError">;
|
|
114
|
+
} & {
|
|
115
|
+
cause: Schema.Union<[Schema.instanceOf<globalThis.QuotaExceededError> | typeof Schema.Never, Schema.filter<Schema.instanceOf<DOMException>>]>;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Error for the web standard "QuotaExceededError" DOMException-derived error.
|
|
119
|
+
*
|
|
120
|
+
* The quota has been exceeded.
|
|
121
|
+
*
|
|
122
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/QuotaExceededError | MDN Reference}
|
|
123
|
+
* @see {@link https://webidl.spec.whatwg.org/#quotaexceedederror | Specification}
|
|
124
|
+
*/
|
|
125
|
+
export declare class QuotaExceededError extends QuotaExceededError_base {
|
|
126
|
+
readonly [TypeId]: TypeId;
|
|
127
|
+
get message(): string;
|
|
128
|
+
}
|
|
129
|
+
declare const NoModificationAllowedError_base: Schema.TaggedErrorClass<NoModificationAllowedError, "@livestore/utils/Web/NoModificationAllowedError", {
|
|
130
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/NoModificationAllowedError">;
|
|
131
|
+
} & {
|
|
132
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* Error for the web standard "NoModificationAllowedError" DOMException.
|
|
136
|
+
*
|
|
137
|
+
* The object can not be modified.
|
|
138
|
+
*
|
|
139
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#nomodificationallowederror | MDN Reference}
|
|
140
|
+
* @see {@link https://webidl.spec.whatwg.org/#nomodificationallowederror | Specification}
|
|
141
|
+
*/
|
|
142
|
+
export declare class NoModificationAllowedError extends NoModificationAllowedError_base {
|
|
143
|
+
readonly [TypeId]: TypeId;
|
|
144
|
+
get message(): string;
|
|
145
|
+
}
|
|
146
|
+
declare const NotFoundError_base: Schema.TaggedErrorClass<NotFoundError, "@livestore/utils/Web/NotFoundError", {
|
|
147
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/NotFoundError">;
|
|
148
|
+
} & {
|
|
149
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Error for the web standard "NotFoundError" DOMException
|
|
153
|
+
*
|
|
154
|
+
* The object can not be found here.
|
|
155
|
+
*
|
|
156
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#notfounderror | MDN Reference}
|
|
157
|
+
* @see {@link https://webidl.spec.whatwg.org/#notfounderror | Specification}
|
|
158
|
+
*/
|
|
159
|
+
export declare class NotFoundError extends NotFoundError_base {
|
|
160
|
+
readonly [TypeId]: TypeId;
|
|
161
|
+
get message(): string;
|
|
162
|
+
}
|
|
163
|
+
declare const NotAllowedError_base: Schema.TaggedErrorClass<NotAllowedError, "@livestore/utils/Web/NotAllowedError", {
|
|
164
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/NotAllowedError">;
|
|
165
|
+
} & {
|
|
166
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Error for the web standard "NotAllowedError" DOMException
|
|
170
|
+
*
|
|
171
|
+
* The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
|
|
172
|
+
*
|
|
173
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#notallowederror | MDN Reference}
|
|
174
|
+
* @see {@link https://webidl.spec.whatwg.org/#notallowederror | Specification}
|
|
175
|
+
*/
|
|
176
|
+
export declare class NotAllowedError extends NotAllowedError_base {
|
|
177
|
+
readonly [TypeId]: TypeId;
|
|
178
|
+
get message(): string;
|
|
179
|
+
}
|
|
180
|
+
declare const TypeMismatchError_base: Schema.TaggedErrorClass<TypeMismatchError, "@livestore/utils/Web/TypeMismatchError", {
|
|
181
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/TypeMismatchError">;
|
|
182
|
+
} & {
|
|
183
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
184
|
+
}>;
|
|
185
|
+
/**
|
|
186
|
+
* Error for the web standard "TypeMismatchError" DOMException.
|
|
187
|
+
*
|
|
188
|
+
* The object can not be converted to the expected type.
|
|
189
|
+
*
|
|
190
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#typemismatcherror | MDN Reference}
|
|
191
|
+
* @see {@link https://webidl.spec.whatwg.org/#typemismatcherror | Specification}
|
|
192
|
+
*/
|
|
193
|
+
export declare class TypeMismatchError extends TypeMismatchError_base {
|
|
194
|
+
readonly [TypeId]: TypeId;
|
|
195
|
+
get message(): string;
|
|
196
|
+
}
|
|
197
|
+
declare const InvalidStateError_base: Schema.TaggedErrorClass<InvalidStateError, "@livestore/utils/Web/InvalidStateError", {
|
|
198
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/InvalidStateError">;
|
|
199
|
+
} & {
|
|
200
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
201
|
+
}>;
|
|
202
|
+
/**
|
|
203
|
+
* Error for the web standard "InvalidStateError" DOMException.
|
|
204
|
+
*
|
|
205
|
+
* The object is in an invalid state.
|
|
206
|
+
*
|
|
207
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#invalidstateerror | MDN Reference}
|
|
208
|
+
* @see {@link https://webidl.spec.whatwg.org/#invalidstateerror | Specification}
|
|
209
|
+
*/
|
|
210
|
+
export declare class InvalidStateError extends InvalidStateError_base {
|
|
211
|
+
readonly [TypeId]: TypeId;
|
|
212
|
+
get message(): string;
|
|
213
|
+
}
|
|
214
|
+
declare const AbortError_base: Schema.TaggedErrorClass<AbortError, "@livestore/utils/Web/AbortError", {
|
|
215
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/AbortError">;
|
|
216
|
+
} & {
|
|
217
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
218
|
+
}>;
|
|
219
|
+
/**
|
|
220
|
+
* Error for the web standard "AbortError" DOMException.
|
|
221
|
+
*
|
|
222
|
+
* The operation was aborted.
|
|
223
|
+
*
|
|
224
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#aborterror | MDN Reference}
|
|
225
|
+
* @see {@link https://webidl.spec.whatwg.org/#aborterror | Specification}
|
|
226
|
+
*/
|
|
227
|
+
export declare class AbortError extends AbortError_base {
|
|
228
|
+
readonly [TypeId]: TypeId;
|
|
229
|
+
get message(): string;
|
|
230
|
+
}
|
|
231
|
+
declare const InvalidModificationError_base: Schema.TaggedErrorClass<InvalidModificationError, "@livestore/utils/Web/InvalidModificationError", {
|
|
232
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/InvalidModificationError">;
|
|
233
|
+
} & {
|
|
234
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
235
|
+
}>;
|
|
236
|
+
/**
|
|
237
|
+
* Error for the web standard "InvalidModificationError" DOMException.
|
|
238
|
+
*
|
|
239
|
+
* The object can not be modified in this way.
|
|
240
|
+
*
|
|
241
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#invalidmodificationerror | MDN Reference}
|
|
242
|
+
* @see {@link https://webidl.spec.whatwg.org/#invalidmodificationerror | Specification}
|
|
243
|
+
*/
|
|
244
|
+
export declare class InvalidModificationError extends InvalidModificationError_base {
|
|
245
|
+
readonly [TypeId]: TypeId;
|
|
246
|
+
get message(): string;
|
|
247
|
+
}
|
|
248
|
+
declare const SecurityError_base: Schema.TaggedErrorClass<SecurityError, "@livestore/utils/Web/SecurityError", {
|
|
249
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/SecurityError">;
|
|
250
|
+
} & {
|
|
251
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
252
|
+
}>;
|
|
253
|
+
/**
|
|
254
|
+
* Error for the web standard "SecurityError" DOMException.
|
|
255
|
+
*
|
|
256
|
+
* The operation is insecure.
|
|
257
|
+
*
|
|
258
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#securityerror | MDN Reference}
|
|
259
|
+
* @see {@link https://webidl.spec.whatwg.org/#securityerror | Specification}
|
|
260
|
+
*/
|
|
261
|
+
export declare class SecurityError extends SecurityError_base {
|
|
262
|
+
readonly [TypeId]: TypeId;
|
|
263
|
+
get message(): string;
|
|
264
|
+
}
|
|
265
|
+
declare const DataCloneError_base: Schema.TaggedErrorClass<DataCloneError, "@livestore/utils/Web/DataCloneError", {
|
|
266
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/DataCloneError">;
|
|
267
|
+
} & {
|
|
268
|
+
cause: Schema.filter<Schema.instanceOf<DOMException>>;
|
|
269
|
+
}>;
|
|
270
|
+
/**
|
|
271
|
+
* Error for the web standard "DataCloneError" DOMException.
|
|
272
|
+
*
|
|
273
|
+
* The object can not be cloned.
|
|
274
|
+
*
|
|
275
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/DOMException#datacloneerror | MDN Reference}
|
|
276
|
+
* @see {@link https://webidl.spec.whatwg.org/#datacloneerror | Specification}
|
|
277
|
+
*/
|
|
278
|
+
export declare class DataCloneError extends DataCloneError_base {
|
|
279
|
+
readonly [TypeId]: TypeId;
|
|
280
|
+
get message(): string;
|
|
281
|
+
}
|
|
282
|
+
declare const UnknownError_base: Schema.TaggedErrorClass<UnknownError, "@livestore/utils/Web/UnknownError", {
|
|
283
|
+
readonly _tag: Schema.tag<"@livestore/utils/Web/UnknownError">;
|
|
284
|
+
} & {
|
|
285
|
+
module: Schema.optional<typeof Schema.String>;
|
|
286
|
+
method: Schema.optional<typeof Schema.String>;
|
|
287
|
+
description: Schema.optional<typeof Schema.String>;
|
|
288
|
+
cause: Schema.optional<typeof Schema.Defect>;
|
|
289
|
+
}>;
|
|
290
|
+
/**
|
|
291
|
+
* Catch-all error for unexpected runtime errors in web environments.
|
|
292
|
+
*
|
|
293
|
+
* This error is used when an unexpected exception occurs that doesn't fit
|
|
294
|
+
* into the other specific error categories. It provides context about where
|
|
295
|
+
* the error occurred and preserves the original cause for debugging.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* import { WebError } from "@livestore/utils/effect"
|
|
300
|
+
* import { Effect } from "effect"
|
|
301
|
+
*
|
|
302
|
+
* const riskyOperation = () => {
|
|
303
|
+
* try {
|
|
304
|
+
* // Some operation that might throw
|
|
305
|
+
* throw new Error("Unexpected runtime issue")
|
|
306
|
+
* } catch (cause) {
|
|
307
|
+
* return Effect.fail(new WebError.UnknownError({
|
|
308
|
+
* module: "JSON",
|
|
309
|
+
* method: "parse",
|
|
310
|
+
* description: "Could not parse string as JSON",
|
|
311
|
+
* cause
|
|
312
|
+
* }))
|
|
313
|
+
* }
|
|
314
|
+
* }
|
|
315
|
+
*
|
|
316
|
+
* const program = riskyOperation().pipe(
|
|
317
|
+
* Effect.catchTag("@livestore/utils/Web/UnknownError", (error) => {
|
|
318
|
+
* console.log(error.message)
|
|
319
|
+
* // "JSON.parse: Could not parse string as JSON"
|
|
320
|
+
* return Effect.succeed("JSON parsing not possible")
|
|
321
|
+
* })
|
|
322
|
+
* )
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
export declare class UnknownError extends UnknownError_base {
|
|
326
|
+
readonly [TypeId]: TypeId;
|
|
327
|
+
get message(): string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Union type representing all possible web errors.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```ts
|
|
334
|
+
* import { WebError } from "@livestore/utils/effect"
|
|
335
|
+
* import { Effect, Match } from "effect"
|
|
336
|
+
*
|
|
337
|
+
* const handleAnyWebError = Match.type<WebError.WebError>().pipe(
|
|
338
|
+
* Match.tag("NotFoundError", (err) =>
|
|
339
|
+
* `Not found error: ${err.cause.message}`
|
|
340
|
+
* ),
|
|
341
|
+
* Match.tag("TypeError", (err) =>
|
|
342
|
+
* `Type error: ${err.cause.message}`
|
|
343
|
+
* ),
|
|
344
|
+
* Match.orElse((err) =>
|
|
345
|
+
* `Unknown error: ${err.message}`
|
|
346
|
+
* )
|
|
347
|
+
* )
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export type WebError = EvalError | RangeError | ReferenceError | TypeError | URIError | NoModificationAllowedError | NotFoundError | NotAllowedError | TypeMismatchError | InvalidStateError | AbortError | InvalidModificationError | SecurityError | DataCloneError | QuotaExceededError | UnknownError;
|
|
351
|
+
/**
|
|
352
|
+
* Schema for validating and parsing web errors.
|
|
353
|
+
*
|
|
354
|
+
* This schema can be used to decode unknown values into properly typed web
|
|
355
|
+
* errors, ensuring type safety when handling errors from external sources or
|
|
356
|
+
* serialized data.
|
|
357
|
+
*/
|
|
358
|
+
export declare const WebError: Schema.Union<[
|
|
359
|
+
typeof EvalError,
|
|
360
|
+
typeof RangeError,
|
|
361
|
+
typeof ReferenceError,
|
|
362
|
+
typeof TypeError,
|
|
363
|
+
typeof URIError,
|
|
364
|
+
typeof QuotaExceededError,
|
|
365
|
+
typeof NoModificationAllowedError,
|
|
366
|
+
typeof NotFoundError,
|
|
367
|
+
typeof NotAllowedError,
|
|
368
|
+
typeof TypeMismatchError,
|
|
369
|
+
typeof InvalidStateError,
|
|
370
|
+
typeof AbortError,
|
|
371
|
+
typeof InvalidModificationError,
|
|
372
|
+
typeof SecurityError,
|
|
373
|
+
typeof DataCloneError,
|
|
374
|
+
typeof UnknownError
|
|
375
|
+
]>;
|
|
376
|
+
/**
|
|
377
|
+
* Constructor type for any `WebError` variant exposed by the schema union.
|
|
378
|
+
*
|
|
379
|
+
* Useful when constraining APIs (e.g. `parseWebError`) to accept only
|
|
380
|
+
* specific web error constructors while preserving their instance types.
|
|
381
|
+
*/
|
|
382
|
+
type WebErrorConstructor = (typeof WebError.members)[number];
|
|
383
|
+
/**
|
|
384
|
+
* Parses an unknown value into a typed WebError instance.
|
|
385
|
+
*
|
|
386
|
+
* This function safely attempts to parse the provided value into one of the
|
|
387
|
+
* known WebError types. If the value does not match any known type, it
|
|
388
|
+
* defaults to return an `UnknownError` that encapsulates the value and
|
|
389
|
+
* the original error information.
|
|
390
|
+
*
|
|
391
|
+
* @param value - The unknown value to parse
|
|
392
|
+
* @param expected - The errors we expect to receive. Can be used to narrow the return type.
|
|
393
|
+
* @returns A union of the WebError instance. UnknownError is always included in the union
|
|
394
|
+
* as a fallback when the specific error type cannot be determined.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* import { WebError } from "@livestore/utils/effect"
|
|
399
|
+
*
|
|
400
|
+
* // ┌─── Effect<PermissionStatus, WebError.InvalidStateError | WebError.TypeError | WebError.UnknownError>
|
|
401
|
+
* // ▼
|
|
402
|
+
* const permissionStatus = Effect.tryPromise({
|
|
403
|
+
* try: () => navigator.permissions.query({ name: 'geolocation' }),
|
|
404
|
+
* catch: (u) => WebError.parseWebError(u, [WebError.InvalidStateError, WebError.TypeError]),
|
|
405
|
+
* })
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* Passing specific expected errors narrows the return type
|
|
410
|
+
* ```ts
|
|
411
|
+
* const specificError = WebError.parseWebError(error, [WebError.InvalidStateError, WebError.TypeError])
|
|
412
|
+
* // specificError is typed as WebError.InvalidStateError | WebError.TypeError | WebError.UnknownError
|
|
413
|
+
* ```
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* Without additional arguments the full union type is returned
|
|
417
|
+
* ```ts
|
|
418
|
+
* const anyError = WebError.parseWebError(error)
|
|
419
|
+
* // anyError is typed as WebError (all possible error types)
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
export declare function parseWebError(value: unknown): WebError;
|
|
423
|
+
export declare function parseWebError<BECs extends readonly WebErrorConstructor[]>(value: unknown, expected: BECs): InstanceType<BECs[number]> | UnknownError;
|
|
424
|
+
export {};
|
|
425
|
+
//# sourceMappingURL=WebError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebError.d.ts","sourceRoot":"","sources":["../../src/browser/WebError.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA;AAChC,OAAO,EAAkC,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/D;;GAEG;AACH,eAAO,MAAM,MAAM,8BAA8B,CAAA;AAEjD;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAA;AAElC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,QAA4C,CAAA;;;;;;AASzF;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,cAE7B;IACA,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAS;CACnC;;;;;;AAED;;;;;;;GAOG;AACH,qBAAa,UAAW,SAAQ,eAE9B;IACA,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAS;CACnC;;;;;;AAED;;;;;;;GAOG;AACH,qBAAa,cAAe,SAAQ,mBAElC;IACA,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAS;CACnC;;;;;;AAED;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,cAE7B;IACA,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAS;CACnC;;;;;;AAED;;;;;;;GAOG;AACH,qBAAa,QAAS,SAAQ,aAE5B;IACA,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAS;CACnC;;;;;;AAoBD;;;;;;;GAOG;AACH,qBAAa,kBAAmB,SAAQ,u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