@evolu/react-native 16.0.0 → 16.0.1

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.
@@ -0,0 +1,82 @@
1
+ import {
2
+ assertEqual,
3
+ assertLength,
4
+ assertNonNullable,
5
+ assertThrows,
6
+ assertTrue,
7
+ testStubGlobal,
8
+ } from "@evolu/common";
9
+ import { describe, it, mock } from "node:test";
10
+ import { createRun } from "./Task.ts";
11
+
12
+ describe("createRun", () => {
13
+ it("createRun reports defects with ErrorUtils.reportError", async () => {
14
+ const reportError = mock.fn<(error: unknown) => void>();
15
+ using _errorUtils = testStubGlobal("ErrorUtils", {
16
+ getGlobalHandler: () => null,
17
+ setGlobalHandler:
18
+ mock.fn<NonNullable<typeof ErrorUtils>["setGlobalHandler"]>(),
19
+ reportError,
20
+ });
21
+ await using run = createRun();
22
+ const defect = new Error("boom");
23
+
24
+ run.panic(defect);
25
+
26
+ assertEqual(reportError.mock.callCount(), 1);
27
+ const reported = reportError.mock.calls[0]?.arguments[0];
28
+ assertNonNullable(reported);
29
+ assertTrue(typeof reported === "object");
30
+ assertEqual(Reflect.get(reported, "reason"), {
31
+ type: "PanicAbortReason",
32
+ defect,
33
+ });
34
+ });
35
+
36
+ it("createRun preserves a custom reportDefect", async () => {
37
+ const reportError =
38
+ mock.fn<NonNullable<typeof ErrorUtils>["reportError"]>();
39
+ const reportDefect = mock.fn();
40
+ using _errorUtils = testStubGlobal("ErrorUtils", {
41
+ getGlobalHandler: () => null,
42
+ setGlobalHandler:
43
+ mock.fn<NonNullable<typeof ErrorUtils>["setGlobalHandler"]>(),
44
+ reportError,
45
+ });
46
+ await using run = createRun({ reportDefect });
47
+
48
+ run.panic(new Error("boom"));
49
+
50
+ assertEqual(reportDefect.mock.callCount(), 1);
51
+ assertEqual(reportError.mock.callCount(), 0);
52
+ });
53
+
54
+ it("createRun falls back when ErrorUtils is unavailable", async (t) => {
55
+ using _errorUtils = testStubGlobal("ErrorUtils", undefined);
56
+ assertTrue(Reflect.deleteProperty(globalThis, "ErrorUtils"));
57
+ const callbacks: Array<() => void> = [];
58
+ t.mock.method(globalThis, "queueMicrotask", (callback: () => void) => {
59
+ callbacks.push(callback);
60
+ });
61
+ await using run = createRun();
62
+
63
+ run.panic(new Error("boom"));
64
+
65
+ assertLength(callbacks, 1);
66
+ assertThrows(callbacks[0], (reported) => {
67
+ assertNonNullable(reported);
68
+ assertTrue(typeof reported === "object");
69
+ const reason = Reflect.get(reported, "reason");
70
+ assertNonNullable(reason);
71
+ assertTrue(typeof reason === "object");
72
+ assertEqual(Reflect.get(reason, "type"), "PanicAbortReason");
73
+ });
74
+ });
75
+
76
+ it("creates a run", async () => {
77
+ await using run = createRun();
78
+
79
+ assertNonNullable(run);
80
+ assertNonNullable(run.deps);
81
+ });
82
+ });
package/src/Task.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  *
24
24
  * ```ts
25
25
  * import {
26
+ * assertSame,
26
27
  * createConsole,
27
28
  * createConsoleFormatter,
28
29
  * ok,
@@ -38,7 +39,7 @@ import {
38
39
  * await using run = createRun({ console });
39
40
  * const appPromise = run.ok(() => ok("started"));
40
41
  *
41
- * expect(await appPromise).toBe("started");
42
+ * assertSame(await appPromise, "started");
42
43
  * ```
43
44
  */
44
45
  export function createRun(): DisposableRun;
@@ -51,8 +52,12 @@ export function createRun<D extends object>(
51
52
  deps?: RunCustomDeps<D>,
52
53
  ): DisposableRun | DisposableRun<D> {
53
54
  const reportDefect = (reported: unknown): void => {
54
- if (globalThis.ErrorUtils) globalThis.ErrorUtils.reportError(reported);
55
- else reportDefectAfterMicrotask(reported);
55
+ if (globalThis.ErrorUtils) {
56
+ // oxlint-disable-next-line evolu/no-unnecessary-global-this -- Report through the React Native host API on the global object even if a realm lexical binding shadows it.
57
+ globalThis.ErrorUtils.reportError(reported);
58
+ } else {
59
+ reportDefectAfterMicrotask(reported);
60
+ }
56
61
  };
57
62
 
58
63
  return deps === undefined
@@ -10,7 +10,7 @@ export const EvoluIdenticon: FC<{
10
10
  style?: IdenticonStyle;
11
11
  }> = ({ id, size = 32, borderRadius = 3, style }) => {
12
12
  const svg = useMemo(() => createIdenticon(id, style), [id, style]);
13
- return id ? (
13
+ return (
14
14
  <View
15
15
  style={{
16
16
  width: size,
@@ -21,5 +21,5 @@ export const EvoluIdenticon: FC<{
21
21
  >
22
22
  <SvgXml xml={svg} width={size} height={size} />
23
23
  </View>
24
- ) : null;
24
+ );
25
25
  };
package/src/shared.ts CHANGED
@@ -56,7 +56,7 @@ export const createEvoluDeps = (
56
56
  };
57
57
 
58
58
  const createDbWorker: CreateDbWorker = (): DbWorker =>
59
- createWorker<DbWorkerInit, never>((self) => {
59
+ createWorker<DbWorkerInit>((self) => {
60
60
  const dbWorkerRun = createWorkerRun();
61
61
  void dbWorkerRun(startDbWorker(self));
62
62
  });
@@ -8,6 +8,7 @@ import {
8
8
  import {
9
9
  deleteDatabaseSync,
10
10
  openDatabaseSync,
11
+ type SQLiteBindValue,
11
12
  type SQLiteStatement,
12
13
  } from "expo-sqlite";
13
14
 
@@ -39,7 +40,10 @@ export const createExpoSqliteDriver: CreateSqliteDriver =
39
40
  return ok({
40
41
  exec: (query) => {
41
42
  const execStatement = (statement: SQLiteStatement) => {
42
- const result = statement.executeSync(query.parameters);
43
+ // Expo only reads the array, but its parameter type is mutable.
44
+ const result = statement.executeSync(
45
+ query.parameters as Array<SQLiteBindValue>,
46
+ );
43
47
  try {
44
48
  const rows = result.getAllSync();
45
49
  const changes = result.changes;