From ae9f2373ae846228080120ec122625d7da04a0ee Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Mon, 5 Feb 2024 23:51:18 -0500 Subject: [PATCH] build: refines github workflow --- .github/workflows/ci.yaml | 35 ++++++++++++++++++++ .github/workflows/test.yml | 43 ------------------------- .vscode/settings.json | 8 +++-- packages/react/README.md | 66 +++++++++++++++++--------------------- 4 files changed, 71 insertions(+), 81 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..3be95919 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,35 @@ +name: CI +on: + - push + - pull_request + +jobs: + quality-checks: + name: Quality Checks + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 20.10.0 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 8.15.0 + run_install: false + + - name: Install Dependencies + run: pnpm install --frozen-lockfile --ignore-scripts + + - name: Lint Check + run: pnpm lint:check + + - name: Format Check + run: pnpm format:check + + - name: Run Tests + run: pnpm test diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 909ab724..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,43 +0,0 @@ -on: - - push - - pull_request - -jobs: - cache-and-install: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install Node.js - uses: actions/setup-node@v3 - with: - node-version: 20 - - - uses: pnpm/action-setup@v2 - name: Install pnpm - id: pnpm-install - with: - version: 8.10.0 - run_install: false - - - name: Get pnpm store directory - id: pnpm-cache - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - run: pnpm install - - - name: Run tests - run: pnpm test \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 95b2d647..357529c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,7 @@ { - "standard.enable": false -} \ No newline at end of file + "editor.codeActionsOnSave": { + "source.fixAll": "always" + }, + "editor.formatOnSave": true, + "files.autoSave": "onFocusChange" +} diff --git a/packages/react/README.md b/packages/react/README.md index a573c5fe..d390e7e1 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -1,5 +1,3 @@ - - # Fireproof logo [Fireproof](https://fireproof.storage) – live database for the web

