@evolu/react-native 15.0.2 → 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.
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +2 -0
- package/dist/src/Polyfills.d.ts.map +1 -1
- package/dist/src/Polyfills.js +7 -2
- package/dist/src/Task.d.ts +2 -1
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +5 -2
- package/dist/src/components/EvoluIdenticon.js +2 -2
- package/dist/src/exports/expo-sqlite.d.ts +2 -1
- package/dist/src/exports/expo-sqlite.d.ts.map +1 -1
- package/dist/src/exports/expo-sqlite.js +2 -8
- package/dist/src/shared.js +0 -47
- package/dist/src/sqlite-drivers/createExpoSqliteDriver.d.ts.map +1 -1
- package/dist/src/sqlite-drivers/createExpoSqliteDriver.js +1 -0
- package/package.json +11 -43
- package/src/ErrorUtils.d.ts +2 -1
- package/src/LockManager.test.ts +537 -0
- package/src/LockManager.ts +2 -0
- package/src/Polyfills.test.ts +623 -0
- package/src/Polyfills.ts +7 -2
- package/src/Task.test.ts +82 -0
- package/src/Task.ts +8 -3
- package/src/components/EvoluIdenticon.tsx +2 -2
- package/src/exports/expo-sqlite.ts +2 -9
- package/src/shared.ts +1 -50
- package/src/sqlite-drivers/createExpoSqliteDriver.ts +5 -1
- package/dist/src/createExpoDeps.d.ts +0 -1
- package/dist/src/createExpoDeps.d.ts.map +0 -1
- package/dist/src/createExpoDeps.js +0 -163
- package/dist/src/exports/bare-op-sqlite.d.ts +0 -1
- package/dist/src/exports/bare-op-sqlite.d.ts.map +0 -1
- package/dist/src/exports/bare-op-sqlite.js +0 -31
- package/dist/src/exports/expo-op-sqlite.d.ts +0 -1
- package/dist/src/exports/expo-op-sqlite.d.ts.map +0 -1
- package/dist/src/exports/expo-op-sqlite.js +0 -16
- package/dist/src/sqlite-drivers/createOpSqliteDriver.d.ts +0 -3
- package/dist/src/sqlite-drivers/createOpSqliteDriver.d.ts.map +0 -1
- package/dist/src/sqlite-drivers/createOpSqliteDriver.js +0 -119
- package/src/createExpoDeps.ts +0 -164
- package/src/exports/bare-op-sqlite.ts +0 -30
- package/src/exports/expo-op-sqlite.ts +0 -15
- package/src/sqlite-drivers/createOpSqliteDriver.ts +0 -76
package/src/Task.test.ts
ADDED
|
@@ -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
|
-
*
|
|
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)
|
|
55
|
-
|
|
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
|
|
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
|
-
)
|
|
24
|
+
);
|
|
25
25
|
};
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Public entry point for Expo SQLite. Exported as
|
|
3
3
|
* "@evolu/react-native/expo-sqlite" in package.json.
|
|
4
4
|
*
|
|
5
|
-
* Use this with Expo projects
|
|
5
|
+
* Use this with Expo projects and existing React Native projects configured
|
|
6
|
+
* with Expo modules.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
import type { ConsoleDep } from "@evolu/common";
|
|
@@ -20,11 +21,3 @@ export const createEvoluDeps = (deps: Partial<ConsoleDep> = {}): EvoluDeps =>
|
|
|
20
21
|
void Expo.reloadAppAsync();
|
|
21
22
|
},
|
|
22
23
|
});
|
|
23
|
-
|
|
24
|
-
// import { createExpoDeps } from "../createExpoDeps.ts";
|
|
25
|
-
// import { createExpoSqliteDriver } from "../sqlite-drivers/createExpoSqliteDriver.ts";
|
|
26
|
-
//
|
|
27
|
-
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
28
|
-
// export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
29
|
-
// createSqliteDriver: createExpoSqliteDriver,
|
|
30
|
-
// });
|
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
|
|
59
|
+
createWorker<DbWorkerInit>((self) => {
|
|
60
60
|
const dbWorkerRun = createWorkerRun();
|
|
61
61
|
void dbWorkerRun(startDbWorker(self));
|
|
62
62
|
});
|
|
@@ -82,52 +82,3 @@ export const createEvoluDeps = (
|
|
|
82
82
|
sharedWorker,
|
|
83
83
|
});
|
|
84
84
|
};
|
|
85
|
-
|
|
86
|
-
// TODO: Reimplement local auth for React Native from scratch.
|
|
87
|
-
// export const createSharedLocalAuth = (
|
|
88
|
-
// secureStorage: SecureStorage,
|
|
89
|
-
// ): LocalAuth =>
|
|
90
|
-
// createLocalAuth({
|
|
91
|
-
// randomBytes,
|
|
92
|
-
// secureStorage,
|
|
93
|
-
// });
|
|
94
|
-
|
|
95
|
-
// import {
|
|
96
|
-
// createConsole,
|
|
97
|
-
// createLocalAuth,
|
|
98
|
-
// createRandomBytes,
|
|
99
|
-
// type CreateSqliteDriverDep,
|
|
100
|
-
// type LocalAuth,
|
|
101
|
-
// type ReloadAppDep,
|
|
102
|
-
// type SecureStorage,
|
|
103
|
-
// } from "@evolu/common";
|
|
104
|
-
// import type {
|
|
105
|
-
// // createDbWorkerForPlatform,
|
|
106
|
-
// // createDbWorkerForPlatform,
|
|
107
|
-
// EvoluDeps,
|
|
108
|
-
// } from "@evolu/common/local-first";
|
|
109
|
-
//
|
|
110
|
-
// const _console = createConsole();
|
|
111
|
-
// const randomBytes = createRandomBytes();
|
|
112
|
-
//
|
|
113
|
-
// export const createSharedEvoluDeps = (
|
|
114
|
-
// _deps: CreateSqliteDriverDep & ReloadAppDep,
|
|
115
|
-
// ): EvoluDeps => {
|
|
116
|
-
// throw new Error("todo");
|
|
117
|
-
// };
|
|
118
|
-
//
|
|
119
|
-
// ({
|
|
120
|
-
// ...deps,
|
|
121
|
-
// console,
|
|
122
|
-
// sharedWorker: "TODO" as never,
|
|
123
|
-
// // createDbWorker: () =>
|
|
124
|
-
// // createDbWorkerForPlatform({
|
|
125
|
-
// // ...deps,
|
|
126
|
-
// // console,
|
|
127
|
-
// // createWebSocket,
|
|
128
|
-
// // random: createRandom(),
|
|
129
|
-
// // randomBytes,
|
|
130
|
-
// // time: createTime(),
|
|
131
|
-
// // }),
|
|
132
|
-
// randomBytes,
|
|
133
|
-
// });
|
|
@@ -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
|
-
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=createExpoDeps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createExpoDeps.d.ts","sourceRoot":"","sources":["../../src/createExpoDeps.ts"],"names":[],"mappings":""}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import type {
|
|
3
|
-
// AccessControl,
|
|
4
|
-
// LocalAuthOptions,
|
|
5
|
-
// SecureStorage,
|
|
6
|
-
// SensitiveInfoItem,
|
|
7
|
-
// StorageMetadata,
|
|
8
|
-
// } from "@evolu/common";
|
|
9
|
-
// import {
|
|
10
|
-
// type CreateSqliteDriverDep,
|
|
11
|
-
// type LocalAuth,
|
|
12
|
-
// localAuthDefaultOptions,
|
|
13
|
-
// type ReloadApp,
|
|
14
|
-
// } from "@evolu/common";
|
|
15
|
-
// import type { EvoluDeps } from "@evolu/common/local-first";
|
|
16
|
-
// import * as Expo from "expo";
|
|
17
|
-
// import * as SecureStore from "expo-secure-store";
|
|
18
|
-
// import KVStore from "expo-sqlite/kv-store";
|
|
19
|
-
// import { createSharedEvoluDeps, createSharedLocalAuth } from "./shared.ts";
|
|
20
|
-
// const reloadApp: ReloadApp = () => {
|
|
21
|
-
// void Expo.reloadAppAsync();
|
|
22
|
-
// };
|
|
23
|
-
//
|
|
24
|
-
// const createSecureStore = (): SecureStorage => {
|
|
25
|
-
// const store: SecureStorage = {
|
|
26
|
-
// setItem: async (key, value, options) => {
|
|
27
|
-
// const rnsiOpts = convertOptions(options);
|
|
28
|
-
// const service = options?.service ?? "default";
|
|
29
|
-
// const metadata = createMetadata(options?.accessControl === "none");
|
|
30
|
-
// await KVStore.setItem(`${service}-${key}`, "1");
|
|
31
|
-
// await SecureStore.setItemAsync(
|
|
32
|
-
// key,
|
|
33
|
-
// JSON.stringify({ value, metadata }),
|
|
34
|
-
// rnsiOpts,
|
|
35
|
-
// );
|
|
36
|
-
// return { metadata };
|
|
37
|
-
// },
|
|
38
|
-
//
|
|
39
|
-
// getItem: async (key, options) => {
|
|
40
|
-
// const rnsiOpts = convertOptions(options);
|
|
41
|
-
// const service = options?.service ?? "default";
|
|
42
|
-
// let data: { value: string; metadata: StorageMetadata };
|
|
43
|
-
// try {
|
|
44
|
-
// const result = await SecureStore.getItemAsync(key, rnsiOpts);
|
|
45
|
-
// if (!result) return null;
|
|
46
|
-
// data = JSON.parse(result) as {
|
|
47
|
-
// value: string;
|
|
48
|
-
// metadata: StorageMetadata;
|
|
49
|
-
// };
|
|
50
|
-
// } catch (_error) {
|
|
51
|
-
// return null;
|
|
52
|
-
// }
|
|
53
|
-
// return { key, service, ...data };
|
|
54
|
-
// },
|
|
55
|
-
//
|
|
56
|
-
// deleteItem: async (key, options) => {
|
|
57
|
-
// const rnsiOpts = convertOptions(options);
|
|
58
|
-
// const service = options?.service ?? "default";
|
|
59
|
-
// await Promise.all([
|
|
60
|
-
// KVStore.removeItemAsync(`${service}-${key}`),
|
|
61
|
-
// SecureStore.deleteItemAsync(key, rnsiOpts),
|
|
62
|
-
// ]);
|
|
63
|
-
// return true;
|
|
64
|
-
// },
|
|
65
|
-
//
|
|
66
|
-
// getAllItems: async (options) => {
|
|
67
|
-
// const keys = await KVStore.getAllKeysAsync();
|
|
68
|
-
// const service = options?.service ?? "default";
|
|
69
|
-
// const metadata = createMetadata(options?.accessControl === "none");
|
|
70
|
-
// return keys
|
|
71
|
-
// .filter((key) => key.startsWith(`${service}-`))
|
|
72
|
-
// .map((key) => ({
|
|
73
|
-
// key: key.slice(service.length + 1),
|
|
74
|
-
// service,
|
|
75
|
-
// metadata,
|
|
76
|
-
// }));
|
|
77
|
-
// },
|
|
78
|
-
//
|
|
79
|
-
// clearService: async (options) => {
|
|
80
|
-
// const rnsiOpts = convertOptions(options);
|
|
81
|
-
// const service = options?.service ?? "default";
|
|
82
|
-
// const items = await store.getAllItems(options);
|
|
83
|
-
// await KVStore.multiRemove(items.map((item) => `${service}-${item.key}`));
|
|
84
|
-
// await Promise.all(
|
|
85
|
-
// items.map(async (item) => {
|
|
86
|
-
// await SecureStore.deleteItemAsync(item.key, rnsiOpts);
|
|
87
|
-
// }),
|
|
88
|
-
// );
|
|
89
|
-
// },
|
|
90
|
-
// };
|
|
91
|
-
//
|
|
92
|
-
// return store;
|
|
93
|
-
// };
|
|
94
|
-
// /**
|
|
95
|
-
// * Create default metadata for backwards compatibility with items that don't
|
|
96
|
-
// * have stored metadata.
|
|
97
|
-
// */
|
|
98
|
-
// const createMetadata = (isSecure = true): SensitiveInfoItem["metadata"] => ({
|
|
99
|
-
// backend: "keychain",
|
|
100
|
-
// accessControl: isSecure ? "biometryCurrentSet" : "none",
|
|
101
|
-
// securityLevel: isSecure ? "biometry" : "software",
|
|
102
|
-
// timestamp: Date.now(),
|
|
103
|
-
// });
|
|
104
|
-
//
|
|
105
|
-
// const convertOptions = (
|
|
106
|
-
// options?: LocalAuthOptions,
|
|
107
|
-
// ): SecureStore.SecureStoreOptions => {
|
|
108
|
-
// const accessGroup =
|
|
109
|
-
// options?.keychainGroup ?? localAuthDefaultOptions.keychainGroup ?? "";
|
|
110
|
-
// const keychainService =
|
|
111
|
-
// options?.service ?? localAuthDefaultOptions.service ?? "";
|
|
112
|
-
// const keychainAccessible = convertKeychainAccessible(
|
|
113
|
-
// options?.accessControl ??
|
|
114
|
-
// localAuthDefaultOptions.accessControl ??
|
|
115
|
-
// "biometryCurrentSet",
|
|
116
|
-
// );
|
|
117
|
-
// const authenticationPrompt =
|
|
118
|
-
// options?.authenticationPrompt?.title ??
|
|
119
|
-
// localAuthDefaultOptions.authenticationPrompt?.title ??
|
|
120
|
-
// "";
|
|
121
|
-
// return {
|
|
122
|
-
// accessGroup,
|
|
123
|
-
// keychainService,
|
|
124
|
-
// keychainAccessible,
|
|
125
|
-
// authenticationPrompt,
|
|
126
|
-
// requireAuthentication: options?.accessControl !== "none",
|
|
127
|
-
// };
|
|
128
|
-
// };
|
|
129
|
-
//
|
|
130
|
-
// const convertKeychainAccessible = (
|
|
131
|
-
// accessControl: AccessControl,
|
|
132
|
-
// ): SecureStore.KeychainAccessibilityConstant => {
|
|
133
|
-
// switch (accessControl) {
|
|
134
|
-
// case "none":
|
|
135
|
-
// // eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
136
|
-
// return SecureStore.ALWAYS;
|
|
137
|
-
// case "biometryCurrentSet":
|
|
138
|
-
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
139
|
-
// case "biometryAny":
|
|
140
|
-
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
141
|
-
// case "devicePasscode":
|
|
142
|
-
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
143
|
-
// case "secureEnclaveBiometry":
|
|
144
|
-
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
145
|
-
// // Exhaustive check
|
|
146
|
-
// default:
|
|
147
|
-
// accessControl satisfies never;
|
|
148
|
-
// // Default (for typescript, should never hit)
|
|
149
|
-
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
150
|
-
// }
|
|
151
|
-
// };
|
|
152
|
-
//
|
|
153
|
-
// const localAuth = createSharedLocalAuth(createSecureStore());
|
|
154
|
-
//
|
|
155
|
-
// export const createExpoDeps = (
|
|
156
|
-
// deps: CreateSqliteDriverDep,
|
|
157
|
-
// ): { evoluReactNativeDeps: EvoluDeps; localAuth: LocalAuth } => ({
|
|
158
|
-
// evoluReactNativeDeps: createSharedEvoluDeps({
|
|
159
|
-
// ...deps,
|
|
160
|
-
// reloadApp,
|
|
161
|
-
// }),
|
|
162
|
-
// localAuth,
|
|
163
|
-
// });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=bare-op-sqlite.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bare-op-sqlite.d.ts","sourceRoot":"","sources":["../../../src/exports/bare-op-sqlite.ts"],"names":[],"mappings":""}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// /**
|
|
3
|
-
// * Public entry point for bare React Native with OP-SQLite. Exported as
|
|
4
|
-
// * "@evolu/react-native/bare-op-sqlite" in package.json.
|
|
5
|
-
// *
|
|
6
|
-
// * Use this with bare React Native projects (not Expo) that use
|
|
7
|
-
// * `@op-engineering/op-sqlite`.
|
|
8
|
-
// */
|
|
9
|
-
//
|
|
10
|
-
// import { type ReloadApp } from "@evolu/common";
|
|
11
|
-
// import { DevSettings } from "react-native";
|
|
12
|
-
// import { SensitiveInfo } from "react-native-sensitive-info";
|
|
13
|
-
// import { createSharedEvoluDeps, createSharedLocalAuth } from "../shared.ts";
|
|
14
|
-
// import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.ts";
|
|
15
|
-
//
|
|
16
|
-
// const reloadApp: ReloadApp = () => {
|
|
17
|
-
// if (process.env.NODE_ENV === "development") {
|
|
18
|
-
// DevSettings.reload();
|
|
19
|
-
// } else {
|
|
20
|
-
// // TODO: reload not implemented for bare rn
|
|
21
|
-
// }
|
|
22
|
-
// };
|
|
23
|
-
//
|
|
24
|
-
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
25
|
-
// export const evoluReactNativeDeps = createSharedEvoluDeps({
|
|
26
|
-
// createSqliteDriver: createOpSqliteDriver,
|
|
27
|
-
// reloadApp,
|
|
28
|
-
// });
|
|
29
|
-
//
|
|
30
|
-
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
31
|
-
// export const localAuth = createSharedLocalAuth(SensitiveInfo);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=expo-op-sqlite.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expo-op-sqlite.d.ts","sourceRoot":"","sources":["../../../src/exports/expo-op-sqlite.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// /**
|
|
3
|
-
// * Public entry point for Expo with OP-SQLite. Exported as
|
|
4
|
-
// * "@evolu/react-native/expo-op-sqlite" in package.json.
|
|
5
|
-
// *
|
|
6
|
-
// * Use this with Expo projects that use `@op-engineering/op-sqlite` for better
|
|
7
|
-
// * performance.
|
|
8
|
-
// */
|
|
9
|
-
//
|
|
10
|
-
// import { createExpoDeps } from "../createExpoDeps.ts";
|
|
11
|
-
// import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.ts";
|
|
12
|
-
//
|
|
13
|
-
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
14
|
-
// export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
15
|
-
// createSqliteDriver: createOpSqliteDriver,
|
|
16
|
-
// });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createOpSqliteDriver.d.ts","sourceRoot":"","sources":["../../../src/sqlite-drivers/createOpSqliteDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,kBAAkB,EAGxB,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,oBAAoB,EAAE,kBAiEhC,CAAC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
|
-
import { constVoid, bytesToHex, createPreparedStatementsCache, ok, } from "@evolu/common";
|
|
54
|
-
import { open } from "@op-engineering/op-sqlite";
|
|
55
|
-
export const createOpSqliteDriver = (name, options) => () => {
|
|
56
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
57
|
-
try {
|
|
58
|
-
// https://op-engineering.github.io/op-sqlite/docs/configuration#in-memory
|
|
59
|
-
const disposer = __addDisposableResource(env_1, new DisposableStack(), false);
|
|
60
|
-
const db = disposer.adopt(open(options?.mode === "memory"
|
|
61
|
-
? { name: `inMemoryDb`, location: ":memory:" }
|
|
62
|
-
: {
|
|
63
|
-
name: `evolu1-${name}.db`,
|
|
64
|
-
...(options?.mode === "encrypted" && {
|
|
65
|
-
encryptionKey: `x'${bytesToHex(options.encryptionKey)}'`,
|
|
66
|
-
}),
|
|
67
|
-
}), (db) => {
|
|
68
|
-
db.close();
|
|
69
|
-
});
|
|
70
|
-
const cache = disposer.use(createPreparedStatementsCache((sql) => db.prepareStatement(sql),
|
|
71
|
-
// op-sqlite doesn't have API for that
|
|
72
|
-
constVoid));
|
|
73
|
-
const disposables = disposer.move();
|
|
74
|
-
return ok({
|
|
75
|
-
exec: (query) => {
|
|
76
|
-
const prepared = cache.get(query);
|
|
77
|
-
if (prepared) {
|
|
78
|
-
prepared.bindSync(query.parameters);
|
|
79
|
-
}
|
|
80
|
-
const { rows, rowsAffected } = db.executeSync(query.sql, query.parameters);
|
|
81
|
-
return { rows: rows, changes: rowsAffected };
|
|
82
|
-
},
|
|
83
|
-
// FIXME: op-sqlite does not expose binary, but a path to the database file
|
|
84
|
-
// another react native dependency would be needed to implement this
|
|
85
|
-
export: () => {
|
|
86
|
-
throw new Error("TODO: Not implemented yet");
|
|
87
|
-
},
|
|
88
|
-
deleteDatabase: () => {
|
|
89
|
-
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
90
|
-
try {
|
|
91
|
-
const deleteDisposer = __addDisposableResource(env_2, new DisposableStack(), false);
|
|
92
|
-
if (options?.mode !== "memory") {
|
|
93
|
-
deleteDisposer.defer(() => {
|
|
94
|
-
db.delete();
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
deleteDisposer.use(disposables);
|
|
98
|
-
}
|
|
99
|
-
catch (e_2) {
|
|
100
|
-
env_2.error = e_2;
|
|
101
|
-
env_2.hasError = true;
|
|
102
|
-
}
|
|
103
|
-
finally {
|
|
104
|
-
__disposeResources(env_2);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
[Symbol.dispose]: () => {
|
|
108
|
-
disposables.dispose();
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
catch (e_1) {
|
|
113
|
-
env_1.error = e_1;
|
|
114
|
-
env_1.hasError = true;
|
|
115
|
-
}
|
|
116
|
-
finally {
|
|
117
|
-
__disposeResources(env_1);
|
|
118
|
-
}
|
|
119
|
-
};
|