snapback4-expo 0.1.14 → 0.2.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/README.md CHANGED
@@ -2,18 +2,27 @@
2
2
 
3
3
  Snapback 4's device in Rust, as an Expo module: the partition in its own
4
4
  SQLite, the stream applied, the outbox kept, queries and predictions
5
- answered — the same interpreter the server runs — behind one JSON call.
6
- `snapback4/native` is the client over it:
5
+ answered — the same interpreter the server runs, and the same module the
6
+ web runs as wasm — behind one JSON call. `snapback4/local` is the client
7
+ over it:
7
8
 
8
9
  ```ts
9
- import { createNativeClient } from "snapback4/native";
10
- import { nativeAvailable, nativeDevice, documentDirectory } from "snapback4-expo";
10
+ import { createLocalClient } from "snapback4/local";
11
+ import { createClient } from "snapback4/client";
12
+ import { nativeAvailable, nativeDevice } from "snapback4-expo";
11
13
 
14
+ const safe = (name: string) => name.replace(/[^A-Za-z0-9._-]/g, "_"); // store and session names carry the URL and the viewer
15
+ const sqliteStore = { open: async (name: string, schema: unknown) => openSqlite(expoSqliteDriver(await SQLite.openDatabaseAsync(`${safe(name)}.db`)), schema) };
12
16
  const client = nativeAvailable()
13
- ? await createNativeClient({ url, guest: true, sessionStore, native: nativeDevice, dataDir: documentDirectory() })
14
- : await createLocalClient({ url, guest: true, sessionStore, store: sqliteStore }); // Expo Go: the TypeScript tier
17
+ ? await createLocalClient({ url, guest: true, sessionStore, device: nativeDevice })
18
+ : createClient({ url, session }); // Expo Go: the online tier, with a session the app keeps
15
19
  ```
16
20
 
21
+ `createNativeClient` probes the module first and rejects with
22
+ `E_NATIVE_VERSION` when the native binary predates the JavaScript client:
23
+ reloading JavaScript does not update the module; rebuild the development
24
+ build.
25
+
17
26
  Expo Go loads no custom native code, so the module is present only in a
18
27
  development or production build: add `expo-dev-client`, then
19
28
  `npx expo run:ios` (the module autolinks; nothing to configure). The
@@ -10,7 +10,7 @@
10
10
  <key>HeadersPath</key>
11
11
  <string>Headers</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>ios-arm64-simulator</string>
13
+ <string>ios-arm64</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>libsnapback4_device.a</string>
16
16
  <key>SupportedArchitectures</key>
@@ -19,8 +19,6 @@
19
19
  </array>
20
20
  <key>SupportedPlatform</key>
21
21
  <string>ios</string>
22
- <key>SupportedPlatformVariant</key>
23
- <string>simulator</string>
24
22
  </dict>
25
23
  <dict>
26
24
  <key>BinaryPath</key>
@@ -28,7 +26,7 @@
28
26
  <key>HeadersPath</key>
29
27
  <string>Headers</string>
30
28
  <key>LibraryIdentifier</key>
31
- <string>ios-arm64</string>
29
+ <string>ios-arm64-simulator</string>
32
30
  <key>LibraryPath</key>
33
31
  <string>libsnapback4_device.a</string>
34
32
  <key>SupportedArchitectures</key>
@@ -37,6 +35,8 @@
37
35
  </array>
38
36
  <key>SupportedPlatform</key>
39
37
  <string>ios</string>
38
+ <key>SupportedPlatformVariant</key>
39
+ <string>simulator</string>
40
40
  </dict>
41
41
  </array>
42
42
  <key>CFBundlePackageType</key>
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "snapback4-expo",
3
- "version": "0.1.14",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Snapback 4's native module for Expo: the device in Rust (the partition in its own SQLite, the stream applied, the outbox kept, queries and predictions answered) behind one JSON call, and the opener `snapback4/native` takes.",
6
6
  "main": "src/index.ts",
7
7
  "types": "src/index.ts",
8
- "files": ["src", "ios", "expo-module.config.json", "README.md"],
8
+ "files": [
9
+ "src",
10
+ "ios",
11
+ "expo-module.config.json",
12
+ "README.md"
13
+ ],
9
14
  "peerDependencies": {
10
15
  "expo": "*",
11
16
  "snapback4": "*"
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- // The opener `snapback4/native` takes, over the Expo module: absent in
1
+ // The opener `snapback4/local` takes, over the Expo module: absent in
2
2
  // Expo Go (which loads no custom native code), present in a development
3
- // or production build. An app asks `nativeAvailable()` and falls back to
4
- // the TypeScript tier (`snapback4/local` over expo-sqlite) when it is not.
3
+ // or production build. An app asks `nativeAvailable()` and runs the
4
+ // online tier (`snapback4/client`) when it is not.
5
5
  import { requireOptionalNativeModule } from "expo-modules-core";
6
- import type { NativeCore, NativeOpener } from "snapback4/native";
6
+ import type { DeviceCore, DeviceOpener } from "snapback4/local";
7
7
 
8
8
  interface Snapback4Native {
9
9
  readonly documentDirectory: string;
@@ -26,10 +26,10 @@ export function documentDirectory(): string {
26
26
  return native.documentDirectory;
27
27
  }
28
28
 
29
- export const nativeDevice: NativeOpener = {
30
- async open(path, backend): Promise<NativeCore> {
29
+ export const nativeDevice: DeviceOpener = {
30
+ async open(name, backend): Promise<DeviceCore> {
31
31
  if (!native) throw new Error("snapback4-expo: the native module is not in this build (Expo Go loads no custom native code; make a development build)");
32
- const handle = await native.open(path, backend ? JSON.stringify(backend) : null);
32
+ const handle = await native.open(`${native.documentDirectory.replace(/\/$/, "")}/${name}.sqlite`, backend ? JSON.stringify(backend) : null);
33
33
  return {
34
34
  async call(request) {
35
35
  const t0 = trace ? Date.now() : 0;