snapback4-expo 0.1.14 → 0.2.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 +19 -10
- package/ios/Snapback4Device.xcframework/Info.plist +4 -4
- package/ios/Snapback4Device.xcframework/ios-arm64/Headers/snapback4.h +11 -4
- package/ios/Snapback4Device.xcframework/ios-arm64/libsnapback4_device.a +0 -0
- package/ios/Snapback4Device.xcframework/ios-arm64-simulator/Headers/snapback4.h +11 -4
- package/ios/Snapback4Device.xcframework/ios-arm64-simulator/libsnapback4_device.a +0 -0
- package/package.json +7 -2
- package/src/index.ts +7 -7
package/README.md
CHANGED
|
@@ -2,27 +2,36 @@
|
|
|
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
|
|
6
|
-
`snapback4/
|
|
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 {
|
|
10
|
-
import {
|
|
10
|
+
import { createLocalClient } from "snapback4/local";
|
|
11
|
+
import { createClient } from "snapback4/client";
|
|
12
|
+
import { nativeAvailable, nativeDevice } from "snapback4-expo";
|
|
11
13
|
|
|
12
14
|
const client = nativeAvailable()
|
|
13
|
-
? await
|
|
14
|
-
:
|
|
15
|
+
? await createLocalClient({ url, guest: true, sessionStore, device: nativeDevice })
|
|
16
|
+
: createClient({ url, session }); // Expo Go: the online tier, with a session the app keeps
|
|
15
17
|
```
|
|
16
18
|
|
|
19
|
+
`createNativeClient` probes the module first and rejects with
|
|
20
|
+
`E_NATIVE_VERSION` when the native binary predates the JavaScript client:
|
|
21
|
+
reloading JavaScript does not update the module; rebuild the development
|
|
22
|
+
build.
|
|
23
|
+
|
|
17
24
|
Expo Go loads no custom native code, so the module is present only in a
|
|
18
25
|
development or production build: add `expo-dev-client`, then
|
|
19
26
|
`npx expo run:ios` (the module autolinks; nothing to configure). The
|
|
20
27
|
Rust library ships in the package as `ios/Snapback4Device.xcframework`
|
|
21
|
-
(
|
|
22
|
-
from `crates/snapback4-device`)
|
|
23
|
-
|
|
28
|
+
(about 13.2 MB in 0.2.1, a 6.6 MB archive per slice, built by
|
|
29
|
+
`scripts/build-xcframework.sh` from `crates/snapback4-device`). It includes
|
|
30
|
+
SQLite and the native-query Wasm host. The earlier module measured 1.7 MB
|
|
31
|
+
linked and about a millisecond per call; those measurements predate the
|
|
32
|
+
native-query host.
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
Earlier iOS simulator evidence from the repository's witness in a development
|
|
26
35
|
build (`WITNESS_DEV_CLIENT=1 node witness/expo.mjs`, recorded in
|
|
27
36
|
`metrics/witness.jsonl` as `dev-client-native`): a cold sync of 303 rows
|
|
28
37
|
in 31 ms, a reopen in 6 ms, a cold start with no network answering the
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<key>HeadersPath</key>
|
|
11
11
|
<string>Headers</string>
|
|
12
12
|
<key>LibraryIdentifier</key>
|
|
13
|
-
<string>ios-arm64
|
|
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>
|
|
@@ -9,9 +9,13 @@
|
|
|
9
9
|
* Ops: state, adopt {backend}, apply {page, first}, query {name, viewer, args, now},
|
|
10
10
|
* predict {name, viewer, args, now, newIds, entropy}, withdraw {predicted},
|
|
11
11
|
* enqueue {entry}, queued, next_submission, dequeue {id}, meta {key},
|
|
12
|
-
* set_meta {key, value}, clear_rows. Nothing
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* set_meta {key, value}, clear_rows. Nothing unwinds across this boundary:
|
|
13
|
+
* unwind builds translate an internal panic to E_STORE; production uses
|
|
14
|
+
* panic=abort and terminates before unwinding. Every answer is JSON the
|
|
15
|
+
* caller frees. A device is not thread-safe: one caller at a time, as the
|
|
16
|
+
* store is one transaction at a time.
|
|
17
|
+
* `apply.first` must be true on the first page of a snapshot. It defaults
|
|
18
|
+
* to false so an omitted marker cannot discard a snapshot already staged.
|
|
15
19
|
*/
|
|
16
20
|
#ifndef SNAPBACK4_H
|
|
17
21
|
#define SNAPBACK4_H
|
|
@@ -26,7 +30,10 @@ typedef struct sb4_device sb4_device;
|
|
|
26
30
|
* (ask `sb4_open_reason` why). */
|
|
27
31
|
sb4_device *sb4_open(const char *path, const char *backend_json);
|
|
28
32
|
|
|
29
|
-
/*
|
|
33
|
+
/* Take the refusal recorded by the most recent failed `sb4_open` on this
|
|
34
|
+
* thread, as JSON to free. This diagnoses that attempt without opening or
|
|
35
|
+
* mutating the store a second time. The arguments are retained for ABI
|
|
36
|
+
* compatibility. */
|
|
30
37
|
char *sb4_open_reason(const char *path, const char *backend_json);
|
|
31
38
|
|
|
32
39
|
/* One call; the answer is JSON to free with `sb4_free`. */
|
|
Binary file
|
|
@@ -9,9 +9,13 @@
|
|
|
9
9
|
* Ops: state, adopt {backend}, apply {page, first}, query {name, viewer, args, now},
|
|
10
10
|
* predict {name, viewer, args, now, newIds, entropy}, withdraw {predicted},
|
|
11
11
|
* enqueue {entry}, queued, next_submission, dequeue {id}, meta {key},
|
|
12
|
-
* set_meta {key, value}, clear_rows. Nothing
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* set_meta {key, value}, clear_rows. Nothing unwinds across this boundary:
|
|
13
|
+
* unwind builds translate an internal panic to E_STORE; production uses
|
|
14
|
+
* panic=abort and terminates before unwinding. Every answer is JSON the
|
|
15
|
+
* caller frees. A device is not thread-safe: one caller at a time, as the
|
|
16
|
+
* store is one transaction at a time.
|
|
17
|
+
* `apply.first` must be true on the first page of a snapshot. It defaults
|
|
18
|
+
* to false so an omitted marker cannot discard a snapshot already staged.
|
|
15
19
|
*/
|
|
16
20
|
#ifndef SNAPBACK4_H
|
|
17
21
|
#define SNAPBACK4_H
|
|
@@ -26,7 +30,10 @@ typedef struct sb4_device sb4_device;
|
|
|
26
30
|
* (ask `sb4_open_reason` why). */
|
|
27
31
|
sb4_device *sb4_open(const char *path, const char *backend_json);
|
|
28
32
|
|
|
29
|
-
/*
|
|
33
|
+
/* Take the refusal recorded by the most recent failed `sb4_open` on this
|
|
34
|
+
* thread, as JSON to free. This diagnoses that attempt without opening or
|
|
35
|
+
* mutating the store a second time. The arguments are retained for ABI
|
|
36
|
+
* compatibility. */
|
|
30
37
|
char *sb4_open_reason(const char *path, const char *backend_json);
|
|
31
38
|
|
|
32
39
|
/* One call; the answer is JSON to free with `sb4_free`. */
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snapback4-expo",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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": [
|
|
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/
|
|
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
|
|
4
|
-
//
|
|
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 {
|
|
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:
|
|
30
|
-
async open(
|
|
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(
|
|
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;
|