@@ -10,7 +8,7 @@ Simplify your application state with a live database. Automatically update your UI based on local or remote changes, and optionally integrate with any cloud for replication and sharing. -Fireproof is an embedded JavaScript document database designed to streamline app development. Data resides locally, with optional encrypted cloud storage and real-time sync and collaboration. Features like live queries, database branches and snapshots, and file attachments make Fireproof ideal for browser-based apps big or small. +Fireproof is an embedded JavaScript document database designed to streamline app development. Data resides locally, with optional encrypted cloud storage and real-time sync and collaboration. Features like live queries, database branches and snapshots, and file attachments make Fireproof ideal for browser-based apps big or small. Fireproof works in the browser, server, edge function, and any other JavaScript environment, with [connectors for popular backend services like AWS, Netlify, and PartyKit.]() @@ -31,7 +29,7 @@ npm install @fireproof/core The default build is optimized for browsers, to load the node build add `/node`: ```js -import { fireproof } from '@fireproof/core/node' +import { fireproof } from "@fireproof/core/node"; ``` Add the database to any web page via HTML script tag (global is `Fireproof`): @@ -41,8 +39,8 @@ Add the database to any web page via HTML script tag (global is `Fireproof`): ``` Go ahead and write features, then [connect to any cloud backend](https://www.npmjs.com/package/@fireproof/connect) later. - - ### JavaScript Example + +### JavaScript Example ```js import { fireproof } from 'use-fireproof' @@ -60,7 +58,7 @@ const result = await db.query("age", { range: [40, 52] }) Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/database-api/basics) You can [find a real-world JavaScript app here.](https://github.com/mlc-ai/web-stable-diffusion/pull/52) Fireproof has been tested in many JavaScript environments. Read more about [bundler support](https://use-fireproof.com/docs/bundling). -### React Example +### React Example Fireproof has React hooks so you can avoid boilerplate and write expressive code. Instead of dealing with React contexts and reducers, simple hooks make your JSON documents feel like `setState()` objects. @@ -74,7 +72,7 @@ function App() { Read the [step-by-step React tutorial](https://use-fireproof.com/docs/react-tutorial) to get started, or [check out this code sandbox example](https://codesandbox.io/s/fireproof-react-antd-twelve-nk63z6?file=/src/App.tsx) to see how easy it is to build a basic app. -## Why choose Fireproof +## Why choose Fireproof Fireproof has a unique take on distributed data integrity, rooted in immutable data and cryptographically verifiable protocols. This allows you to add live data to any app without complex configuration or installation (it's just an npm module) and if you decide to connect to the cloud you can easily choose storage providers or connect to your own S3 bucket. End-to-end encryption allows you to manage keys separately from data, defining custom security policies, so you can get started writing app features today, and connect to any environment when you are ready. This infrastructure independence makes Fireproof great for brownfield and greenfield projects alike. @@ -84,11 +82,11 @@ Fireproof has a unique take on distributed data integrity, rooted in immutable d The core features of the database are available on any platform in a compact JavaScript package and a foundational cloud storage service. -* **JSON Documents** - Encrypted changes are persisted locally and to any connected storage. Store any JSON object using a familiar document database API. -* **File Attachments** - Share social media or manage uploads within Fireproof's [file attachment API](https://use-fireproof.com/docs/database-api/documents#put-with-files). Attachments are stored locally and in the cloud, and can be encrypted or public. -* **Live Query** - Sort and filter any database with CouchDB-style `map` functions. The `useFireproof` React hook integrates so cleanly your code doesn't even have to import `useState` or `useEffect`, instead, [`useLiveQuery`](https://use-fireproof.com/docs/react-hooks/use-live-query) makes dynamic renders easy. -* **Realtime Updates** - [Subscribe to query changes in your application](https://use-fireproof.com/docs/database-api/database#subscribing-to-changes), so your UI updates automatically. This makes vanilla JS apps super easy to build -- the `useFireproof` React hook handles this so you won't need `db.subscribe()` there. -* **Cryptographic Proofs** - Fireproof's Merkle clocks and hash trees are immutable and self-validating, making all query results into offline-capable data slices. Fireproof makes cryptographic proofs available for all of its operations, accelerating replication and making trustless index sharing possible. This makes it a great choice for building custom document approval workflows or other situations where provenance is important. +- **JSON Documents** - Encrypted changes are persisted locally and to any connected storage. Store any JSON object using a familiar document database API. +- **File Attachments** - Share social media or manage uploads within Fireproof's [file attachment API](https://use-fireproof.com/docs/database-api/documents#put-with-files). Attachments are stored locally and in the cloud, and can be encrypted or public. +- **Live Query** - Sort and filter any database with CouchDB-style `map` functions. The `useFireproof` React hook integrates so cleanly your code doesn't even have to import `useState` or `useEffect`, instead, [`useLiveQuery`](https://use-fireproof.com/docs/react-hooks/use-live-query) makes dynamic renders easy. +- **Realtime Updates** - [Subscribe to query changes in your application](https://use-fireproof.com/docs/database-api/database#subscribing-to-changes), so your UI updates automatically. This makes vanilla JS apps super easy to build -- the `useFireproof` React hook handles this so you won't need `db.subscribe()` there. +- **Cryptographic Proofs** - Fireproof's Merkle clocks and hash trees are immutable and self-validating, making all query results into offline-capable data slices. Fireproof makes cryptographic proofs available for all of its operations, accelerating replication and making trustless index sharing possible. This makes it a great choice for building custom document approval workflows or other situations where provenance is important. Learn more about the [architecture](https://use-fireproof.com/docs/architecture) behind Fireproof. @@ -100,7 +98,7 @@ With Fireproof, you **build first** and connect it to your cloud of choice when ### AI Copilot Quick Start -Because Fireproof is designed to let you get started in the browser and connect to the cloud when you're ready, it's ideal for AI-assisted app development. If you are using GPT, Claude, or Bard, you can [easily enable the AI to write React apps using Fireproof](https://hackernoon.com/get-chatgpt-to-focus-on-coding-on-the-right-apis-with-gptdoc-strings). +Because Fireproof is designed to let you get started in the browser and connect to the cloud when you're ready, it's ideal for AI-assisted app development. If you are using GPT, Claude, or Bard, you can [easily enable the AI to write React apps using Fireproof](https://hackernoon.com/get-chatgpt-to-focus-on-coding-on-the-right-apis-with-gptdoc-strings). Working with an AI assistant is a great way to get started on projects or try out new frameworks. Paste this line of code into your prompt, along with a detailed description of the app to build, and your app will be running without ever requiring a cloud. @@ -115,18 +113,18 @@ For example prompts and inspiration [check out the illustrated version of this t Import from the package like this: ```js -import { fireproof } from 'use-fireproof' +import { fireproof } from "use-fireproof"; ``` + and create a database: - + ```js -const database = fireproof('my-app-name') +const database = fireproof("my-app-name"); ``` - ### JSON Documents -A simple put, get and delete interface for keeping track of all your JSON documents. Once your data is in Fireproof you can access it from any app or website. +A simple put, get and delete interface for keeping track of all your JSON documents. Once your data is in Fireproof you can access it from any app or website. ```js const { id } = await database.put({ @@ -135,7 +133,7 @@ const { id } = await database.put({ age: 47 }); -const doc = await database.get('three-thousand') +const doc = await database.get('three-thousand') // { // _id : 'three-thousand' // name : 'André', @@ -145,12 +143,10 @@ const doc = await database.get('three-thousand') Fireproof tracks all versions so undo is easy to write, and cryptographically verifiable snapshots of the database are as easy as web links. - ### Flexible Query - ```js -const { rows } = await database.query("age", { range: [40, 52] }) +const { rows } = await database.query("age", { range: [40, 52] }); ``` Fireproof provides a live query interface that allows you to subscribe to changes in your data. This means that your UI will automatically update whenever there is a change to your data. See the [useFireproof React hooks documentation](https://github.com/fireproof-storage/fireproof/blob/main/packages/react/README.md) for the easiest way to use this feature. @@ -158,13 +154,14 @@ Fireproof provides a live query interface that allows you to subscribe to change You can specify your function as a string and Fireproof will interpret it as indexing that field on all documents. You can also pass a function for more control: ```js -const { rows } = await database.query(function (doc, map) { - map(doc.age, doc.name) - }, { range: [40, 52] }) +const { rows } = await database.query( + function (doc, map) { + map(doc.age, doc.name); + }, + { range: [40, 52] } +); ``` - - The same mechanism that powers the built-in indexes can all be used to connect secondary [vector indexers](https://github.com/tantaraio/voy) or fulltext indexes to Fireproof. [Follow this tutorial to connect a secondary index](https://fireproof.storage/documentation/external-indexers/). ### Realtime Updates @@ -182,25 +179,23 @@ const unsubscribe = database.subscribe(changes) => { Return the `unsubscribe` function from `useEffect` and React will handle it for you. (In the code below, we use the arrow function's implicit return to connect the unsubscribe function to the `useEffect` hook. This prevents extra subscriptions from building up on each render.) ```js -useEffect(() => database.subscribe((changes) => - changes.forEach(change => console.log(change))), []) +useEffect(() => database.subscribe((changes) => changes.forEach((change) => console.log(change))), []); ``` The React [useLiveQuery](https://use-fireproof.com/docs/react-hooks/use-live-query) hook automatically refreshes query results for you, but under the hood, it's just calling `index.query()` and calling `setState()` when the results change. You can use the same technique to build your live query UIs with any framework. ### Cryptographic Proofs -Fireproof's Merkle clocks and hash trees are immutable and self-validating, and all query results are offline-capable data slices. Fireproof makes cryptographic proofs available for all of its operations, accelerating replication and making trustless index sharing possible. If you are making a "DocuSign for _____", [proofs make Fireproof the ideal verifiable document database](https://fireproof.storage/posts/from-mlops-to-point-of-sale:-merkle-proofs-and-data-locality/) for smart contracts and other applications where unique, verifiable, and trustworthy data is required. [Proof chains provide performance benefits as well](https://purrfect-tracker-45c.notion.site/Data-Routing-23c37b269b4c4c3dacb60d0077113bcb), by allowing recipients to skip costly I/O operations and instead cryptographically verify that changes contain all of the required context. - +Fireproof's Merkle clocks and hash trees are immutable and self-validating, and all query results are offline-capable data slices. Fireproof makes cryptographic proofs available for all of its operations, accelerating replication and making trustless index sharing possible. If you are making a "DocuSign for **\_**", [proofs make Fireproof the ideal verifiable document database](https://fireproof.storage/posts/from-mlops-to-point-of-sale:-merkle-proofs-and-data-locality/) for smart contracts and other applications where unique, verifiable, and trustworthy data is required. [Proof chains provide performance benefits as well](https://purrfect-tracker-45c.notion.site/Data-Routing-23c37b269b4c4c3dacb60d0077113bcb), by allowing recipients to skip costly I/O operations and instead cryptographically verify that changes contain all of the required context. ### Cloud Storage When you are ready to save your data to the cloud for sharing or backup: ```js -import { connect } from 'use-fireproof' +import { connect } from "use-fireproof"; -const connection = await connect.web3(db, 'my-account-email@example.com') +const connection = await connect.web3(db, "my-account-email@example.com"); ``` You can tie any app to your app developer storage account, or allow users to create personal storage accounts (at no cost to you). @@ -211,10 +206,9 @@ Currently, the web3 driver only stores database data, not metadata, but that sti The six-month roadmap for Fireproof includes these features to make it a complete offering for application data. - ### Automatic Replication -Documents changes are persisted to [Filecoin](https://filecoin.io) via [web3.storage](https://web3.storage), and made available over IPFS and on a global content delivery network. All you need to do to sync state is send a link to the latest database head, and Fireproof will take care of the rest. +Documents changes are persisted to [Filecoin](https://filecoin.io) via [web3.storage](https://web3.storage), and made available over IPFS and on a global content delivery network. All you need to do to sync state is send a link to the latest database head, and Fireproof will take care of the rest. ### Peer-to-peer Sync