@evolu/react-native 13.0.0 → 14.1.0
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/components/EvoluIdenticon.d.ts +9 -0
- package/dist/components/EvoluIdenticon.d.ts.map +1 -0
- package/dist/components/EvoluIdenticon.js +14 -0
- package/dist/createExpoDeps.d.ts +7 -0
- package/dist/createExpoDeps.d.ts.map +1 -0
- package/dist/createExpoDeps.js +123 -0
- package/dist/exports/bare-op-sqlite.d.ts +10 -0
- package/dist/exports/bare-op-sqlite.d.ts.map +1 -0
- package/dist/exports/bare-op-sqlite.js +24 -0
- package/dist/exports/expo-op-sqlite.d.ts +9 -0
- package/dist/exports/expo-op-sqlite.d.ts.map +1 -0
- package/dist/exports/expo-op-sqlite.js +12 -0
- package/dist/exports/expo-sqlite.d.ts +8 -0
- package/dist/exports/expo-sqlite.d.ts.map +1 -0
- package/dist/exports/expo-sqlite.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/shared.d.ts +5 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +39 -0
- package/dist/{providers/ExpoSqliteDriver.d.ts → sqlite-drivers/createExpoSqliteDriver.d.ts} +1 -1
- package/dist/sqlite-drivers/createExpoSqliteDriver.d.ts.map +1 -0
- package/dist/{providers/ExpoSqliteDriver.js → sqlite-drivers/createExpoSqliteDriver.js} +10 -3
- package/dist/{providers/OpSqliteDriver.d.ts → sqlite-drivers/createOpSqliteDriver.d.ts} +1 -1
- package/dist/sqlite-drivers/createOpSqliteDriver.d.ts.map +1 -0
- package/dist/{providers/OpSqliteDriver.js → sqlite-drivers/createOpSqliteDriver.js} +11 -3
- package/package.json +62 -24
- package/src/components/EvoluIdenticon.tsx +25 -0
- package/src/createExpoDeps.ts +162 -0
- package/src/exports/bare-op-sqlite.ts +28 -0
- package/src/exports/expo-op-sqlite.ts +14 -0
- package/src/exports/expo-sqlite.ts +13 -0
- package/src/index.ts +1 -0
- package/src/shared.ts +63 -0
- package/src/{providers/ExpoSqliteDriver.ts → sqlite-drivers/createExpoSqliteDriver.ts} +12 -3
- package/src/{providers/OpSqliteDriver.ts → sqlite-drivers/createOpSqliteDriver.ts} +14 -4
- package/dist/expo-sqlite.d.ts +0 -4
- package/dist/expo-sqlite.d.ts.map +0 -1
- package/dist/expo-sqlite.js +0 -31
- package/dist/op-sqlite.d.ts +0 -4
- package/dist/op-sqlite.d.ts.map +0 -1
- package/dist/op-sqlite.js +0 -36
- package/dist/providers/ExpoSqliteDriver.d.ts.map +0 -1
- package/dist/providers/OpSqliteDriver.d.ts.map +0 -1
- package/dist/utils/Hermes.d.ts +0 -3
- package/dist/utils/Hermes.d.ts.map +0 -1
- package/dist/utils/Hermes.js +0 -14
- package/src/expo-sqlite.ts +0 -53
- package/src/op-sqlite.ts +0 -56
- package/src/utils/Hermes.ts +0 -14
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IdenticonStyle, OwnerId } from "@evolu/common";
|
|
2
|
+
import { FC } from "react";
|
|
3
|
+
export declare const EvoluIdenticon: FC<{
|
|
4
|
+
id: OwnerId;
|
|
5
|
+
size?: number;
|
|
6
|
+
borderRadius?: number;
|
|
7
|
+
style?: IdenticonStyle;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=EvoluIdenticon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvoluIdenticon.d.ts","sourceRoot":"","sources":["../../src/components/EvoluIdenticon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,EAAE,EAAW,MAAM,OAAO,CAAC;AAIpC,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB,CAcA,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createIdenticon } from "@evolu/common";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { View } from "react-native";
|
|
5
|
+
import { SvgXml } from "react-native-svg";
|
|
6
|
+
export const EvoluIdenticon = ({ id, size = 32, borderRadius = 3, style }) => {
|
|
7
|
+
const svg = useMemo(() => createIdenticon(id, style), [id, style]);
|
|
8
|
+
return id ? (_jsx(View, { style: {
|
|
9
|
+
width: size,
|
|
10
|
+
height: size,
|
|
11
|
+
borderRadius,
|
|
12
|
+
overflow: "hidden",
|
|
13
|
+
}, children: _jsx(SvgXml, { xml: svg, width: size, height: size }) })) : null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CreateSqliteDriverDep, LocalAuth } from "@evolu/common";
|
|
2
|
+
import { EvoluDeps } from "@evolu/common/evolu";
|
|
3
|
+
export declare const createExpoDeps: (deps: CreateSqliteDriverDep) => {
|
|
4
|
+
evoluReactNativeDeps: EvoluDeps;
|
|
5
|
+
localAuth: LocalAuth;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=createExpoDeps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createExpoDeps.d.ts","sourceRoot":"","sources":["../src/createExpoDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,SAAS,EAAa,MAAM,qBAAqB,CAAC;AAwJ3D,eAAO,MAAM,cAAc,GACzB,MAAM,qBAAqB,KAC1B;IAAE,oBAAoB,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAMxD,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as Expo from "expo";
|
|
2
|
+
import { createSharedEvoluDeps, createSharedLocalAuth } from "./shared.js";
|
|
3
|
+
import { localAuthDefaultOptions } from "@evolu/common";
|
|
4
|
+
import * as SecureStore from "expo-secure-store";
|
|
5
|
+
import KVStore from "expo-sqlite/kv-store";
|
|
6
|
+
const reloadApp = () => {
|
|
7
|
+
void Expo.reloadAppAsync();
|
|
8
|
+
};
|
|
9
|
+
const createSecureStore = () => {
|
|
10
|
+
const store = {
|
|
11
|
+
setItem: async (key, value, options) => {
|
|
12
|
+
const rnsiOpts = convertOptions(options);
|
|
13
|
+
const service = options?.service ?? "default";
|
|
14
|
+
const metadata = createMetadata(options?.accessControl === "none");
|
|
15
|
+
await KVStore.setItem(`${service}-${key}`, "1");
|
|
16
|
+
await SecureStore.setItemAsync(key, JSON.stringify({ value, metadata }), rnsiOpts);
|
|
17
|
+
return { metadata };
|
|
18
|
+
},
|
|
19
|
+
getItem: async (key, options) => {
|
|
20
|
+
const rnsiOpts = convertOptions(options);
|
|
21
|
+
const service = options?.service ?? "default";
|
|
22
|
+
let data;
|
|
23
|
+
try {
|
|
24
|
+
const result = await SecureStore.getItemAsync(key, rnsiOpts);
|
|
25
|
+
if (!result)
|
|
26
|
+
return null;
|
|
27
|
+
data = JSON.parse(result);
|
|
28
|
+
}
|
|
29
|
+
catch (_error) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return { key, service, ...data };
|
|
33
|
+
},
|
|
34
|
+
deleteItem: async (key, options) => {
|
|
35
|
+
const rnsiOpts = convertOptions(options);
|
|
36
|
+
const service = options?.service ?? "default";
|
|
37
|
+
await Promise.all([
|
|
38
|
+
KVStore.removeItemAsync(`${service}-${key}`),
|
|
39
|
+
SecureStore.deleteItemAsync(key, rnsiOpts),
|
|
40
|
+
]);
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
getAllItems: async (options) => {
|
|
44
|
+
const keys = await KVStore.getAllKeysAsync();
|
|
45
|
+
const service = options?.service ?? "default";
|
|
46
|
+
const metadata = createMetadata(options?.accessControl === "none");
|
|
47
|
+
return keys
|
|
48
|
+
.filter((key) => key.startsWith(`${service}-`))
|
|
49
|
+
.map((key) => ({
|
|
50
|
+
key: key.slice(service.length + 1),
|
|
51
|
+
service,
|
|
52
|
+
metadata,
|
|
53
|
+
}));
|
|
54
|
+
},
|
|
55
|
+
clearService: async (options) => {
|
|
56
|
+
const rnsiOpts = convertOptions(options);
|
|
57
|
+
const service = options?.service ?? "default";
|
|
58
|
+
const items = await store.getAllItems(options);
|
|
59
|
+
await KVStore.multiRemove(items.map((item) => `${service}-${item.key}`));
|
|
60
|
+
await Promise.all(items.map(async (item) => {
|
|
61
|
+
await SecureStore.deleteItemAsync(item.key, rnsiOpts);
|
|
62
|
+
}));
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
return store;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Create default metadata for backwards compatibility with items that don't
|
|
69
|
+
* have stored metadata.
|
|
70
|
+
*/
|
|
71
|
+
const createMetadata = (isSecure = true) => {
|
|
72
|
+
return {
|
|
73
|
+
backend: "keychain",
|
|
74
|
+
accessControl: isSecure ? "biometryCurrentSet" : "none",
|
|
75
|
+
securityLevel: isSecure ? "biometry" : "software",
|
|
76
|
+
timestamp: Date.now(),
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
function convertOptions(options) {
|
|
80
|
+
const accessGroup = options?.keychainGroup ?? localAuthDefaultOptions.keychainGroup ?? "";
|
|
81
|
+
const keychainService = options?.service ?? localAuthDefaultOptions.service ?? "";
|
|
82
|
+
const keychainAccessible = convertKeychainAccessible(options?.accessControl ??
|
|
83
|
+
localAuthDefaultOptions.accessControl ??
|
|
84
|
+
"biometryCurrentSet");
|
|
85
|
+
const authenticationPrompt = options?.authenticationPrompt?.title ??
|
|
86
|
+
localAuthDefaultOptions.authenticationPrompt?.title ??
|
|
87
|
+
"";
|
|
88
|
+
return {
|
|
89
|
+
accessGroup,
|
|
90
|
+
keychainService,
|
|
91
|
+
keychainAccessible,
|
|
92
|
+
authenticationPrompt,
|
|
93
|
+
requireAuthentication: options?.accessControl !== "none",
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function convertKeychainAccessible(accessControl) {
|
|
97
|
+
switch (accessControl) {
|
|
98
|
+
case "none":
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
100
|
+
return SecureStore.ALWAYS;
|
|
101
|
+
case "biometryCurrentSet":
|
|
102
|
+
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
103
|
+
case "biometryAny":
|
|
104
|
+
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
105
|
+
case "devicePasscode":
|
|
106
|
+
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
107
|
+
case "secureEnclaveBiometry":
|
|
108
|
+
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
109
|
+
// Exhaustive check
|
|
110
|
+
default:
|
|
111
|
+
accessControl;
|
|
112
|
+
// Default (for typescript, should never hit)
|
|
113
|
+
return SecureStore.AFTER_FIRST_UNLOCK;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const localAuth = createSharedLocalAuth(createSecureStore());
|
|
117
|
+
export const createExpoDeps = (deps) => ({
|
|
118
|
+
evoluReactNativeDeps: createSharedEvoluDeps({
|
|
119
|
+
...deps,
|
|
120
|
+
reloadApp,
|
|
121
|
+
}),
|
|
122
|
+
localAuth,
|
|
123
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export declare const evoluReactNativeDeps: import("@evolu/common").EvoluDeps;
|
|
9
|
+
export declare const localAuth: import("@evolu/common").LocalAuth;
|
|
10
|
+
//# sourceMappingURL=bare-op-sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bare-op-sqlite.d.ts","sourceRoot":"","sources":["../../src/exports/bare-op-sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,eAAO,MAAM,oBAAoB,mCAG/B,CAAC;AAEH,eAAO,MAAM,SAAS,mCAAuC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
import { DevSettings } from "react-native";
|
|
9
|
+
import { SensitiveInfo } from "react-native-sensitive-info";
|
|
10
|
+
import { createSharedEvoluDeps, createSharedLocalAuth } from "../shared.js";
|
|
11
|
+
import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.js";
|
|
12
|
+
const reloadApp = () => {
|
|
13
|
+
if (process.env.NODE_ENV === "development") {
|
|
14
|
+
DevSettings.reload();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// TODO: reload not implemented for bare rn
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const evoluReactNativeDeps = createSharedEvoluDeps({
|
|
21
|
+
createSqliteDriver: createOpSqliteDriver,
|
|
22
|
+
reloadApp,
|
|
23
|
+
});
|
|
24
|
+
export const localAuth = createSharedLocalAuth(SensitiveInfo);
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export declare const evoluReactNativeDeps: import("@evolu/common").EvoluDeps, localAuth: import("@evolu/common").LocalAuth;
|
|
9
|
+
//# sourceMappingURL=expo-op-sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo-op-sqlite.d.ts","sourceRoot":"","sources":["../../src/exports/expo-op-sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,eAAO,MAAQ,oBAAoB,qCAAE,SAAS,mCAE5C,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
import { createExpoDeps } from "../createExpoDeps.js";
|
|
9
|
+
import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.js";
|
|
10
|
+
export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
11
|
+
createSqliteDriver: createOpSqliteDriver,
|
|
12
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point for Expo SQLite. Exported as
|
|
3
|
+
* "@evolu/react-native/expo-sqlite" in package.json.
|
|
4
|
+
*
|
|
5
|
+
* Use this with Expo projects that use expo-sqlite.
|
|
6
|
+
*/
|
|
7
|
+
export declare const evoluReactNativeDeps: import("@evolu/common").EvoluDeps, localAuth: import("@evolu/common").LocalAuth;
|
|
8
|
+
//# sourceMappingURL=expo-sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo-sqlite.d.ts","sourceRoot":"","sources":["../../src/exports/expo-sqlite.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,eAAO,MAAQ,oBAAoB,qCAAE,SAAS,mCAE5C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point for Expo SQLite. Exported as
|
|
3
|
+
* "@evolu/react-native/expo-sqlite" in package.json.
|
|
4
|
+
*
|
|
5
|
+
* Use this with Expo projects that use expo-sqlite.
|
|
6
|
+
*/
|
|
7
|
+
import { createExpoDeps } from "../createExpoDeps.js";
|
|
8
|
+
import { createExpoSqliteDriver } from "../sqlite-drivers/createExpoSqliteDriver.js";
|
|
9
|
+
export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
10
|
+
createSqliteDriver: createExpoSqliteDriver,
|
|
11
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./components/EvoluIdenticon.js";
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CreateSqliteDriverDep, LocalAuth, SecureStorage } from "@evolu/common";
|
|
2
|
+
import { EvoluDeps, ReloadAppDep } from "@evolu/common/evolu";
|
|
3
|
+
export declare const createSharedEvoluDeps: (deps: CreateSqliteDriverDep & ReloadAppDep) => EvoluDeps;
|
|
4
|
+
export declare const createSharedLocalAuth: (secureStorage: SecureStorage) => LocalAuth;
|
|
5
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,qBAAqB,EAGrB,SAAS,EACT,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,SAAS,EACT,YAAY,EACb,MAAM,qBAAqB,CAAC;AAuB7B,eAAO,MAAM,qBAAqB,GAChC,MAAM,qBAAqB,GAAG,YAAY,KACzC,SAcD,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAChC,eAAe,aAAa,KAC3B,SAIC,CAAC"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createConsole, createLocalAuth, createRandom, createRandomBytes, createTime, createWebSocket, } from "@evolu/common";
|
|
2
|
+
import { createDbWorkerForPlatform, } from "@evolu/common/evolu";
|
|
3
|
+
/**
|
|
4
|
+
* Polyfills `Promise.withResolvers`.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/facebook/hermes/pull/1452
|
|
7
|
+
*/
|
|
8
|
+
if (typeof Promise.withResolvers === "undefined") {
|
|
9
|
+
// @ts-expect-error This is OK.
|
|
10
|
+
Promise.withResolvers = function () {
|
|
11
|
+
let resolve, reject;
|
|
12
|
+
const promise = new Promise((res, rej) => {
|
|
13
|
+
resolve = res;
|
|
14
|
+
reject = rej;
|
|
15
|
+
});
|
|
16
|
+
return { promise, resolve, reject };
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const console = createConsole();
|
|
20
|
+
const randomBytes = createRandomBytes();
|
|
21
|
+
const time = createTime();
|
|
22
|
+
export const createSharedEvoluDeps = (deps) => ({
|
|
23
|
+
...deps,
|
|
24
|
+
console,
|
|
25
|
+
createDbWorker: () => createDbWorkerForPlatform({
|
|
26
|
+
...deps,
|
|
27
|
+
console,
|
|
28
|
+
createWebSocket,
|
|
29
|
+
random: createRandom(),
|
|
30
|
+
randomBytes,
|
|
31
|
+
time,
|
|
32
|
+
}),
|
|
33
|
+
randomBytes,
|
|
34
|
+
time,
|
|
35
|
+
});
|
|
36
|
+
export const createSharedLocalAuth = (secureStorage) => createLocalAuth({
|
|
37
|
+
randomBytes,
|
|
38
|
+
secureStorage,
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createExpoSqliteDriver.d.ts","sourceRoot":"","sources":["../../src/sqlite-drivers/createExpoSqliteDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAGnB,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,sBAAsB,EAAE,kBAwDpC,CAAC"}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { createPreparedStatementsCache, } from "@evolu/common";
|
|
1
|
+
import { bytesToHex, createPreparedStatementsCache, } from "@evolu/common";
|
|
2
2
|
import { openDatabaseSync } from "expo-sqlite";
|
|
3
|
-
export const createExpoSqliteDriver = (name) => {
|
|
4
|
-
const db = openDatabaseSync(`evolu1-${name}.db`);
|
|
3
|
+
export const createExpoSqliteDriver = (name, options) => {
|
|
4
|
+
const db = openDatabaseSync(options?.memory ? ":memory:" : `evolu1-${name}.db`);
|
|
5
|
+
if (options?.encryptionKey) {
|
|
6
|
+
db.execSync(`
|
|
7
|
+
PRAGMA cipher = 'sqlcipher';
|
|
8
|
+
PRAGMA legacy = 4;
|
|
9
|
+
PRAGMA key = "x'${bytesToHex(options.encryptionKey)}'";
|
|
10
|
+
`);
|
|
11
|
+
}
|
|
5
12
|
let isDisposed = false;
|
|
6
13
|
const cache = createPreparedStatementsCache((sql) => db.prepareSync(sql), (statement) => {
|
|
7
14
|
statement.finalizeSync();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOpSqliteDriver.d.ts","sourceRoot":"","sources":["../../src/sqlite-drivers/createOpSqliteDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAInB,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,oBAAoB,EAAE,kBA8DlC,CAAC"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { constVoid, createPreparedStatementsCache, isSqlMutation, } from "@evolu/common";
|
|
1
|
+
import { bytesToHex, constVoid, createPreparedStatementsCache, isSqlMutation, } from "@evolu/common";
|
|
2
2
|
import { open } from "@op-engineering/op-sqlite";
|
|
3
|
-
export const createOpSqliteDriver = (name) => {
|
|
4
|
-
|
|
3
|
+
export const createOpSqliteDriver = (name, options) => {
|
|
4
|
+
// https://op-engineering.github.io/op-sqlite/docs/configuration#in-memory
|
|
5
|
+
const db = open(options?.memory
|
|
6
|
+
? { name: `inMemoryDb`, location: ":memory:" }
|
|
7
|
+
: {
|
|
8
|
+
name: `evolu1-${name}.db`,
|
|
9
|
+
...(options?.encryptionKey && {
|
|
10
|
+
encryptionKey: `x'${bytesToHex(options.encryptionKey)}'`,
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
5
13
|
let isDisposed = false;
|
|
6
14
|
const cache = createPreparedStatementsCache((sql) => db.prepareStatement(sql),
|
|
7
15
|
// op-sqlite doesn't have API for that
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evolu/react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.1.0",
|
|
4
4
|
"description": "Evolu for React Native and Expo",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"evolu",
|
|
@@ -19,26 +19,43 @@
|
|
|
19
19
|
"homepage": "https://evolu.dev",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js",
|
|
25
|
+
"react-native": "./dist/index.js"
|
|
26
|
+
},
|
|
22
27
|
"./expo-sqlite": {
|
|
23
|
-
"types": "./dist/expo-sqlite.d.ts",
|
|
24
|
-
"default": "./dist/expo-sqlite.js",
|
|
25
|
-
"react-native": "./dist/expo-sqlite.js",
|
|
28
|
+
"types": "./dist/exports/expo-sqlite.d.ts",
|
|
29
|
+
"default": "./dist/exports/expo-sqlite.js",
|
|
30
|
+
"react-native": "./dist/exports/expo-sqlite.js",
|
|
31
|
+
"browser": "./dist/web.js"
|
|
32
|
+
},
|
|
33
|
+
"./expo-op-sqlite": {
|
|
34
|
+
"types": "./dist/exports/expo-op-sqlite.d.ts",
|
|
35
|
+
"default": "./dist/exports/expo-op-sqlite.js",
|
|
36
|
+
"react-native": "./dist/exports/expo-op-sqlite.js",
|
|
26
37
|
"browser": "./dist/web.js"
|
|
27
38
|
},
|
|
28
|
-
"./op-sqlite": {
|
|
29
|
-
"types": "./dist/op-sqlite.d.ts",
|
|
30
|
-
"default": "./dist/op-sqlite.js",
|
|
31
|
-
"react-native": "./dist/op-sqlite.js",
|
|
39
|
+
"./bare-op-sqlite": {
|
|
40
|
+
"types": "./dist/exports/bare-op-sqlite.d.ts",
|
|
41
|
+
"default": "./dist/exports/bare-op-sqlite.js",
|
|
42
|
+
"react-native": "./dist/exports/bare-op-sqlite.js",
|
|
32
43
|
"browser": "./dist/web.js"
|
|
33
44
|
}
|
|
34
45
|
},
|
|
35
46
|
"typesVersions": {
|
|
36
47
|
"*": {
|
|
48
|
+
".": [
|
|
49
|
+
"./dist/index.d.ts"
|
|
50
|
+
],
|
|
37
51
|
"expo-sqlite": [
|
|
38
|
-
"./dist/expo-sqlite.d.ts"
|
|
52
|
+
"./dist/exports/expo-sqlite.d.ts"
|
|
39
53
|
],
|
|
40
|
-
"op-sqlite": [
|
|
41
|
-
"./dist/op-sqlite.d.ts"
|
|
54
|
+
"expo-op-sqlite": [
|
|
55
|
+
"./dist/exports/expo-op-sqlite.d.ts"
|
|
56
|
+
],
|
|
57
|
+
"bare-op-sqlite": [
|
|
58
|
+
"./dist/exports/bare-op-sqlite.d.ts"
|
|
42
59
|
]
|
|
43
60
|
}
|
|
44
61
|
},
|
|
@@ -48,23 +65,32 @@
|
|
|
48
65
|
"README.md"
|
|
49
66
|
],
|
|
50
67
|
"devDependencies": {
|
|
51
|
-
"@op-engineering/op-sqlite": "^
|
|
52
|
-
"expo": "^
|
|
53
|
-
"expo-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
68
|
+
"@op-engineering/op-sqlite": "^15.0.3",
|
|
69
|
+
"expo": "^54.0.10",
|
|
70
|
+
"expo-secure-store": "~15.0.7",
|
|
71
|
+
"expo-sqlite": "~16.0.8",
|
|
72
|
+
"react-native": "^0.81.4",
|
|
73
|
+
"react-native-nitro-modules": "^0.31.2",
|
|
74
|
+
"react-native-sensitive-info": "^6.0.0-rc.8",
|
|
75
|
+
"react-native-svg": "^15.14.0",
|
|
76
|
+
"shx": "^0.4.0",
|
|
77
|
+
"typescript": "^5.9.2",
|
|
78
|
+
"vitest": "^4.0.4",
|
|
79
|
+
"@evolu/common": "7.2.0",
|
|
80
|
+
"@evolu/react": "10.2.0",
|
|
59
81
|
"@evolu/tsconfig": "0.0.2"
|
|
60
82
|
},
|
|
61
83
|
"peerDependencies": {
|
|
62
|
-
"@evolu/common": "^
|
|
63
|
-
"@evolu/react": "^
|
|
84
|
+
"@evolu/common": "^7.2.0",
|
|
85
|
+
"@evolu/react": "^10.2.0",
|
|
64
86
|
"@op-engineering/op-sqlite": ">=12",
|
|
65
|
-
"expo": ">=
|
|
66
|
-
"expo-
|
|
67
|
-
"
|
|
87
|
+
"expo": ">=54",
|
|
88
|
+
"expo-secure-store": ">=15",
|
|
89
|
+
"expo-sqlite": ">=16",
|
|
90
|
+
"react-native": ">=0.81",
|
|
91
|
+
"react-native-nitro-modules": ">=0.31",
|
|
92
|
+
"react-native-sensitive-info": ">=6",
|
|
93
|
+
"react-native-svg": ">=15"
|
|
68
94
|
},
|
|
69
95
|
"peerDependenciesMeta": {
|
|
70
96
|
"@op-engineering/op-sqlite": {
|
|
@@ -75,6 +101,18 @@
|
|
|
75
101
|
},
|
|
76
102
|
"expo-sqlite": {
|
|
77
103
|
"optional": true
|
|
104
|
+
},
|
|
105
|
+
"expo-secure-store": {
|
|
106
|
+
"optional": true
|
|
107
|
+
},
|
|
108
|
+
"react-native-nitro-modules": {
|
|
109
|
+
"optional": true
|
|
110
|
+
},
|
|
111
|
+
"react-native-sensitive-info": {
|
|
112
|
+
"optional": true
|
|
113
|
+
},
|
|
114
|
+
"react-native-svg": {
|
|
115
|
+
"optional": true
|
|
78
116
|
}
|
|
79
117
|
},
|
|
80
118
|
"publishConfig": {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createIdenticon, IdenticonStyle, OwnerId } from "@evolu/common";
|
|
2
|
+
import { FC, useMemo } from "react";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import { SvgXml } from "react-native-svg";
|
|
5
|
+
|
|
6
|
+
export const EvoluIdenticon: FC<{
|
|
7
|
+
id: OwnerId;
|
|
8
|
+
size?: number;
|
|
9
|
+
borderRadius?: number;
|
|
10
|
+
style?: IdenticonStyle;
|
|
11
|
+
}> = ({ id, size = 32, borderRadius = 3, style }) => {
|
|
12
|
+
const svg = useMemo(() => createIdenticon(id, style), [id, style]);
|
|
13
|
+
return id ? (
|
|
14
|
+
<View
|
|
15
|
+
style={{
|
|
16
|
+
width: size,
|
|
17
|
+
height: size,
|
|
18
|
+
borderRadius,
|
|
19
|
+
overflow: "hidden",
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
<SvgXml xml={svg} width={size} height={size} />
|
|
23
|
+
</View>
|
|
24
|
+
) : null;
|
|
25
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { CreateSqliteDriverDep, LocalAuth } from "@evolu/common";
|
|
2
|
+
import { EvoluDeps, ReloadApp } from "@evolu/common/evolu";
|
|
3
|
+
import * as Expo from "expo";
|
|
4
|
+
import { createSharedEvoluDeps, createSharedLocalAuth } from "./shared.js";
|
|
5
|
+
import type {
|
|
6
|
+
AccessControl,
|
|
7
|
+
LocalAuthOptions,
|
|
8
|
+
SecureStorage,
|
|
9
|
+
SensitiveInfoItem,
|
|
10
|
+
StorageMetadata,
|
|
11
|
+
} from "@evolu/common";
|
|
12
|
+
import { localAuthDefaultOptions } from "@evolu/common";
|
|
13
|
+
import * as SecureStore from "expo-secure-store";
|
|
14
|
+
import KVStore from "expo-sqlite/kv-store";
|
|
15
|
+
|
|
16
|
+
const reloadApp: ReloadApp = () => {
|
|
17
|
+
void Expo.reloadAppAsync();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const createSecureStore = (): SecureStorage => {
|
|
21
|
+
const store: SecureStorage = {
|
|
22
|
+
setItem: async (key, value, options) => {
|
|
23
|
+
const rnsiOpts = convertOptions(options);
|
|
24
|
+
const service = options?.service ?? "default";
|
|
25
|
+
const metadata = createMetadata(options?.accessControl === "none");
|
|
26
|
+
await KVStore.setItem(`${service}-${key}`, "1");
|
|
27
|
+
await SecureStore.setItemAsync(
|
|
28
|
+
key,
|
|
29
|
+
JSON.stringify({ value, metadata }),
|
|
30
|
+
rnsiOpts,
|
|
31
|
+
);
|
|
32
|
+
return { metadata };
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
getItem: async (key, options) => {
|
|
36
|
+
const rnsiOpts = convertOptions(options);
|
|
37
|
+
const service = options?.service ?? "default";
|
|
38
|
+
let data: { value: string; metadata: StorageMetadata };
|
|
39
|
+
try {
|
|
40
|
+
const result = await SecureStore.getItemAsync(key, rnsiOpts);
|
|
41
|
+
if (!result) return null;
|
|
42
|
+
data = JSON.parse(result) as {
|
|
43
|
+
value: string;
|
|
44
|
+
metadata: StorageMetadata;
|
|
45
|
+
};
|
|
46
|
+
} catch (_error) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return { key, service, ...data };
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
deleteItem: async (key, options) => {
|
|
53
|
+
const rnsiOpts = convertOptions(options);
|
|
54
|
+
const service = options?.service ?? "default";
|
|
55
|
+
await Promise.all([
|
|
56
|
+
KVStore.removeItemAsync(`${service}-${key}`),
|
|
57
|
+
SecureStore.deleteItemAsync(key, rnsiOpts),
|
|
58
|
+
]);
|
|
59
|
+
return true;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
getAllItems: async (options) => {
|
|
63
|
+
const keys = await KVStore.getAllKeysAsync();
|
|
64
|
+
const service = options?.service ?? "default";
|
|
65
|
+
const metadata = createMetadata(options?.accessControl === "none");
|
|
66
|
+
return keys
|
|
67
|
+
.filter((key) => key.startsWith(`${service}-`))
|
|
68
|
+
.map((key) => ({
|
|
69
|
+
key: key.slice(service.length + 1),
|
|
70
|
+
service,
|
|
71
|
+
metadata,
|
|
72
|
+
}));
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
clearService: async (options) => {
|
|
76
|
+
const rnsiOpts = convertOptions(options);
|
|
77
|
+
const service = options?.service ?? "default";
|
|
78
|
+
const items = await store.getAllItems(options);
|
|
79
|
+
await KVStore.multiRemove(items.map((item) => `${service}-${item.key}`));
|
|
80
|
+
await Promise.all(
|
|
81
|
+
items.map(async (item) => {
|
|
82
|
+
await SecureStore.deleteItemAsync(item.key, rnsiOpts);
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return store;
|
|
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
|
+
});
|
|
@@ -0,0 +1,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 { ReloadApp } from "@evolu/common/evolu";
|
|
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
|
+
export const evoluReactNativeDeps = createSharedEvoluDeps({
|
|
24
|
+
createSqliteDriver: createOpSqliteDriver,
|
|
25
|
+
reloadApp,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const localAuth = createSharedLocalAuth(SensitiveInfo);
|
|
@@ -0,0 +1,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
|
+
export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
13
|
+
createSqliteDriver: createOpSqliteDriver,
|
|
14
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point for Expo SQLite. Exported as
|
|
3
|
+
* "@evolu/react-native/expo-sqlite" in package.json.
|
|
4
|
+
*
|
|
5
|
+
* Use this with Expo projects that use expo-sqlite.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createExpoDeps } from "../createExpoDeps.js";
|
|
9
|
+
import { createExpoSqliteDriver } from "../sqlite-drivers/createExpoSqliteDriver.js";
|
|
10
|
+
|
|
11
|
+
export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
|
|
12
|
+
createSqliteDriver: createExpoSqliteDriver,
|
|
13
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./components/EvoluIdenticon.js";
|
package/src/shared.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createConsole,
|
|
3
|
+
createLocalAuth,
|
|
4
|
+
createRandom,
|
|
5
|
+
createRandomBytes,
|
|
6
|
+
CreateSqliteDriverDep,
|
|
7
|
+
createTime,
|
|
8
|
+
createWebSocket,
|
|
9
|
+
LocalAuth,
|
|
10
|
+
SecureStorage,
|
|
11
|
+
} from "@evolu/common";
|
|
12
|
+
import {
|
|
13
|
+
createDbWorkerForPlatform,
|
|
14
|
+
EvoluDeps,
|
|
15
|
+
ReloadAppDep,
|
|
16
|
+
} from "@evolu/common/evolu";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Polyfills `Promise.withResolvers`.
|
|
20
|
+
*
|
|
21
|
+
* @see https://github.com/facebook/hermes/pull/1452
|
|
22
|
+
*/
|
|
23
|
+
if (typeof Promise.withResolvers === "undefined") {
|
|
24
|
+
// @ts-expect-error This is OK.
|
|
25
|
+
Promise.withResolvers = function () {
|
|
26
|
+
let resolve, reject;
|
|
27
|
+
const promise = new Promise((res, rej) => {
|
|
28
|
+
resolve = res;
|
|
29
|
+
reject = rej;
|
|
30
|
+
});
|
|
31
|
+
return { promise, resolve, reject };
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const console = createConsole();
|
|
36
|
+
const randomBytes = createRandomBytes();
|
|
37
|
+
const time = createTime();
|
|
38
|
+
|
|
39
|
+
export const createSharedEvoluDeps = (
|
|
40
|
+
deps: CreateSqliteDriverDep & ReloadAppDep,
|
|
41
|
+
): EvoluDeps => ({
|
|
42
|
+
...deps,
|
|
43
|
+
console,
|
|
44
|
+
createDbWorker: () =>
|
|
45
|
+
createDbWorkerForPlatform({
|
|
46
|
+
...deps,
|
|
47
|
+
console,
|
|
48
|
+
createWebSocket,
|
|
49
|
+
random: createRandom(),
|
|
50
|
+
randomBytes,
|
|
51
|
+
time,
|
|
52
|
+
}),
|
|
53
|
+
randomBytes,
|
|
54
|
+
time,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const createSharedLocalAuth = (
|
|
58
|
+
secureStorage: SecureStorage,
|
|
59
|
+
): LocalAuth =>
|
|
60
|
+
createLocalAuth({
|
|
61
|
+
randomBytes,
|
|
62
|
+
secureStorage,
|
|
63
|
+
});
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
+
bytesToHex,
|
|
2
3
|
createPreparedStatementsCache,
|
|
3
4
|
CreateSqliteDriver,
|
|
4
5
|
SqliteDriver,
|
|
5
6
|
SqliteRow,
|
|
6
7
|
} from "@evolu/common";
|
|
7
|
-
|
|
8
8
|
import { openDatabaseSync, SQLiteStatement } from "expo-sqlite";
|
|
9
9
|
|
|
10
|
-
export const createExpoSqliteDriver: CreateSqliteDriver = (name) => {
|
|
11
|
-
const db = openDatabaseSync(
|
|
10
|
+
export const createExpoSqliteDriver: CreateSqliteDriver = (name, options) => {
|
|
11
|
+
const db = openDatabaseSync(
|
|
12
|
+
options?.memory ? ":memory:" : `evolu1-${name}.db`,
|
|
13
|
+
);
|
|
14
|
+
if (options?.encryptionKey) {
|
|
15
|
+
db.execSync(`
|
|
16
|
+
PRAGMA cipher = 'sqlcipher';
|
|
17
|
+
PRAGMA legacy = 4;
|
|
18
|
+
PRAGMA key = "x'${bytesToHex(options.encryptionKey)}'";
|
|
19
|
+
`);
|
|
20
|
+
}
|
|
12
21
|
let isDisposed = false;
|
|
13
22
|
|
|
14
23
|
const cache = createPreparedStatementsCache<SQLiteStatement>(
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
+
bytesToHex,
|
|
2
3
|
constVoid,
|
|
3
4
|
createPreparedStatementsCache,
|
|
4
|
-
isSqlMutation,
|
|
5
5
|
CreateSqliteDriver,
|
|
6
|
+
isSqlMutation,
|
|
6
7
|
SqliteDriver,
|
|
7
8
|
SqliteRow,
|
|
8
9
|
} from "@evolu/common";
|
|
9
|
-
|
|
10
10
|
import { open, PreparedStatement } from "@op-engineering/op-sqlite";
|
|
11
11
|
|
|
12
|
-
export const createOpSqliteDriver: CreateSqliteDriver = (name) => {
|
|
13
|
-
|
|
12
|
+
export const createOpSqliteDriver: CreateSqliteDriver = (name, options) => {
|
|
13
|
+
// https://op-engineering.github.io/op-sqlite/docs/configuration#in-memory
|
|
14
|
+
const db = open(
|
|
15
|
+
options?.memory
|
|
16
|
+
? { name: `inMemoryDb`, location: ":memory:" }
|
|
17
|
+
: {
|
|
18
|
+
name: `evolu1-${name}.db`,
|
|
19
|
+
...(options?.encryptionKey && {
|
|
20
|
+
encryptionKey: `x'${bytesToHex(options.encryptionKey)}'`,
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
);
|
|
14
24
|
let isDisposed = false;
|
|
15
25
|
|
|
16
26
|
const cache = createPreparedStatementsCache<PreparedStatement>(
|
package/dist/expo-sqlite.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expo-sqlite.d.ts","sourceRoot":"","sources":["../src/expo-sqlite.ts"],"names":[],"mappings":"AASA,OAAO,EACL,cAAc,EAId,SAAS,EACV,MAAM,qBAAqB,CAAC;AAS7B,eAAO,MAAM,cAAc,EAAE,cAI3B,CAAC;AAkBH,eAAO,MAAM,oBAAoB,EAAE,SAMlC,CAAC"}
|
package/dist/expo-sqlite.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createConsole, createEnglishMnemonic, createNanoIdLib, createRandom, createRandomBytes, createTime, } from "@evolu/common";
|
|
2
|
-
import { createDbWorkerForPlatform, createWebSocketSync, } from "@evolu/common/evolu";
|
|
3
|
-
import * as Expo from "expo";
|
|
4
|
-
import { createExpoSqliteDriver } from "./providers/ExpoSqliteDriver.js";
|
|
5
|
-
import { polyfillHermes } from "./utils/Hermes.js";
|
|
6
|
-
polyfillHermes();
|
|
7
|
-
export const createAppState = () => ({
|
|
8
|
-
reset: () => {
|
|
9
|
-
void Expo.reloadAppAsync();
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
const nanoIdLib = createNanoIdLib();
|
|
13
|
-
const console = createConsole();
|
|
14
|
-
const time = createTime();
|
|
15
|
-
const createDbWorker = () => createDbWorkerForPlatform({
|
|
16
|
-
createSqliteDriver: createExpoSqliteDriver,
|
|
17
|
-
createSync: createWebSocketSync,
|
|
18
|
-
console,
|
|
19
|
-
time,
|
|
20
|
-
random: createRandom(),
|
|
21
|
-
nanoIdLib,
|
|
22
|
-
createMnemonic: createEnglishMnemonic,
|
|
23
|
-
createRandomBytes,
|
|
24
|
-
});
|
|
25
|
-
export const evoluReactNativeDeps = {
|
|
26
|
-
time,
|
|
27
|
-
nanoIdLib,
|
|
28
|
-
console,
|
|
29
|
-
createAppState,
|
|
30
|
-
createDbWorker,
|
|
31
|
-
};
|
package/dist/op-sqlite.d.ts
DELETED
package/dist/op-sqlite.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"op-sqlite.d.ts","sourceRoot":"","sources":["../src/op-sqlite.ts"],"names":[],"mappings":"AASA,OAAO,EACL,cAAc,EAId,SAAS,EACV,MAAM,qBAAqB,CAAC;AAQ7B,eAAO,MAAM,cAAc,EAAE,cAQ3B,CAAC;AAkBH,eAAO,MAAM,oBAAoB,EAAE,SAMlC,CAAC"}
|
package/dist/op-sqlite.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createConsole, createEnglishMnemonic, createNanoIdLib, createRandom, createRandomBytes, createTime, } from "@evolu/common";
|
|
2
|
-
import { createDbWorkerForPlatform, createWebSocketSync, } from "@evolu/common/evolu";
|
|
3
|
-
import { DevSettings } from "react-native";
|
|
4
|
-
import { createOpSqliteDriver } from "./providers/OpSqliteDriver.js";
|
|
5
|
-
import { polyfillHermes } from "./utils/Hermes.js";
|
|
6
|
-
polyfillHermes();
|
|
7
|
-
export const createAppState = () => ({
|
|
8
|
-
reset: () => {
|
|
9
|
-
if (process.env.NODE_ENV === "development") {
|
|
10
|
-
DevSettings.reload();
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
// TODO: reload not implemented for bare rn
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
const nanoIdLib = createNanoIdLib();
|
|
18
|
-
const console = createConsole();
|
|
19
|
-
const time = createTime();
|
|
20
|
-
const createDbWorker = () => createDbWorkerForPlatform({
|
|
21
|
-
createSqliteDriver: createOpSqliteDriver,
|
|
22
|
-
createSync: createWebSocketSync,
|
|
23
|
-
console,
|
|
24
|
-
time,
|
|
25
|
-
random: createRandom(),
|
|
26
|
-
nanoIdLib,
|
|
27
|
-
createMnemonic: createEnglishMnemonic,
|
|
28
|
-
createRandomBytes,
|
|
29
|
-
});
|
|
30
|
-
export const evoluReactNativeDeps = {
|
|
31
|
-
time,
|
|
32
|
-
nanoIdLib,
|
|
33
|
-
console,
|
|
34
|
-
createAppState,
|
|
35
|
-
createDbWorker,
|
|
36
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSqliteDriver.d.ts","sourceRoot":"","sources":["../../src/providers/ExpoSqliteDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAGnB,MAAM,eAAe,CAAC;AAIvB,eAAO,MAAM,sBAAsB,EAAE,kBA+CpC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OpSqliteDriver.d.ts","sourceRoot":"","sources":["../../src/providers/OpSqliteDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAGnB,MAAM,eAAe,CAAC;AAIvB,eAAO,MAAM,oBAAoB,EAAE,kBAoDlC,CAAC"}
|
package/dist/utils/Hermes.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Hermes.d.ts","sourceRoot":"","sources":["../../src/utils/Hermes.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,eAAO,MAAM,cAAc,QAAO,IAYjC,CAAC"}
|
package/dist/utils/Hermes.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** Polyfills `Promise.withResolvers`. */
|
|
2
|
-
export const polyfillHermes = () => {
|
|
3
|
-
if (typeof Promise.withResolvers === "undefined") {
|
|
4
|
-
// @ts-expect-error This is OK.
|
|
5
|
-
Promise.withResolvers = function () {
|
|
6
|
-
let resolve, reject;
|
|
7
|
-
const promise = new Promise((res, rej) => {
|
|
8
|
-
resolve = res;
|
|
9
|
-
reject = rej;
|
|
10
|
-
});
|
|
11
|
-
return { promise, resolve, reject };
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
};
|
package/src/expo-sqlite.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createConsole,
|
|
3
|
-
createEnglishMnemonic,
|
|
4
|
-
createNanoIdLib,
|
|
5
|
-
createRandom,
|
|
6
|
-
createRandomBytes,
|
|
7
|
-
createTime,
|
|
8
|
-
} from "@evolu/common";
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
CreateAppState,
|
|
12
|
-
CreateDbWorker,
|
|
13
|
-
createDbWorkerForPlatform,
|
|
14
|
-
createWebSocketSync,
|
|
15
|
-
EvoluDeps,
|
|
16
|
-
} from "@evolu/common/evolu";
|
|
17
|
-
|
|
18
|
-
import * as Expo from "expo";
|
|
19
|
-
|
|
20
|
-
import { createExpoSqliteDriver } from "./providers/ExpoSqliteDriver.js";
|
|
21
|
-
import { polyfillHermes } from "./utils/Hermes.js";
|
|
22
|
-
|
|
23
|
-
polyfillHermes();
|
|
24
|
-
|
|
25
|
-
export const createAppState: CreateAppState = () => ({
|
|
26
|
-
reset: () => {
|
|
27
|
-
void Expo.reloadAppAsync();
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const nanoIdLib = createNanoIdLib();
|
|
32
|
-
const console = createConsole();
|
|
33
|
-
const time = createTime();
|
|
34
|
-
|
|
35
|
-
const createDbWorker: CreateDbWorker = () =>
|
|
36
|
-
createDbWorkerForPlatform({
|
|
37
|
-
createSqliteDriver: createExpoSqliteDriver,
|
|
38
|
-
createSync: createWebSocketSync,
|
|
39
|
-
console,
|
|
40
|
-
time,
|
|
41
|
-
random: createRandom(),
|
|
42
|
-
nanoIdLib,
|
|
43
|
-
createMnemonic: createEnglishMnemonic,
|
|
44
|
-
createRandomBytes,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export const evoluReactNativeDeps: EvoluDeps = {
|
|
48
|
-
time,
|
|
49
|
-
nanoIdLib,
|
|
50
|
-
console,
|
|
51
|
-
createAppState,
|
|
52
|
-
createDbWorker,
|
|
53
|
-
};
|
package/src/op-sqlite.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createConsole,
|
|
3
|
-
createEnglishMnemonic,
|
|
4
|
-
createNanoIdLib,
|
|
5
|
-
createRandom,
|
|
6
|
-
createRandomBytes,
|
|
7
|
-
createTime,
|
|
8
|
-
} from "@evolu/common";
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
CreateAppState,
|
|
12
|
-
CreateDbWorker,
|
|
13
|
-
createDbWorkerForPlatform,
|
|
14
|
-
createWebSocketSync,
|
|
15
|
-
EvoluDeps,
|
|
16
|
-
} from "@evolu/common/evolu";
|
|
17
|
-
|
|
18
|
-
import { DevSettings } from "react-native";
|
|
19
|
-
import { createOpSqliteDriver } from "./providers/OpSqliteDriver.js";
|
|
20
|
-
import { polyfillHermes } from "./utils/Hermes.js";
|
|
21
|
-
|
|
22
|
-
polyfillHermes();
|
|
23
|
-
|
|
24
|
-
export const createAppState: CreateAppState = () => ({
|
|
25
|
-
reset: () => {
|
|
26
|
-
if (process.env.NODE_ENV === "development") {
|
|
27
|
-
DevSettings.reload();
|
|
28
|
-
} else {
|
|
29
|
-
// TODO: reload not implemented for bare rn
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const nanoIdLib = createNanoIdLib();
|
|
35
|
-
const console = createConsole();
|
|
36
|
-
const time = createTime();
|
|
37
|
-
|
|
38
|
-
const createDbWorker: CreateDbWorker = () =>
|
|
39
|
-
createDbWorkerForPlatform({
|
|
40
|
-
createSqliteDriver: createOpSqliteDriver,
|
|
41
|
-
createSync: createWebSocketSync,
|
|
42
|
-
console,
|
|
43
|
-
time,
|
|
44
|
-
random: createRandom(),
|
|
45
|
-
nanoIdLib,
|
|
46
|
-
createMnemonic: createEnglishMnemonic,
|
|
47
|
-
createRandomBytes,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
export const evoluReactNativeDeps: EvoluDeps = {
|
|
51
|
-
time,
|
|
52
|
-
nanoIdLib,
|
|
53
|
-
console,
|
|
54
|
-
createAppState,
|
|
55
|
-
createDbWorker,
|
|
56
|
-
};
|
package/src/utils/Hermes.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** Polyfills `Promise.withResolvers`. */
|
|
2
|
-
export const polyfillHermes = (): void => {
|
|
3
|
-
if (typeof Promise.withResolvers === "undefined") {
|
|
4
|
-
// @ts-expect-error This is OK.
|
|
5
|
-
Promise.withResolvers = function () {
|
|
6
|
-
let resolve, reject;
|
|
7
|
-
const promise = new Promise((res, rej) => {
|
|
8
|
-
resolve = res;
|
|
9
|
-
reject = rej;
|
|
10
|
-
});
|
|
11
|
-
return { promise, resolve, reject };
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
};
|