@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.
Files changed (42) hide show
  1. package/dist/src/LockManager.d.ts.map +1 -1
  2. package/dist/src/LockManager.js +2 -0
  3. package/dist/src/Polyfills.d.ts.map +1 -1
  4. package/dist/src/Polyfills.js +7 -2
  5. package/dist/src/Task.d.ts +2 -1
  6. package/dist/src/Task.d.ts.map +1 -1
  7. package/dist/src/Task.js +5 -2
  8. package/dist/src/components/EvoluIdenticon.js +2 -2
  9. package/dist/src/exports/expo-sqlite.d.ts +2 -1
  10. package/dist/src/exports/expo-sqlite.d.ts.map +1 -1
  11. package/dist/src/exports/expo-sqlite.js +2 -8
  12. package/dist/src/shared.js +0 -47
  13. package/dist/src/sqlite-drivers/createExpoSqliteDriver.d.ts.map +1 -1
  14. package/dist/src/sqlite-drivers/createExpoSqliteDriver.js +1 -0
  15. package/package.json +11 -43
  16. package/src/ErrorUtils.d.ts +2 -1
  17. package/src/LockManager.test.ts +537 -0
  18. package/src/LockManager.ts +2 -0
  19. package/src/Polyfills.test.ts +623 -0
  20. package/src/Polyfills.ts +7 -2
  21. package/src/Task.test.ts +82 -0
  22. package/src/Task.ts +8 -3
  23. package/src/components/EvoluIdenticon.tsx +2 -2
  24. package/src/exports/expo-sqlite.ts +2 -9
  25. package/src/shared.ts +1 -50
  26. package/src/sqlite-drivers/createExpoSqliteDriver.ts +5 -1
  27. package/dist/src/createExpoDeps.d.ts +0 -1
  28. package/dist/src/createExpoDeps.d.ts.map +0 -1
  29. package/dist/src/createExpoDeps.js +0 -163
  30. package/dist/src/exports/bare-op-sqlite.d.ts +0 -1
  31. package/dist/src/exports/bare-op-sqlite.d.ts.map +0 -1
  32. package/dist/src/exports/bare-op-sqlite.js +0 -31
  33. package/dist/src/exports/expo-op-sqlite.d.ts +0 -1
  34. package/dist/src/exports/expo-op-sqlite.d.ts.map +0 -1
  35. package/dist/src/exports/expo-op-sqlite.js +0 -16
  36. package/dist/src/sqlite-drivers/createOpSqliteDriver.d.ts +0 -3
  37. package/dist/src/sqlite-drivers/createOpSqliteDriver.d.ts.map +0 -1
  38. package/dist/src/sqlite-drivers/createOpSqliteDriver.js +0 -119
  39. package/src/createExpoDeps.ts +0 -164
  40. package/src/exports/bare-op-sqlite.ts +0 -30
  41. package/src/exports/expo-op-sqlite.ts +0 -15
  42. package/src/sqlite-drivers/createOpSqliteDriver.ts +0 -76
@@ -1,164 +0,0 @@
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.ts";
19
-
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
- // /**
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,30 +0,0 @@
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.ts";
13
- // import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.ts";
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,15 +0,0 @@
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.ts";
10
- // import { createOpSqliteDriver } from "../sqlite-drivers/createOpSqliteDriver.ts";
11
- //
12
- // // eslint-disable-next-line evolu/require-pure-annotation
13
- // export const { evoluReactNativeDeps, localAuth } = createExpoDeps({
14
- // createSqliteDriver: createOpSqliteDriver,
15
- // });
@@ -1,76 +0,0 @@
1
- import {
2
- constVoid,
3
- bytesToHex,
4
- createPreparedStatementsCache,
5
- type CreateSqliteDriver,
6
- ok,
7
- type SqliteRow,
8
- } from "@evolu/common";
9
- import { open, type PreparedStatement } from "@op-engineering/op-sqlite";
10
-
11
- export const createOpSqliteDriver: CreateSqliteDriver =
12
- (name, options) => () => {
13
- // https://op-engineering.github.io/op-sqlite/docs/configuration#in-memory
14
- using disposer = new DisposableStack();
15
- const db = disposer.adopt(
16
- open(
17
- options?.mode === "memory"
18
- ? { name: `inMemoryDb`, location: ":memory:" }
19
- : {
20
- name: `evolu1-${name}.db`,
21
- ...(options?.mode === "encrypted" && {
22
- encryptionKey: `x'${bytesToHex(options.encryptionKey)}'`,
23
- }),
24
- },
25
- ),
26
- (db) => {
27
- db.close();
28
- },
29
- );
30
-
31
- const cache = disposer.use(
32
- createPreparedStatementsCache<PreparedStatement>(
33
- (sql) => db.prepareStatement(sql),
34
- // op-sqlite doesn't have API for that
35
- constVoid,
36
- ),
37
- );
38
-
39
- const disposables = disposer.move();
40
-
41
- return ok({
42
- exec: (query) => {
43
- const prepared = cache.get(query);
44
-
45
- if (prepared) {
46
- prepared.bindSync(query.parameters);
47
- }
48
-
49
- const { rows, rowsAffected } = db.executeSync(
50
- query.sql,
51
- query.parameters,
52
- );
53
- return { rows: rows as Array<SqliteRow>, changes: rowsAffected };
54
- },
55
-
56
- // FIXME: op-sqlite does not expose binary, but a path to the database file
57
- // another react native dependency would be needed to implement this
58
- export: () => {
59
- throw new Error("TODO: Not implemented yet");
60
- },
61
-
62
- deleteDatabase: () => {
63
- using deleteDisposer = new DisposableStack();
64
- if (options?.mode !== "memory") {
65
- deleteDisposer.defer(() => {
66
- db.delete();
67
- });
68
- }
69
- deleteDisposer.use(disposables);
70
- },
71
-
72
- [Symbol.dispose]: () => {
73
- disposables.dispose();
74
- },
75
- });
76
- };