@evolu/react-native 5.0.5 → 6.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteLive.d.ts","sourceRoot":"","sources":["../src/SqliteLive.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAIP,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AA2BtC,eAAO,MAAM,UAAU,mCAAkC,CAAC"}
1
+ {"version":3,"file":"SqliteLive.d.ts","sourceRoot":"","sources":["../src/SqliteLive.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAKP,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAgCtC,eAAO,MAAM,UAAU,mCAAkC,CAAC"}
@@ -1,23 +1,24 @@
1
1
  import { Sqlite, ensureSqliteQuery, maybeParseJson, valuesToSqliteValues, } from "@evolu/common";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Layer from "effect/Layer";
4
- import * as SQLite from "expo-sqlite";
5
- const db = SQLite.openDatabase("evolu1.db");
4
+ import * as SQLite from "expo-sqlite/next.js";
5
+ const db = SQLite.openDatabaseSync("evolu1.db");
6
6
  const exec = (arg) => Effect.gen(function* (_) {
7
7
  const sqliteQuery = ensureSqliteQuery(arg);
8
8
  const query = {
9
9
  sql: sqliteQuery.sql,
10
10
  args: valuesToSqliteValues(sqliteQuery.parameters),
11
11
  };
12
- const { rows, rowsAffected } = yield* _(Effect.promise(() => db
13
- .execAsync([query], false)
14
- .then((a) => a[0])
15
- .then((result) => {
16
- if ("error" in result)
17
- throw result.error;
18
- return result;
19
- })));
20
- maybeParseJson(rows);
21
- return { rows, changes: rowsAffected };
12
+ const isSelectOrPragma = query.sql.trimStart().toLowerCase().startsWith("select") ||
13
+ query.sql.trimStart().toLowerCase().startsWith("pragma");
14
+ // Expo can log only strings.
15
+ // console.log(JSON.stringify(isSelect), sql);
16
+ if (isSelectOrPragma) {
17
+ const rows = (yield* _(Effect.promise(() => db.getAllAsync(query.sql, query.args))));
18
+ maybeParseJson(rows);
19
+ return { rows, changes: 0 };
20
+ }
21
+ const { changes } = yield* _(Effect.promise(() => db.runAsync(query.sql, query.args)));
22
+ return { rows: [], changes };
22
23
  });
23
24
  export const SqliteLive = Layer.succeed(Sqlite, { exec });
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { InvalidMnemonicError, Mnemonic } from "@evolu/common";
2
2
  import * as Effect from "effect/Effect";
3
- export { Id, NonEmptyString1000, PositiveInt, SqliteBoolean, SqliteDate, String, String1000, canUseDom, cast, database, id, table, } from "@evolu/common";
4
- export type { EvoluError, ExtractRow, InvalidMnemonicError, Mnemonic, NotNull, Owner, OwnerId, QueryResult, SyncState, Timestamp, TimestampError, UnexpectedError, } from "@evolu/common";
5
- export { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/sqlite";
3
+ export * from "@evolu/common/public";
6
4
  /** Parse a string to {@link Mnemonic}. */
7
5
  export declare const parseMnemonic: (mnemonic: string) => Effect.Effect<Mnemonic, InvalidMnemonicError>;
8
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,oBAAoB,EACpB,QAAQ,EAKT,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AASxC,OAAO,EACL,EAAE,EACF,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,UAAU,EACV,MAAM,EACN,UAAU,EACV,SAAS,EACT,IAAI,EACJ,QAAQ,EACR,EAAE,EACF,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,QAAQ,EACR,OAAO,EACP,KAAK,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACT,cAAc,EACd,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,0CAA0C;AAC1C,eAAO,MAAM,aAAa,EAAE,CAC1B,QAAQ,EAAE,MAAM,KACb,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,oBAAoB,CAG1C,CAAC;AAER;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,WAAW,+NAUvB,CAAC;AAEF,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,oBAAoB,EACpB,QAAQ,EAKT,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAUxC,cAAc,sBAAsB,CAAC;AAErC,0CAA0C;AAC1C,eAAO,MAAM,aAAa,EAAE,CAC1B,QAAQ,EAAE,MAAM,KACb,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,oBAAoB,CAG1C,CAAC;AAER;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,WAAW,+NAevB,CAAC;AAEF,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,14 +1,9 @@
1
1
  import { Bip39, DbWorkerLive, EvoluCommonLive, FetchLive, FlushSyncDefaultLive, NanoIdLive, SecretBoxLive, SyncWorkerLive, makeCreateEvolu, } from "@evolu/common";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Layer from "effect/Layer";
4
- import { AppStateLive, Bip39Live, SyncLockLive } from "./PlatformLive.js";
4
+ import { AppStateLive, Bip39Live, PlatformNameLive, SyncLockLive, } from "./PlatformLive.js";
5
5
  import { SqliteLive } from "./SqliteLive.js";
6
- // export * from "@evolu/common/public"
7
- // https://github.com/facebook/metro/issues/1128
8
- // So we have to export manually.
9
- // TODO: Recheck after RN 0.73 release.
10
- export { Id, NonEmptyString1000, PositiveInt, SqliteBoolean, SqliteDate, String, String1000, canUseDom, cast, database, id, table, } from "@evolu/common";
11
- export { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/sqlite";
6
+ export * from "@evolu/common/public";
12
7
  /** Parse a string to {@link Mnemonic}. */
13
8
  export const parseMnemonic = Bip39.pipe(Effect.provide(Bip39Live), Effect.runSync).parse;
14
9
  /**
@@ -42,5 +37,5 @@ export const parseMnemonic = Bip39.pipe(Effect.provide(Bip39Live), Effect.runSyn
42
37
  *
43
38
  * const evolu = createEvolu(Database);
44
39
  */
45
- export const createEvolu = makeCreateEvolu(EvoluCommonLive.pipe(Layer.provide(Layer.mergeAll(FlushSyncDefaultLive, AppStateLive, DbWorkerLive)), Layer.provide(Layer.mergeAll(Bip39Live, NanoIdLive, SqliteLive, SyncWorkerLive)), Layer.provide(Layer.mergeAll(SecretBoxLive, SyncLockLive, FetchLive))));
40
+ export const createEvolu = makeCreateEvolu(EvoluCommonLive.pipe(Layer.provide(Layer.mergeAll(FlushSyncDefaultLive, AppStateLive, DbWorkerLive, PlatformNameLive)), Layer.provide(Layer.mergeAll(Bip39Live, NanoIdLive, SqliteLive, SyncWorkerLive)), Layer.provide(Layer.mergeAll(SecretBoxLive, SyncLockLive, FetchLive))));
46
41
  export * from "@evolu/common-react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evolu/react-native",
3
- "version": "5.0.5",
3
+ "version": "6.0.0",
4
4
  "description": "Evolu for React Native",
5
5
  "keywords": [
6
6
  "evolu",
@@ -31,22 +31,22 @@
31
31
  "README.md"
32
32
  ],
33
33
  "dependencies": {
34
- "expo-updates": "^0.18.17"
34
+ "expo-updates": "^0.24.11"
35
35
  },
36
36
  "devDependencies": {
37
37
  "eslint": "^8.57.0",
38
- "expo": "^49.0.21",
39
- "expo-sqlite": "~11.3.3",
40
- "react-native": "0.72.6",
38
+ "expo": "^50.0.7",
39
+ "expo-sqlite": "~13.2.2",
40
+ "react-native": "0.73.4",
41
41
  "typescript": "^5.3.3",
42
42
  "vitest": "^1.3.1",
43
- "@evolu/common": "3.1.6",
44
- "@evolu/common-react": "5.0.4",
43
+ "@evolu/common": "3.1.7",
44
+ "@evolu/common-react": "5.0.5",
45
45
  "@evolu/tsconfig": "0.0.2",
46
46
  "eslint-config-evolu": "1.0.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@evolu/common-react": "^5.0.4",
49
+ "@evolu/common-react": "^5.0.5",
50
50
  "expo": "^49.0.20",
51
51
  "expo-sqlite": "~11.3.3",
52
52
  "react-native": "^0.72.4"
package/src/SqliteLive.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import {
2
2
  Sqlite,
3
+ SqliteRow,
3
4
  ensureSqliteQuery,
4
5
  maybeParseJson,
5
6
  valuesToSqliteValues,
6
7
  } from "@evolu/common";
7
8
  import * as Effect from "effect/Effect";
8
9
  import * as Layer from "effect/Layer";
9
- import * as SQLite from "expo-sqlite";
10
+ import * as SQLite from "expo-sqlite/next.js";
10
11
 
11
- const db = SQLite.openDatabase("evolu1.db");
12
+ const db = SQLite.openDatabaseSync("evolu1.db");
12
13
 
13
14
  const exec: Sqlite["exec"] = (arg) =>
14
15
  Effect.gen(function* (_) {
@@ -17,19 +18,24 @@ const exec: Sqlite["exec"] = (arg) =>
17
18
  sql: sqliteQuery.sql,
18
19
  args: valuesToSqliteValues(sqliteQuery.parameters),
19
20
  };
20
- const { rows, rowsAffected } = yield* _(
21
- Effect.promise(() =>
22
- db
23
- .execAsync([query], false)
24
- .then((a) => a[0])
25
- .then((result) => {
26
- if ("error" in result) throw result.error;
27
- return result;
28
- }),
29
- ),
21
+
22
+ const isSelectOrPragma =
23
+ query.sql.trimStart().toLowerCase().startsWith("select") ||
24
+ query.sql.trimStart().toLowerCase().startsWith("pragma");
25
+ // Expo can log only strings.
26
+ // console.log(JSON.stringify(isSelect), sql);
27
+
28
+ if (isSelectOrPragma) {
29
+ const rows = (yield* _(
30
+ Effect.promise(() => db.getAllAsync(query.sql, query.args)),
31
+ )) as SqliteRow[];
32
+ maybeParseJson(rows);
33
+ return { rows, changes: 0 };
34
+ }
35
+ const { changes } = yield* _(
36
+ Effect.promise(() => db.runAsync(query.sql, query.args)),
30
37
  );
31
- maybeParseJson(rows);
32
- return { rows, changes: rowsAffected };
38
+ return { rows: [], changes };
33
39
  });
34
40
 
35
41
  export const SqliteLive = Layer.succeed(Sqlite, { exec });
package/src/index.ts CHANGED
@@ -13,42 +13,15 @@ import {
13
13
  } from "@evolu/common";
14
14
  import * as Effect from "effect/Effect";
15
15
  import * as Layer from "effect/Layer";
16
- import { AppStateLive, Bip39Live, SyncLockLive } from "./PlatformLive.js";
16
+ import {
17
+ AppStateLive,
18
+ Bip39Live,
19
+ PlatformNameLive,
20
+ SyncLockLive,
21
+ } from "./PlatformLive.js";
17
22
  import { SqliteLive } from "./SqliteLive.js";
18
23
 
19
- // export * from "@evolu/common/public"
20
- // https://github.com/facebook/metro/issues/1128
21
- // So we have to export manually.
22
- // TODO: Recheck after RN 0.73 release.
23
- export {
24
- Id,
25
- NonEmptyString1000,
26
- PositiveInt,
27
- SqliteBoolean,
28
- SqliteDate,
29
- String,
30
- String1000,
31
- canUseDom,
32
- cast,
33
- database,
34
- id,
35
- table,
36
- } from "@evolu/common";
37
- export type {
38
- EvoluError,
39
- ExtractRow,
40
- InvalidMnemonicError,
41
- Mnemonic,
42
- NotNull,
43
- Owner,
44
- OwnerId,
45
- QueryResult,
46
- SyncState,
47
- Timestamp,
48
- TimestampError,
49
- UnexpectedError,
50
- } from "@evolu/common";
51
- export { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/sqlite";
24
+ export * from "@evolu/common/public";
52
25
 
53
26
  /** Parse a string to {@link Mnemonic}. */
54
27
  export const parseMnemonic: (
@@ -92,7 +65,12 @@ export const parseMnemonic: (
92
65
  export const createEvolu = makeCreateEvolu(
93
66
  EvoluCommonLive.pipe(
94
67
  Layer.provide(
95
- Layer.mergeAll(FlushSyncDefaultLive, AppStateLive, DbWorkerLive),
68
+ Layer.mergeAll(
69
+ FlushSyncDefaultLive,
70
+ AppStateLive,
71
+ DbWorkerLive,
72
+ PlatformNameLive,
73
+ ),
96
74
  ),
97
75
  Layer.provide(
98
76
  Layer.mergeAll(Bip39Live, NanoIdLive, SqliteLive, SyncWorkerLive),