@evolu/react-native 14.3.0 → 15.0.0-next.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/README.md +3 -3
- package/dist/src/LockManager.d.ts +13 -0
- package/dist/src/LockManager.d.ts.map +1 -0
- package/dist/src/LockManager.js +219 -0
- package/dist/src/Polyfills.d.ts +3 -0
- package/dist/src/Polyfills.d.ts.map +1 -0
- package/dist/src/Polyfills.js +209 -0
- package/dist/src/Task.d.ts +31 -0
- package/dist/src/Task.d.ts.map +1 -0
- package/dist/src/Task.js +46 -0
- package/dist/src/components/EvoluIdenticon.d.ts +9 -0
- package/dist/src/components/EvoluIdenticon.d.ts.map +1 -0
- package/dist/{components → src/components}/EvoluIdenticon.js +1 -1
- package/dist/src/createExpoDeps.d.ts +1 -0
- package/dist/src/createExpoDeps.d.ts.map +1 -0
- package/dist/src/createExpoDeps.js +163 -0
- package/dist/src/exports/bare-op-sqlite.d.ts +1 -0
- package/dist/src/exports/bare-op-sqlite.d.ts.map +1 -0
- package/dist/src/exports/bare-op-sqlite.js +31 -0
- package/dist/src/exports/expo-op-sqlite.d.ts +1 -0
- package/dist/src/exports/expo-op-sqlite.d.ts.map +1 -0
- package/dist/src/exports/expo-op-sqlite.js +16 -0
- package/dist/src/exports/expo-sqlite.d.ts +11 -0
- package/dist/src/exports/expo-sqlite.d.ts.map +1 -0
- package/dist/src/exports/expo-sqlite.js +24 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/shared.d.ts +5 -0
- package/dist/src/shared.d.ts.map +1 -0
- package/dist/src/shared.js +90 -0
- package/dist/src/sqlite-drivers/createExpoSqliteDriver.d.ts +3 -0
- package/dist/src/sqlite-drivers/createExpoSqliteDriver.d.ts.map +1 -0
- package/dist/src/sqlite-drivers/createExpoSqliteDriver.js +134 -0
- package/dist/src/sqlite-drivers/createOpSqliteDriver.d.ts +3 -0
- package/dist/src/sqlite-drivers/createOpSqliteDriver.d.ts.map +1 -0
- package/dist/src/sqlite-drivers/createOpSqliteDriver.js +119 -0
- package/dist/src/web.d.ts.map +1 -0
- package/package.json +72 -48
- package/src/ErrorUtils.d.ts +19 -0
- package/src/LockManager.ts +325 -0
- package/src/Polyfills.ts +301 -0
- package/src/Task.ts +66 -0
- package/src/components/EvoluIdenticon.tsx +2 -2
- package/src/createExpoDeps.ts +162 -160
- package/src/exports/bare-op-sqlite.ts +30 -28
- package/src/exports/expo-op-sqlite.ts +15 -14
- package/src/exports/expo-sqlite.ts +21 -4
- package/src/index.ts +2 -0
- package/src/shared.ts +115 -49
- package/src/sqlite-drivers/createExpoSqliteDriver.ts +74 -51
- package/src/sqlite-drivers/createOpSqliteDriver.ts +62 -60
- package/dist/components/EvoluIdenticon.d.ts +0 -9
- package/dist/components/EvoluIdenticon.d.ts.map +0 -1
- package/dist/createExpoDeps.d.ts +0 -7
- package/dist/createExpoDeps.d.ts.map +0 -1
- package/dist/createExpoDeps.js +0 -123
- package/dist/exports/bare-op-sqlite.d.ts +0 -10
- package/dist/exports/bare-op-sqlite.d.ts.map +0 -1
- package/dist/exports/bare-op-sqlite.js +0 -24
- package/dist/exports/expo-op-sqlite.d.ts +0 -9
- package/dist/exports/expo-op-sqlite.d.ts.map +0 -1
- package/dist/exports/expo-op-sqlite.js +0 -12
- package/dist/exports/expo-sqlite.d.ts +0 -8
- package/dist/exports/expo-sqlite.d.ts.map +0 -1
- package/dist/exports/expo-sqlite.js +0 -11
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1
- package/dist/shared.d.ts +0 -5
- package/dist/shared.d.ts.map +0 -1
- package/dist/shared.js +0 -39
- package/dist/sqlite-drivers/createExpoSqliteDriver.d.ts +0 -3
- package/dist/sqlite-drivers/createExpoSqliteDriver.d.ts.map +0 -1
- package/dist/sqlite-drivers/createExpoSqliteDriver.js +0 -46
- package/dist/sqlite-drivers/createOpSqliteDriver.d.ts +0 -3
- package/dist/sqlite-drivers/createOpSqliteDriver.d.ts.map +0 -1
- package/dist/sqlite-drivers/createOpSqliteDriver.js +0 -54
- package/dist/web.d.ts.map +0 -1
- /package/dist/{web.d.ts → src/web.d.ts} +0 -0
- /package/dist/{web.js → src/web.js} +0 -0
package/src/createExpoDeps.ts
CHANGED
|
@@ -1,162 +1,164 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
1
|
+
// import type {
|
|
2
|
+
// AccessControl,
|
|
3
|
+
// LocalAuthOptions,
|
|
4
|
+
// SecureStorage,
|
|
5
|
+
// SensitiveInfoItem,
|
|
6
|
+
// StorageMetadata,
|
|
7
|
+
// } from "@evolu/common";
|
|
8
|
+
// import {
|
|
9
|
+
// type CreateSqliteDriverDep,
|
|
10
|
+
// type LocalAuth,
|
|
11
|
+
// localAuthDefaultOptions,
|
|
12
|
+
// type ReloadApp,
|
|
13
|
+
// } from "@evolu/common";
|
|
14
|
+
// import type { EvoluDeps } from "@evolu/common/local-first";
|
|
15
|
+
// import * as Expo from "expo";
|
|
16
|
+
// import * as SecureStore from "expo-secure-store";
|
|
17
|
+
// import KVStore from "expo-sqlite/kv-store";
|
|
18
|
+
// import { createSharedEvoluDeps, createSharedLocalAuth } from "./shared.js";
|
|
15
19
|
|
|
16
|
-
const reloadApp: ReloadApp = () => {
|
|
17
|
-
|
|
18
|
-
};
|
|
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
|
+
// };
|
|
19
94
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Create default metadata for backwards compatibility with items that don't
|
|
93
|
-
* have stored metadata.
|
|
94
|
-
*/
|
|
95
|
-
const createMetadata = (isSecure = true): SensitiveInfoItem["metadata"] => {
|
|
96
|
-
return {
|
|
97
|
-
backend: "keychain",
|
|
98
|
-
accessControl: isSecure ? "biometryCurrentSet" : "none",
|
|
99
|
-
securityLevel: isSecure ? "biometry" : "software",
|
|
100
|
-
timestamp: Date.now(),
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
function convertOptions(
|
|
105
|
-
options?: LocalAuthOptions,
|
|
106
|
-
): SecureStore.SecureStoreOptions {
|
|
107
|
-
const accessGroup =
|
|
108
|
-
options?.keychainGroup ?? localAuthDefaultOptions.keychainGroup ?? "";
|
|
109
|
-
const keychainService =
|
|
110
|
-
options?.service ?? localAuthDefaultOptions.service ?? "";
|
|
111
|
-
const keychainAccessible = convertKeychainAccessible(
|
|
112
|
-
options?.accessControl ??
|
|
113
|
-
localAuthDefaultOptions.accessControl ??
|
|
114
|
-
"biometryCurrentSet",
|
|
115
|
-
);
|
|
116
|
-
const authenticationPrompt =
|
|
117
|
-
options?.authenticationPrompt?.title ??
|
|
118
|
-
localAuthDefaultOptions.authenticationPrompt?.title ??
|
|
119
|
-
"";
|
|
120
|
-
return {
|
|
121
|
-
accessGroup,
|
|
122
|
-
keychainService,
|
|
123
|
-
keychainAccessible,
|
|
124
|
-
authenticationPrompt,
|
|
125
|
-
requireAuthentication: options?.accessControl !== "none",
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function convertKeychainAccessible(
|
|
130
|
-
accessControl: AccessControl,
|
|
131
|
-
): SecureStore.KeychainAccessibilityConstant {
|
|
132
|
-
switch (accessControl) {
|
|
133
|
-
case "none":
|
|
134
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
135
|
-
return SecureStore.ALWAYS;
|
|
136
|
-
case "biometryCurrentSet":
|
|
137
|
-
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
138
|
-
case "biometryAny":
|
|
139
|
-
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
140
|
-
case "devicePasscode":
|
|
141
|
-
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
142
|
-
case "secureEnclaveBiometry":
|
|
143
|
-
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
144
|
-
// Exhaustive check
|
|
145
|
-
default:
|
|
146
|
-
accessControl satisfies never;
|
|
147
|
-
// Default (for typescript, should never hit)
|
|
148
|
-
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const localAuth = createSharedLocalAuth(createSecureStore());
|
|
153
|
-
|
|
154
|
-
export const createExpoDeps = (
|
|
155
|
-
deps: CreateSqliteDriverDep,
|
|
156
|
-
): { evoluReactNativeDeps: EvoluDeps; localAuth: LocalAuth } => ({
|
|
157
|
-
evoluReactNativeDeps: createSharedEvoluDeps({
|
|
158
|
-
...deps,
|
|
159
|
-
reloadApp,
|
|
160
|
-
}),
|
|
161
|
-
localAuth,
|
|
162
|
-
});
|
|
95
|
+
// /**
|
|
96
|
+
// * Create default metadata for backwards compatibility with items that don't
|
|
97
|
+
// * have stored metadata.
|
|
98
|
+
// */
|
|
99
|
+
// const createMetadata = (isSecure = true): SensitiveInfoItem["metadata"] => ({
|
|
100
|
+
// backend: "keychain",
|
|
101
|
+
// accessControl: isSecure ? "biometryCurrentSet" : "none",
|
|
102
|
+
// securityLevel: isSecure ? "biometry" : "software",
|
|
103
|
+
// timestamp: Date.now(),
|
|
104
|
+
// });
|
|
105
|
+
//
|
|
106
|
+
// const convertOptions = (
|
|
107
|
+
// options?: LocalAuthOptions,
|
|
108
|
+
// ): SecureStore.SecureStoreOptions => {
|
|
109
|
+
// const accessGroup =
|
|
110
|
+
// options?.keychainGroup ?? localAuthDefaultOptions.keychainGroup ?? "";
|
|
111
|
+
// const keychainService =
|
|
112
|
+
// options?.service ?? localAuthDefaultOptions.service ?? "";
|
|
113
|
+
// const keychainAccessible = convertKeychainAccessible(
|
|
114
|
+
// options?.accessControl ??
|
|
115
|
+
// localAuthDefaultOptions.accessControl ??
|
|
116
|
+
// "biometryCurrentSet",
|
|
117
|
+
// );
|
|
118
|
+
// const authenticationPrompt =
|
|
119
|
+
// options?.authenticationPrompt?.title ??
|
|
120
|
+
// localAuthDefaultOptions.authenticationPrompt?.title ??
|
|
121
|
+
// "";
|
|
122
|
+
// return {
|
|
123
|
+
// accessGroup,
|
|
124
|
+
// keychainService,
|
|
125
|
+
// keychainAccessible,
|
|
126
|
+
// authenticationPrompt,
|
|
127
|
+
// requireAuthentication: options?.accessControl !== "none",
|
|
128
|
+
// };
|
|
129
|
+
// };
|
|
130
|
+
//
|
|
131
|
+
// const convertKeychainAccessible = (
|
|
132
|
+
// accessControl: AccessControl,
|
|
133
|
+
// ): SecureStore.KeychainAccessibilityConstant => {
|
|
134
|
+
// switch (accessControl) {
|
|
135
|
+
// case "none":
|
|
136
|
+
// // eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
137
|
+
// return SecureStore.ALWAYS;
|
|
138
|
+
// case "biometryCurrentSet":
|
|
139
|
+
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
140
|
+
// case "biometryAny":
|
|
141
|
+
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
142
|
+
// case "devicePasscode":
|
|
143
|
+
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
144
|
+
// case "secureEnclaveBiometry":
|
|
145
|
+
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
146
|
+
// // Exhaustive check
|
|
147
|
+
// default:
|
|
148
|
+
// accessControl satisfies never;
|
|
149
|
+
// // Default (for typescript, should never hit)
|
|
150
|
+
// return SecureStore.AFTER_FIRST_UNLOCK;
|
|
151
|
+
// }
|
|
152
|
+
// };
|
|
153
|
+
//
|
|
154
|
+
// const localAuth = createSharedLocalAuth(createSecureStore());
|
|
155
|
+
//
|
|
156
|
+
// export const createExpoDeps = (
|
|
157
|
+
// deps: CreateSqliteDriverDep,
|
|
158
|
+
// ): { evoluReactNativeDeps: EvoluDeps; localAuth: LocalAuth } => ({
|
|
159
|
+
// evoluReactNativeDeps: createSharedEvoluDeps({
|
|
160
|
+
// ...deps,
|
|
161
|
+
// reloadApp,
|
|
162
|
+
// }),
|
|
163
|
+
// localAuth,
|
|
164
|
+
// });
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { ReloadApp } from "@evolu/common
|
|
10
|
-
import { DevSettings } from "react-native";
|
|
11
|
-
import { SensitiveInfo } from "react-native-sensitive-info";
|
|
12
|
-
import { createSharedEvoluDeps, createSharedLocalAuth } from "../shared.js";
|
|
13
|
-
import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.js";
|
|
14
|
-
|
|
15
|
-
const reloadApp: ReloadApp = () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
// /**
|
|
2
|
+
// * Public entry point for bare React Native with OP-SQLite. Exported as
|
|
3
|
+
// * "@evolu/react-native/bare-op-sqlite" in package.json.
|
|
4
|
+
// *
|
|
5
|
+
// * Use this with bare React Native projects (not Expo) that use
|
|
6
|
+
// * `@op-engineering/op-sqlite`.
|
|
7
|
+
// */
|
|
8
|
+
//
|
|
9
|
+
// import { type ReloadApp } from "@evolu/common";
|
|
10
|
+
// import { DevSettings } from "react-native";
|
|
11
|
+
// import { SensitiveInfo } from "react-native-sensitive-info";
|
|
12
|
+
// import { createSharedEvoluDeps, createSharedLocalAuth } from "../shared.js";
|
|
13
|
+
// import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.js";
|
|
14
|
+
//
|
|
15
|
+
// const reloadApp: ReloadApp = () => {
|
|
16
|
+
// if (process.env.NODE_ENV === "development") {
|
|
17
|
+
// DevSettings.reload();
|
|
18
|
+
// } else {
|
|
19
|
+
// // TODO: reload not implemented for bare rn
|
|
20
|
+
// }
|
|
21
|
+
// };
|
|
22
|
+
//
|
|
23
|
+
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
24
|
+
// export const evoluReactNativeDeps = createSharedEvoluDeps({
|
|
25
|
+
// createSqliteDriver: createOpSqliteDriver,
|
|
26
|
+
// reloadApp,
|
|
27
|
+
// });
|
|
28
|
+
//
|
|
29
|
+
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
30
|
+
// export const localAuth = createSharedLocalAuth(SensitiveInfo);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { createExpoDeps } from "../createExpoDeps.js";
|
|
10
|
-
import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
// /**
|
|
2
|
+
// * Public entry point for Expo with OP-SQLite. Exported as
|
|
3
|
+
// * "@evolu/react-native/expo-op-sqlite" in package.json.
|
|
4
|
+
// *
|
|
5
|
+
// * Use this with Expo projects that use `@op-engineering/op-sqlite` for better
|
|
6
|
+
// * performance.
|
|
7
|
+
// */
|
|
8
|
+
//
|
|
9
|
+
// import { createExpoDeps } from "../createExpoDeps.js";
|
|
10
|
+
// import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.js";
|
|
11
|
+
//
|
|
12
|
+
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
13
|
+
// export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
14
|
+
// createSqliteDriver: createOpSqliteDriver,
|
|
15
|
+
// });
|
|
@@ -5,9 +5,26 @@
|
|
|
5
5
|
* Use this with Expo projects that use expo-sqlite.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import type { ConsoleDep } from "@evolu/common";
|
|
9
|
+
import type { EvoluDeps } from "@evolu/common/local-first";
|
|
10
|
+
import * as Expo from "expo";
|
|
11
|
+
import { createEvoluDeps as createSharedEvoluDeps } from "../shared.js";
|
|
9
12
|
import { createExpoSqliteDriver } from "../sqlite-drivers/createExpoSqliteDriver.js";
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
/** Creates Evolu dependencies for Expo. */
|
|
15
|
+
export const createEvoluDeps = (deps: Partial<ConsoleDep> = {}): EvoluDeps =>
|
|
16
|
+
createSharedEvoluDeps({
|
|
17
|
+
...deps,
|
|
18
|
+
createSqliteDriver: createExpoSqliteDriver,
|
|
19
|
+
reloadApp: () => {
|
|
20
|
+
void Expo.reloadAppAsync();
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// import { createExpoDeps } from "../createExpoDeps.js";
|
|
25
|
+
// import { createExpoSqliteDriver } from "../sqlite-drivers/createExpoSqliteDriver.js";
|
|
26
|
+
//
|
|
27
|
+
// // eslint-disable-next-line evolu/require-pure-annotation
|
|
28
|
+
// export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
29
|
+
// createSqliteDriver: createExpoSqliteDriver,
|
|
30
|
+
// });
|
package/src/index.ts
CHANGED
package/src/shared.ts
CHANGED
|
@@ -1,63 +1,129 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createConsole,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
createConsoleStoreOutput,
|
|
4
|
+
createBroadcastChannel,
|
|
5
|
+
createMessageChannel,
|
|
6
|
+
createMessagePort,
|
|
5
7
|
createRandomBytes,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
createRun,
|
|
9
|
+
createSharedWorker,
|
|
8
10
|
createWebSocket,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
createWorker,
|
|
12
|
+
type ConsoleDep,
|
|
13
|
+
type CreateSqliteDriverDep,
|
|
14
|
+
type ReloadAppDep,
|
|
11
15
|
} from "@evolu/common";
|
|
12
|
-
import {
|
|
13
|
-
|
|
16
|
+
import type {
|
|
17
|
+
CreateDbWorker,
|
|
18
|
+
DbWorker,
|
|
19
|
+
DbWorkerInit,
|
|
14
20
|
EvoluDeps,
|
|
15
|
-
|
|
21
|
+
SharedWorkerInput,
|
|
22
|
+
SharedWorkerOutput,
|
|
23
|
+
} from "@evolu/common/local-first";
|
|
24
|
+
import {
|
|
25
|
+
createEvoluDeps as createCommonEvoluDeps,
|
|
26
|
+
initSharedWorker,
|
|
27
|
+
startDbWorker,
|
|
16
28
|
} from "@evolu/common/local-first";
|
|
29
|
+
import { lockManager } from "./LockManager.js";
|
|
17
30
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
/** Creates Evolu dependencies for React Native. */
|
|
32
|
+
export const createEvoluDeps = (
|
|
33
|
+
deps: ReloadAppDep & CreateSqliteDriverDep & Partial<ConsoleDep>,
|
|
34
|
+
): EvoluDeps => {
|
|
35
|
+
// Worker-side Run lives as long as the app. When RN supports real workers,
|
|
36
|
+
// this moves to the worker entry point (like web's Worker.worker.ts).
|
|
37
|
+
const createWorkerRun = () => {
|
|
38
|
+
const consoleStoreOutput = createConsoleStoreOutput();
|
|
39
|
+
const workerConsole = createConsole({
|
|
40
|
+
output: consoleStoreOutput,
|
|
41
|
+
...(deps.console && { level: deps.console.getLevel() }),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return createRun({
|
|
45
|
+
console: workerConsole,
|
|
46
|
+
consoleStoreOutputEntry: consoleStoreOutput.entry,
|
|
47
|
+
createBroadcastChannel,
|
|
48
|
+
createMessageChannel,
|
|
49
|
+
createMessagePort,
|
|
50
|
+
createWebSocket,
|
|
51
|
+
createSqliteDriver: deps.createSqliteDriver,
|
|
52
|
+
lockManager,
|
|
53
|
+
randomBytes: createRandomBytes(),
|
|
30
54
|
});
|
|
31
|
-
return { promise, resolve, reject };
|
|
32
55
|
};
|
|
33
|
-
}
|
|
34
56
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const
|
|
57
|
+
const createDbWorker: CreateDbWorker = (): DbWorker =>
|
|
58
|
+
createWorker<DbWorkerInit, never>((self) => {
|
|
59
|
+
const dbWorkerRun = createWorkerRun();
|
|
60
|
+
dbWorkerRun(startDbWorker(self));
|
|
61
|
+
});
|
|
38
62
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
...deps,
|
|
47
|
-
console,
|
|
48
|
-
createWebSocket,
|
|
49
|
-
random: createRandom(),
|
|
50
|
-
randomBytes,
|
|
51
|
-
time,
|
|
52
|
-
}),
|
|
53
|
-
randomBytes,
|
|
54
|
-
time,
|
|
55
|
-
});
|
|
63
|
+
const sharedWorker = createSharedWorker<
|
|
64
|
+
SharedWorkerInput,
|
|
65
|
+
SharedWorkerOutput
|
|
66
|
+
>((self) => {
|
|
67
|
+
const sharedWorkerRun = createWorkerRun();
|
|
68
|
+
sharedWorkerRun(initSharedWorker(self));
|
|
69
|
+
});
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
return createCommonEvoluDeps({
|
|
72
|
+
...deps,
|
|
73
|
+
createDbWorker,
|
|
74
|
+
createBroadcastChannel,
|
|
75
|
+
createMessageChannel,
|
|
76
|
+
lockManager,
|
|
77
|
+
reloadApp: deps.reloadApp,
|
|
78
|
+
sharedWorker,
|
|
63
79
|
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// TODO: Reimplement local auth for React Native from scratch.
|
|
83
|
+
// export const createSharedLocalAuth = (
|
|
84
|
+
// secureStorage: SecureStorage,
|
|
85
|
+
// ): LocalAuth =>
|
|
86
|
+
// createLocalAuth({
|
|
87
|
+
// randomBytes,
|
|
88
|
+
// secureStorage,
|
|
89
|
+
// });
|
|
90
|
+
|
|
91
|
+
// import {
|
|
92
|
+
// createConsole,
|
|
93
|
+
// createLocalAuth,
|
|
94
|
+
// createRandomBytes,
|
|
95
|
+
// type CreateSqliteDriverDep,
|
|
96
|
+
// type LocalAuth,
|
|
97
|
+
// type ReloadAppDep,
|
|
98
|
+
// type SecureStorage,
|
|
99
|
+
// } from "@evolu/common";
|
|
100
|
+
// import type {
|
|
101
|
+
// // createDbWorkerForPlatform,
|
|
102
|
+
// // createDbWorkerForPlatform,
|
|
103
|
+
// EvoluDeps,
|
|
104
|
+
// } from "@evolu/common/local-first";
|
|
105
|
+
//
|
|
106
|
+
// const _console = createConsole();
|
|
107
|
+
// const randomBytes = createRandomBytes();
|
|
108
|
+
//
|
|
109
|
+
// export const createSharedEvoluDeps = (
|
|
110
|
+
// _deps: CreateSqliteDriverDep & ReloadAppDep,
|
|
111
|
+
// ): EvoluDeps => {
|
|
112
|
+
// throw new Error("todo");
|
|
113
|
+
// };
|
|
114
|
+
//
|
|
115
|
+
// ({
|
|
116
|
+
// ...deps,
|
|
117
|
+
// console,
|
|
118
|
+
// sharedWorker: "TODO" as never,
|
|
119
|
+
// // createDbWorker: () =>
|
|
120
|
+
// // createDbWorkerForPlatform({
|
|
121
|
+
// // ...deps,
|
|
122
|
+
// // console,
|
|
123
|
+
// // createWebSocket,
|
|
124
|
+
// // random: createRandom(),
|
|
125
|
+
// // randomBytes,
|
|
126
|
+
// // time: createTime(),
|
|
127
|
+
// // }),
|
|
128
|
+
// randomBytes,
|
|
129
|
+
// });
|