Skip to content

Commit

Permalink
add RN bits to fireproof
Browse files Browse the repository at this point in the history
  • Loading branch information
boorad committed Jul 8, 2024
1 parent f729bb1 commit 74f693f
Show file tree
Hide file tree
Showing 16 changed files with 15,920 additions and 8 deletions.
8 changes: 4 additions & 4 deletions examples/react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-native-fireproof-example",
"name": "@fireproof-examples/react-native",
"description": "React Native Fireproof Example",
"version": "0.0.1",
"private": true,
Expand All @@ -11,14 +11,14 @@
"start": "react-native start"
},
"dependencies": {
"@fireproof/core": "workspace:^",
"@fireproof/react-native": "workspace:^",
"@fireproof/core": "file:../../dist/fireproof-core/fireproof-core-0.0.0-dev.tgz",
"@react-native-community/checkbox": "^0.5.17",
"react": "18.2.0",
"react-native": "0.73.7",
"react-native-fast-encoder": "^0.1.12",
"react-native-mmkv": "<3",
"react-native-quick-crypto": "0.7.1"
"react-native-quick-crypto": "0.7.1",
"use-fireproof": "file:../../dist/use-fireproof/use-fireproof-0.0.0-dev.tgz"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
8,360 changes: 8,360 additions & 0 deletions examples/react-native/pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/react-native/src/TodoItem.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState } from "react";
import { Button, StyleSheet, Text, TextInput, View } from "react-native";
import Checkbox from '@react-native-community/checkbox';
import { useFireproof } from "@fireproof/react-native";
import { Todo, TodoFromAllDocs } from "./TodoList";
import { Doc } from "@fireproof/core";
import React, { useState } from "react";
// import { Doc } from "@fireproof/core";

type TodoItemProps = {
item: TodoFromAllDocs;
Expand Down
3 changes: 1 addition & 2 deletions examples/react-native/src/TodoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export type Todo = { text: string; date: number; completed: boolean; };
export type TodoFromAllDocs = { key: string; value: Doc<Todo>; };

const TodoList = () => {
// TODO: {public: true} is there until crypto.subtle.(encrypt|decrypt) are present in RNQC
const { database: db, useDocument, useLiveQuery } = useFireproof('TodoDB', {public: true});
const { database: db, useDocument, useLiveQuery } = useFireproof('TodoDB');

const defaultTodo = {
text: '',
Expand Down
28 changes: 28 additions & 0 deletions scripts/react-native/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
],
"ignorePatterns": ["node_modules", "coverage", "dist"],
"plugins": ["simple-import-sort"],
"parser": "@typescript-eslint/parser",
"env": { "browser": true, "node": true, "es6": true },
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
"pragma": "React",
"version": "detect"
}
},
"rules": {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error"
}
}
3 changes: 3 additions & 0 deletions scripts/react-native/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage
dist
node_modules
32 changes: 32 additions & 0 deletions scripts/react-native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @fireproof/react-native

React Native bindings for Fireproof

## Installation

* Add `@fireproof/react-native` dependency. We also need to add any native module dependencies so they autolink properly.

pnpm add @fireproof/react-native react-native-quick-crypto react-native-mmkv react-native-fast-encoder
pnpm pods

* Install polyfills as early as possible in your application (`index.js` or `App.tsx`)

import '@fireproof/react-native/polyfills';

## Development

To develop your application, run

pnpm start

in its root directory. Then select `i` or `a` to run iOS or Android simulators respectively. You might need to build with XCode or Android Studio at first, to properly compile the native modules.

See the `examples/react-native` app for a working code sample.

## Caveats

Until `react-native-quick-crypto` gets support for `subtle.encrypt()` and `subtle.decrypt()` for `aes`, you need to use `{public: true}` database option:

```js
const { database, useDocument } = useFireproof('TodoDB', { public: true });
```
80 changes: 80 additions & 0 deletions scripts/react-native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "@fireproof/react-native",
"version": "0.18.0",
"description": "Fireproof live database, JavaScript API and React Native hooks",
"type": "module",
"module": "src/index.js",
"main": "src/index.js",
"react-native": "src/index.js",
"types": "dist/index.d.ts",
"homepage": "https://use-fireproof.com",
"keywords": [
"react-native",
"database",
"json",
"live",
"sync"
],
"repository": {
"type": "git",
"url": "git+https://github.com/fireproof-storage/fireproof.git"
},
"bugs": {
"url": "https://github.com/fireproof-storage/fireproof/issues"
},
"files": [
"src"
],
"exports": {
".": {
"import": "./src/index.tsx",
"types": "./src/index.tsx",
"default": "./src/index.tsx"
},
"./polyfills": "./src/polyfills.tsx"
},
"scripts": {
"prepublishOnly": "cp ../../README.md . && npm run build",
"postpublish": "rm README.md",
"build": "tsup",
"build:clean": "rm -rf dist",
"build:watch": "tsup --watch",
"clean": "rm -rf node_modules",
"format:check": "prettier . --check",
"format:fix": "prettier . --write",
"lint:check": "eslint . --ext .ts,.tsx",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"start": "tsup -w"
},
"author": "J Chris Anderson",
"license": "Apache-2.0 OR MIT",
"gptdoc": "Fireproof/React Native/Usage: import { useLiveQuery, useDocument } from 'use-fireproof'; function App() { const result = useLiveQuery(doc => doc.word, { limit: 10 }); const [{ count }, setDoc, saveDoc] = useDocument({_id: 'count', count: 0}); return (<><p>{count} changes</p><input type='text' onChange={() => saveDoc({count: count + 1})} onSubmit={e => useLiveQuery.database.put({word: e.target.value})} /><ul>{result.map(row => (<li key={row.id}>{row.key}</li>))}</ul></>)}",
"dependencies": {
"@craftzdog/react-native-buffer": "^6.0.5",
"@fireproof/core": "file:../../dist/fireproof-core/fireproof-core-0.0.0-dev.tgz",
"@ipld/dag-json": "^10.1.2",
"event-target-shim": "^6.0.2",
"react-native-fast-encoder": "^0.1.12",
"react-native-mmkv": "<3",
"react-native-quick-crypto": "^0.7.1",
"readable-stream": "^4.5.2",
"use-fireproof": "file:../../dist/use-fireproof/use-fireproof-0.0.0-dev.tgz"
},
"peerDependencies": {
"react": ">=18.0.0",
"react-native": "*"
},
"devDependencies": {
"@babel/runtime": "^7.20.0",
"@testing-library/react": "^14.1.2",
"@types/react": "^18.2.48",
"@types/readable-stream": "^4.0.11",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^12.1.0",
"prettier": "^3.2.5",
"randombytes": "^2.1.0",
"typescript": "^5.4.5"
}
}
Loading

0 comments on commit 74f693f

Please sign in to comment.