@evolu/common 6.0.1-preview.25 → 6.0.1-preview.27
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/src/Assert.d.ts +0 -13
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +0 -15
- package/dist/src/Cache.d.ts +44 -0
- package/dist/src/Cache.d.ts.map +1 -0
- package/dist/src/Cache.js +52 -0
- package/dist/src/Evolu/Db.d.ts +6 -6
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +4 -0
- package/dist/src/Evolu/LocalAuth.d.ts +4 -6
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -1
- package/dist/src/Evolu/LocalAuth.js +14 -15
- package/dist/src/Evolu/Owner.d.ts +116 -86
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +48 -45
- package/dist/src/Evolu/Relay.d.ts +6 -5
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +40 -39
- package/dist/src/Evolu/Storage.d.ts +6 -11
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +30 -9
- package/dist/src/Evolu/Sync.d.ts +5 -5
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +3 -5
- package/dist/src/Evolu/Timestamp.d.ts +24 -0
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +24 -0
- package/dist/src/Identicon.d.ts +35 -0
- package/dist/src/Identicon.d.ts.map +1 -0
- package/dist/src/Identicon.js +143 -0
- package/dist/src/ManyToManyMap.d.ts +0 -3
- package/dist/src/ManyToManyMap.d.ts.map +1 -1
- package/dist/src/Platform.d.ts +20 -0
- package/dist/src/Platform.d.ts.map +1 -0
- package/dist/src/Platform.js +22 -0
- package/dist/src/Result.d.ts +13 -6
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Sqlite.d.ts +36 -1
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +56 -3
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +36 -0
- package/dist/src/Type.d.ts +5 -8
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +11 -11
- package/dist/src/Types.d.ts +1 -1
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +2 -7
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -0
- package/package.json +1 -1
- package/src/Assert.ts +0 -19
- package/src/Cache.ts +85 -0
- package/src/Evolu/Db.ts +11 -7
- package/src/Evolu/LocalAuth.ts +35 -22
- package/src/Evolu/Owner.ts +140 -103
- package/src/Evolu/Relay.ts +52 -48
- package/src/Evolu/Storage.ts +47 -23
- package/src/Evolu/Sync.ts +11 -12
- package/src/Evolu/Timestamp.ts +24 -0
- package/src/Identicon.ts +197 -0
- package/src/ManyToManyMap.ts +0 -3
- package/src/Platform.ts +26 -0
- package/src/Result.ts +13 -6
- package/src/Sqlite.ts +68 -5
- package/src/Task.ts +41 -0
- package/src/Type.ts +12 -15
- package/src/Types.ts +1 -1
- package/src/WebSocket.ts +6 -10
- package/src/index.ts +3 -0
package/src/Task.ts
CHANGED
|
@@ -216,6 +216,32 @@ const isAbortError = (error: unknown): error is AbortError =>
|
|
|
216
216
|
error !== null &&
|
|
217
217
|
(error as { type?: unknown }).type === "AbortError";
|
|
218
218
|
|
|
219
|
+
// For React Native
|
|
220
|
+
if (typeof AbortSignal.any !== "function") {
|
|
221
|
+
AbortSignal.any = function (signals: Array<AbortSignal>): AbortSignal {
|
|
222
|
+
const controller = new AbortController();
|
|
223
|
+
|
|
224
|
+
const onAbort = (event: Event) => {
|
|
225
|
+
controller.abort((event.target as AbortSignal).reason);
|
|
226
|
+
cleanup();
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const cleanup = () => {
|
|
230
|
+
for (const s of signals) s.removeEventListener("abort", onAbort);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
for (const s of signals) {
|
|
234
|
+
if (s.aborted) {
|
|
235
|
+
controller.abort(s.reason);
|
|
236
|
+
return controller.signal;
|
|
237
|
+
}
|
|
238
|
+
s.addEventListener("abort", onAbort);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return controller.signal;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
219
245
|
/**
|
|
220
246
|
* Combines user signal from context with an internal signal.
|
|
221
247
|
*
|
|
@@ -304,6 +330,21 @@ export const toTask = <T, E>(
|
|
|
304
330
|
]);
|
|
305
331
|
}) as Task<T, E>;
|
|
306
332
|
|
|
333
|
+
// For React Native
|
|
334
|
+
if (typeof AbortSignal.timeout !== "function") {
|
|
335
|
+
AbortSignal.timeout = function (ms: number): AbortSignal {
|
|
336
|
+
const controller = new AbortController();
|
|
337
|
+
const id = setTimeout(() => {
|
|
338
|
+
controller.abort();
|
|
339
|
+
}, ms);
|
|
340
|
+
// clear timeout if aborted early
|
|
341
|
+
controller.signal.addEventListener("abort", () => {
|
|
342
|
+
clearTimeout(id);
|
|
343
|
+
});
|
|
344
|
+
return controller.signal;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
307
348
|
/**
|
|
308
349
|
* Creates a {@link Task} that waits for the specified duration.
|
|
309
350
|
*
|
package/src/Type.ts
CHANGED
|
@@ -182,6 +182,7 @@ import { pack } from "msgpackr";
|
|
|
182
182
|
import type { Brand } from "./Brand.js";
|
|
183
183
|
import { type RandomBytesDep } from "./Crypto.js";
|
|
184
184
|
import { isPlainObject } from "./Object.js";
|
|
185
|
+
import { hasNodeBuffer } from "./Platform.js";
|
|
185
186
|
import { err, getOrNull, getOrThrow, ok, Result, trySync } from "./Result.js";
|
|
186
187
|
import { safelyStringifyUnknownValue } from "./String.js";
|
|
187
188
|
import type { Literal, Simplify, WidenLiteral } from "./Types.js";
|
|
@@ -253,7 +254,6 @@ export interface Type<
|
|
|
253
254
|
*
|
|
254
255
|
* - When you need to convert a validation result to a nullable value
|
|
255
256
|
* - When the error is not important and you just want the value or nothing
|
|
256
|
-
* - APIs that expect `T | null`
|
|
257
257
|
*
|
|
258
258
|
* ### Example
|
|
259
259
|
*
|
|
@@ -370,8 +370,6 @@ export interface Type<
|
|
|
370
370
|
readonly ParentError: ParentError;
|
|
371
371
|
|
|
372
372
|
/**
|
|
373
|
-
* Error | ParentError
|
|
374
|
-
*
|
|
375
373
|
* ### Example
|
|
376
374
|
*
|
|
377
375
|
* ```ts
|
|
@@ -461,7 +459,7 @@ export type InferParentError<A extends AnyType> =
|
|
|
461
459
|
: never;
|
|
462
460
|
|
|
463
461
|
/**
|
|
464
|
-
* Extracts all error types
|
|
462
|
+
* Extracts all error types from a {@link Type}.
|
|
465
463
|
*
|
|
466
464
|
* @category Utilities
|
|
467
465
|
*/
|
|
@@ -1150,7 +1148,7 @@ export const trimmed: BrandFactory<"Trimmed", string, TrimmedError> = (
|
|
|
1150
1148
|
export interface TrimmedError extends TypeError<"Trimmed"> {}
|
|
1151
1149
|
|
|
1152
1150
|
export const formatTrimmedError = createTypeErrorFormatter<TrimmedError>(
|
|
1153
|
-
(error) => `The value ${error.value}
|
|
1151
|
+
(error) => `The value ${error.value} must be trimmed.`,
|
|
1154
1152
|
);
|
|
1155
1153
|
|
|
1156
1154
|
/**
|
|
@@ -1429,7 +1427,6 @@ export const formatBase64UrlError = createTypeErrorFormatter<Base64UrlError>(
|
|
|
1429
1427
|
(error) => `The value ${error.value} is not a valid Base64Url string.`,
|
|
1430
1428
|
);
|
|
1431
1429
|
|
|
1432
|
-
const hasNodeBuffer = typeof globalThis.Buffer !== "undefined";
|
|
1433
1430
|
const base64UrlOptions = { alphabet: "base64url", omitPadding: true };
|
|
1434
1431
|
|
|
1435
1432
|
/** Encodes a Uint8Array to a {@link Base64Url} string. */
|
|
@@ -1717,7 +1714,7 @@ export const idBytesToId = (idBytes: IdBytes): Id =>
|
|
|
1717
1714
|
uint8ArrayToBase64Url(idBytes) as unknown as Id;
|
|
1718
1715
|
|
|
1719
1716
|
/**
|
|
1720
|
-
* Positive number.
|
|
1717
|
+
* Positive number (> 0).
|
|
1721
1718
|
*
|
|
1722
1719
|
* ### Example
|
|
1723
1720
|
*
|
|
@@ -1740,11 +1737,11 @@ export const positive: BrandFactory<"Positive", number, PositiveError> = (
|
|
|
1740
1737
|
export interface PositiveError extends TypeError<"Positive"> {}
|
|
1741
1738
|
|
|
1742
1739
|
export const formatPositiveError = createTypeErrorFormatter<PositiveError>(
|
|
1743
|
-
(error) => `The value ${error.value}
|
|
1740
|
+
(error) => `The value ${error.value} must be positive (> 0).`,
|
|
1744
1741
|
);
|
|
1745
1742
|
|
|
1746
1743
|
/**
|
|
1747
|
-
* Negative number.
|
|
1744
|
+
* Negative number (< 0).
|
|
1748
1745
|
*
|
|
1749
1746
|
* ### Example
|
|
1750
1747
|
*
|
|
@@ -1764,11 +1761,11 @@ export const negative: BrandFactory<"Negative", number, NegativeError> = (
|
|
|
1764
1761
|
export interface NegativeError extends TypeError<"Negative"> {}
|
|
1765
1762
|
|
|
1766
1763
|
export const formatNegativeError = createTypeErrorFormatter<NegativeError>(
|
|
1767
|
-
(error) => `The value ${error.value}
|
|
1764
|
+
(error) => `The value ${error.value} must be negative (< 0).`,
|
|
1768
1765
|
);
|
|
1769
1766
|
|
|
1770
1767
|
/**
|
|
1771
|
-
* Non-positive number.
|
|
1768
|
+
* Non-positive number (≤ 0).
|
|
1772
1769
|
*
|
|
1773
1770
|
* ### Example
|
|
1774
1771
|
*
|
|
@@ -1797,7 +1794,7 @@ export const formatNonPositiveError =
|
|
|
1797
1794
|
);
|
|
1798
1795
|
|
|
1799
1796
|
/**
|
|
1800
|
-
* Non-negative number.
|
|
1797
|
+
* Non-negative number (≥ 0).
|
|
1801
1798
|
*
|
|
1802
1799
|
* ### Example
|
|
1803
1800
|
*
|
|
@@ -1862,7 +1859,7 @@ export const int: BrandFactory<"Int", number, IntError> = (parent) =>
|
|
|
1862
1859
|
export interface IntError extends TypeError<"Int"> {}
|
|
1863
1860
|
|
|
1864
1861
|
export const formatIntError = createTypeErrorFormatter<IntError>(
|
|
1865
|
-
(error) => `The value ${error.value}
|
|
1862
|
+
(error) => `The value ${error.value} must be an integer.`,
|
|
1866
1863
|
);
|
|
1867
1864
|
|
|
1868
1865
|
/**
|
|
@@ -2008,7 +2005,7 @@ export const nonNaN: BrandFactory<"NonNaN", number, NonNaNError> = (parent) =>
|
|
|
2008
2005
|
export interface NonNaNError extends TypeError<"NonNaN"> {}
|
|
2009
2006
|
|
|
2010
2007
|
export const formatNonNaNError = createTypeErrorFormatter<NonNaNError>(
|
|
2011
|
-
(
|
|
2008
|
+
() => `The value must not be NaN.`,
|
|
2012
2009
|
);
|
|
2013
2010
|
|
|
2014
2011
|
/** @category Number */
|
|
@@ -2030,7 +2027,7 @@ export const finite: BrandFactory<"Finite", number, FiniteError> = (parent) =>
|
|
|
2030
2027
|
export interface FiniteError extends TypeError<"Finite"> {}
|
|
2031
2028
|
|
|
2032
2029
|
export const formatFiniteError = createTypeErrorFormatter<FiniteError>(
|
|
2033
|
-
(error) => `The value ${error.value}
|
|
2030
|
+
(error) => `The value ${error.value} must be finite.`,
|
|
2034
2031
|
);
|
|
2035
2032
|
|
|
2036
2033
|
/**
|
package/src/Types.ts
CHANGED
|
@@ -79,7 +79,7 @@ export type NullablePartial<
|
|
|
79
79
|
export type IntentionalNever = never;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* String
|
|
82
|
+
* String, number, bigint, boolean, undefined, null
|
|
83
83
|
*
|
|
84
84
|
* https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types
|
|
85
85
|
*/
|
package/src/WebSocket.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { assertNoErrorInCatch } from "./Assert.js";
|
|
8
7
|
import { constVoid } from "./Function.js";
|
|
9
8
|
import { err, ok, Result } from "./Result.js";
|
|
10
9
|
import { retry, RetryError, RetryOptions } from "./Task.js";
|
|
@@ -192,7 +191,7 @@ export const createWebSocket: CreateWebSocket = (
|
|
|
192
191
|
* - Is rejected when a connection is closed.
|
|
193
192
|
* - Is resolved when WebSocket is disposed().
|
|
194
193
|
*/
|
|
195
|
-
retry(
|
|
194
|
+
void retry(
|
|
196
195
|
{
|
|
197
196
|
...defaultRetryOptions,
|
|
198
197
|
...retryOptions,
|
|
@@ -222,6 +221,7 @@ export const createWebSocket: CreateWebSocket = (
|
|
|
222
221
|
? { type: "WebSocketConnectionError", event }
|
|
223
222
|
: { type: "WebSocketConnectError", event };
|
|
224
223
|
onError?.(error);
|
|
224
|
+
|
|
225
225
|
// Trigger reconnect only on WebSocketConnectError.
|
|
226
226
|
if (error.type === "WebSocketConnectError") {
|
|
227
227
|
resolve(err(error));
|
|
@@ -237,14 +237,10 @@ export const createWebSocket: CreateWebSocket = (
|
|
|
237
237
|
onMessage?.(event.data as string | ArrayBuffer | Blob);
|
|
238
238
|
};
|
|
239
239
|
}),
|
|
240
|
-
)(reconnectController)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
})
|
|
245
|
-
.catch((error: unknown) => {
|
|
246
|
-
assertNoErrorInCatch("WebSocket retry", error);
|
|
247
|
-
});
|
|
240
|
+
)(reconnectController).then((result) => {
|
|
241
|
+
if (result.ok || result.error.type === "AbortError") return;
|
|
242
|
+
onError?.(result.error as WebSocketError);
|
|
243
|
+
});
|
|
248
244
|
|
|
249
245
|
return {
|
|
250
246
|
send: (data) => {
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./Assert.js";
|
|
|
3
3
|
export * from "./BigInt.js";
|
|
4
4
|
export * from "./Brand.js";
|
|
5
5
|
export * from "./Buffer.js";
|
|
6
|
+
export * from "./Cache.js";
|
|
6
7
|
export * from "./CallbackRegistry.js";
|
|
7
8
|
export * from "./Console.js";
|
|
8
9
|
export * from "./Crypto.js";
|
|
@@ -10,10 +11,12 @@ export * from "./Eq.js";
|
|
|
10
11
|
export * from "./Error.js";
|
|
11
12
|
export * from "./Evolu/Public.js";
|
|
12
13
|
export * from "./Function.js";
|
|
14
|
+
export * from "./Identicon.js";
|
|
13
15
|
export * from "./ManyToManyMap.js";
|
|
14
16
|
export * from "./Number.js";
|
|
15
17
|
export * from "./Object.js";
|
|
16
18
|
export * from "./Order.js";
|
|
19
|
+
export * from "./Platform.js";
|
|
17
20
|
export * from "./Random.js";
|
|
18
21
|
export * from "./Ref.js";
|
|
19
22
|
export * from "./Result.js";
|