@tapedb/react-native 0.0.0-stage → 0.2.2
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/LICENSE +21 -0
- package/README.md +62 -2
- package/index.d.ts +37 -0
- package/index.mjs +33 -0
- package/package.json +39 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brandon Diaz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tapedb/react-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React Native bindings for [tapedb](https://tapedb.dev), a typed database for
|
|
4
|
+
Cloudflare: the same hooks as `@tapedb/react`, plus a durable queue for writes
|
|
5
|
+
made offline.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tapedb/tapedb @tapedb/react-native @react-native-async-storage/async-storage react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { createReactNativeClient } from "@tapedb/react-native";
|
|
13
|
+
import { useLive } from "@tapedb/react-native";
|
|
14
|
+
|
|
15
|
+
const db = createReactNativeClient({ schema, url, workspace, userId, getToken });
|
|
16
|
+
|
|
17
|
+
const { data } = useLive(db.task.findMany({ where: { done: false } }));
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Why this package exists
|
|
21
|
+
|
|
22
|
+
A tapedb write is optimistic and goes into an offline queue first. In a browser
|
|
23
|
+
that queue is IndexedDB. React Native has no IndexedDB, so the queue would be
|
|
24
|
+
memory-only: a write made in a tunnel, or one still pending when iOS
|
|
25
|
+
suspends the app, was gone after a relaunch.
|
|
26
|
+
|
|
27
|
+
`createReactNativeClient` supplies an `AsyncStorageOutbox` instead — one
|
|
28
|
+
AsyncStorage key per pending write, listed back and replayed when the app
|
|
29
|
+
starts again, in the order the writes were made. That is the whole difference
|
|
30
|
+
from `createClient()`; nothing about the API changes.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
// Equivalent, if you want the queue in your own store:
|
|
34
|
+
import { AsyncStorageOutbox } from "@tapedb/react-native";
|
|
35
|
+
|
|
36
|
+
const db = createReactNativeClient({
|
|
37
|
+
schema,
|
|
38
|
+
url,
|
|
39
|
+
workspace,
|
|
40
|
+
userId,
|
|
41
|
+
getToken,
|
|
42
|
+
storage: myKeyValueStore, // getItem, setItem, removeItem, getAllKeys, multiRemove
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The queue is scoped by `url` and `userId`, exactly like the browser's, so
|
|
47
|
+
recreating the client on an account change does not replay the previous
|
|
48
|
+
account's pending writes.
|
|
49
|
+
|
|
50
|
+
## Import paths
|
|
51
|
+
|
|
52
|
+
`@tapedb/react-native` re-exports `@tapedb/tapedb/react` and pins the exact
|
|
53
|
+
`@tapedb/tapedb` version it ships with, so the hooks are the core's own
|
|
54
|
+
bindings rather than a copy:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { useLive } from "@tapedb/react-native"; // preferred
|
|
58
|
+
import { useLive } from "@tapedb/tapedb/react"; // same module, still supported
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`react` and `@react-native-async-storage/async-storage` are peer dependencies.
|
|
62
|
+
`@tapedb/react-native` never imports `react-native`, so it installs and imports
|
|
63
|
+
in Node — its own queue is exercised there against a fake store.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Types for `@tapedb/react-native`: the core's hooks, re-exported, plus the
|
|
2
|
+
// AsyncStorage queue and the client factory that wires it.
|
|
3
|
+
import type {
|
|
4
|
+
AsyncStorageLike,
|
|
5
|
+
Client,
|
|
6
|
+
ClientConfig,
|
|
7
|
+
Models,
|
|
8
|
+
Outbox,
|
|
9
|
+
} from "@tapedb/tapedb";
|
|
10
|
+
|
|
11
|
+
export * from "@tapedb/tapedb/react";
|
|
12
|
+
export { AsyncStorageOutbox } from "@tapedb/tapedb";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `createClient`'s options, plus where the offline queue lives.
|
|
16
|
+
*
|
|
17
|
+
* `outbox` is inherited and still wins: pass one to take over the queue
|
|
18
|
+
* entirely (a SQLite store, a shared queue for several clients).
|
|
19
|
+
*/
|
|
20
|
+
export interface ReactNativeClientConfig<M extends Models>
|
|
21
|
+
extends ClientConfig<M> {
|
|
22
|
+
/**
|
|
23
|
+
* The key-value store behind the queue. Defaults to
|
|
24
|
+
* `@react-native-async-storage/async-storage`; passed explicitly, any store
|
|
25
|
+
* with `getItem`, `setItem`, `removeItem`, `getAllKeys` and `multiRemove`
|
|
26
|
+
* will do.
|
|
27
|
+
*/
|
|
28
|
+
storage?: AsyncStorageLike;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A client whose pending writes are durable across a restart: a write made
|
|
33
|
+
* while offline is listed back and replayed when the app is launched again.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createReactNativeClient<M extends Models>(
|
|
36
|
+
config: ReactNativeClientConfig<M> & { outbox?: Outbox }
|
|
37
|
+
): Client<M>;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// `@tapedb/react-native` is `@tapedb/tapedb/react` — same hooks, same module,
|
|
2
|
+
// same release — plus the one thing React Native needs that a browser gets for
|
|
3
|
+
// free: a durable queue for writes made while offline. The view layer is thin
|
|
4
|
+
// and this file has to run under Node too (its smoke test imports it there),
|
|
5
|
+
// so nothing here imports `react-native`: the store is a peer module and an
|
|
6
|
+
// interface the core defines, and the app's own AsyncStorage satisfies it.
|
|
7
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
8
|
+
import { AsyncStorageOutbox, createClient, scopedOutboxName } from "@tapedb/tapedb";
|
|
9
|
+
|
|
10
|
+
export * from "@tapedb/tapedb/react";
|
|
11
|
+
export { AsyncStorageOutbox } from "@tapedb/tapedb";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `createClient()` for React Native: the same options, with an
|
|
15
|
+
* `AsyncStorage`-backed outbox instead of the IndexedDB one no RN runtime has.
|
|
16
|
+
*
|
|
17
|
+
* The queue is scoped the way the browser scopes its own — `url` plus
|
|
18
|
+
* `userId` — so an account's pending writes are never replayed with the next
|
|
19
|
+
* account's claim.
|
|
20
|
+
*
|
|
21
|
+
* @param config `createClient`'s options. `storage` overrides the store (a
|
|
22
|
+
* test passes a Map-like fake); `outbox` overrides the queue outright.
|
|
23
|
+
*/
|
|
24
|
+
export function createReactNativeClient({ storage = AsyncStorage, outbox, ...config }) {
|
|
25
|
+
return createClient({
|
|
26
|
+
...config,
|
|
27
|
+
outbox:
|
|
28
|
+
outbox ??
|
|
29
|
+
new AsyncStorageOutbox(storage, {
|
|
30
|
+
prefix: `${scopedOutboxName(config.url, config.userId)}:`,
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tapedb/react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "React Native bindings for tapedb: the hooks, plus a durable AsyncStorage outbox so offline writes survive the app being killed.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"import": "./index.mjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "index.mjs",
|
|
13
|
+
"types": "index.d.ts",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"files": [
|
|
16
|
+
"index.mjs",
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@tapedb/tapedb": "0.2.2"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@react-native-async-storage/async-storage": "^1.17.0 || ^2.0.0 || ^3.0.0",
|
|
26
|
+
"react": "^19.0.0"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.18"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/tapedb/tapedb.git",
|
|
38
|
+
"directory": "packages/react-native"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://tapedb.dev"
|
|
41
|
+
}
|