Skip to content

Commit

Permalink
Merge branch 'changes' of https://github.com/valorant-dhruv/fireproof-1
Browse files Browse the repository at this point in the history
… into changes
  • Loading branch information
valorant-dhruv committed Feb 13, 2024
2 parents 60bbff3 + bb42fe6 commit e872f5c
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 57 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage) – live database for the web

<p align="right">
<a href="https://github.com/fireproof-storage/fireproof/actions/workflows/test.yml">
<img src="https://github.com/fireproof-storage/fireproof/actions/workflows/test.yml/badge.svg" alt="Test status">
<a href="https://github.com/fireproof-storage/fireproof/actions/workflows/ci.yaml">
<img src="https://github.com/fireproof-storage/fireproof/actions/workflows/ci.yaml/badge.svg" alt="Build status">
</a>
</p>

Expand Down
2 changes: 1 addition & 1 deletion packages/connect-ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@web3-storage/pail": "^0.4.0",
"@web3-storage/pail": "^0.4.2",
"@fireproof/core": "workspace:^",
"@fireproof/connect": "workspace:^",
"@fireproof/encrypted-blockstore": "workspace:^",
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-partykit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fireproof/partykit",
"version": "0.17.3",
"version": "0.17.5",
"description": "",
"main": "./dist/browser/index.cjs",
"module": "./dist/browser/index.esm.js",
Expand Down Expand Up @@ -46,14 +46,14 @@
"esbuild": "^0.19.4",
"esbuild-plugin-alias": "^0.2.1",
"esbuild-plugin-tsc": "^0.4.0",
"partykit": "0.0.24",
"partykit": "0.0.85",
"ts-loader": "^9.4.4",
"typescript": "^5.2.2",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@web3-storage/pail": "^0.4.0",
"@web3-storage/pail": "^0.4.2",
"@fireproof/connect": "workspace:^",
"@fireproof/encrypted-blockstore": "workspace:^",
"cross-fetch": "^4.0.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/connect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fireproof/connect",
"version": "0.17.2",
"version": "0.17.4",
"description": "",
"main": "./dist/browser/index.cjs",
"module": "./dist/browser/index.esm.js",
Expand Down Expand Up @@ -49,7 +49,8 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@web3-storage/pail": "^0.4.0",
"@web3-storage/pail": "^0.4.2",
"@ipld/dag-json": "^10.1.2",
"@fireproof/encrypted-blockstore": "workspace:^",
"cross-fetch": "^4.0.0",
"multiformats": "^12.0.1"
Expand Down
25 changes: 17 additions & 8 deletions packages/connect/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import type {
} from './types'
import type { AnyLink, Loader } from '@fireproof/encrypted-blockstore'

import { EventBlock, EventView, decodeEventBlock } from '@alanshaw/pail/clock'
import { MemoryBlockstore } from '@alanshaw/pail/block'
import { EventBlock, decodeEventBlock } from '@web3-storage/pail/clock'
import { EventView } from '@web3-storage/pail/clock/api'

import { MemoryBlockstore } from '@web3-storage/pail/block'
import type { Link } from 'multiformats'
import { TaskManager } from './task-manager'

Expand Down Expand Up @@ -47,12 +49,14 @@ export abstract class Connection {
await this.loader!.remoteWAL?._process()
}

connect({ loader }: { loader: Loader }) {
this.connectStorage({ loader })
connect({ loader }: { loader: Loader | undefined }) {
if (!loader) throw new Error('loader is required')
this.connectMeta({ loader })
this.connectStorage({ loader })
}

connectMeta({ loader }: { loader: Loader }) {
connectMeta({ loader }: { loader: Loader | undefined}) {
if (!loader) throw new Error('loader is required')
this.loader = loader
this.taskManager = new TaskManager(loader)
this.onConnect()
Expand All @@ -70,9 +74,11 @@ export abstract class Connection {
})
}

async onConnect() { }
async onConnect() {}

connectStorage({ loader }: { loader: Loader }) {
connectStorage({ loader }: { loader?: Loader }) {
if (!loader) throw new Error('loader is required')
this.loader = loader
loader!.remoteCarStore = new RemoteDataStore(this.loader!.name, this)
loader!.remoteFileStore = new RemoteDataStore(this.loader!.name, this, 'file')
}
Expand All @@ -81,7 +87,10 @@ export abstract class Connection {
const data = {
dbMeta: bytes
}
const event = await EventBlock.create(data, this.parents as unknown as Link<EventView<{ dbMeta: Uint8Array; }>, number, number, 1>[])
const event = await EventBlock.create(
data,
this.parents as unknown as Link<EventView<{ dbMeta: Uint8Array }>, number, number, 1>[]
)
await this.eventBlocks.put(event.cid, event.bytes)
return event as EventBlock<{ dbMeta: Uint8Array }> // todo test these `as` casts
}
Expand Down
4 changes: 2 additions & 2 deletions packages/encrypted-blockstore/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fireproof/encrypted-blockstore",
"version": "0.17.3",
"version": "0.17.4",
"description": "Content-addressed blockstore with pluggable CRDT storage connectors.",
"type": "module",
"main": "./dist/lib/index.cjs",
Expand Down Expand Up @@ -151,7 +151,7 @@
"util": "^0.12.5"
},
"dependencies": {
"@web3-storage/pail": "^0.4.0",
"@web3-storage/pail": "^0.4.2",
"@ipld/car": "^5.2.0",
"@ipld/dag-cbor": "^9.0.3",
"@ipld/dag-json": "^10.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/encrypted-blockstore/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = "0.17.3";
export const PACKAGE_VERSION = "0.17.4";
4 changes: 2 additions & 2 deletions packages/fireproof/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fireproof/core",
"version": "0.17.4",
"version": "0.17.5",
"description": "Live database for the web.",
"type": "module",
"module": "./dist/browser/fireproof.js",
Expand Down Expand Up @@ -131,7 +131,7 @@
"util": "^0.12.5"
},
"dependencies": {
"@web3-storage/pail": "^0.4.1",
"@web3-storage/pail": "^0.4.2",
"@fireproof/encrypted-blockstore": "workspace:^",
"@ipld/car": "^5.2.0",
"@ipld/dag-cbor": "^9.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/fireproof/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = "0.17.4";
export const PACKAGE_VERSION = "0.17.5";
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-fireproof",
"version": "0.17.5",
"version": "0.17.8",
"description": "Fireproof live database, JavaScript API and React hooks",
"type": "module",
"module": "dist/index.js",
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/useFireproof.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type UseLiveQuery = <T extends DocRecord<T>>(

type UpdateDocFnOptions = {
readonly replace?: boolean;
readonly reset?: boolean;
};

type UpdateDocFn<T extends DocRecord<T>> = (newDoc?: Partial<Doc<T>>, options?: UpdateDocFnOptions) => void;
Expand Down Expand Up @@ -140,16 +141,15 @@ export function useFireproof(name: string | Database = "useFireproof", config: C
);

const updateDoc: UpdateDocFn<T> = useCallback(
(newDoc, opts = { replace: false }) => {
if (!newDoc) return void refreshDoc();
(newDoc, opts = { replace: false, reset: false }) => {
if (!newDoc) return void (opts.reset ? setDoc(initialDoc) : refreshDoc());
setDoc((d) => (opts.replace ? (newDoc as Doc<T>) : { ...d, ...newDoc }));
},
[refreshDoc]
[refreshDoc, initialDoc]
);

useEffect(() => {
if (!docId) return;

const unsubscribe = database.subscribe((changes) => {
if (changes.find((c) => c._id === docId)) {
void refreshDoc(); // todo use change.value
Expand Down
4 changes: 2 additions & 2 deletions packages/solid-js/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage) + SolidJS

<p align="right">
<a href="https://github.com/fireproof-storage/fireproof/actions/workflows/test.yml">
<img src="https://github.com/fireproof-storage/fireproof/actions/workflows/test.yml/badge.svg" alt="Test status">
<a href="https://github.com/fireproof-storage/fireproof/actions/workflows/ci.yaml">
<img src="https://github.com/fireproof-storage/fireproof/actions/workflows/ci.yaml/badge.svg" alt="Test status">
</a>
</p>

Expand Down
2 changes: 1 addition & 1 deletion packages/solid-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fireproof/solid-js",
"version": "0.17.0",
"version": "0.17.1",
"description": "The official SolidJS adapter for Fireproof. Light up your data with an embedded live database for your SolidJS web app.",
"type": "module",
"module": "./dist/server.js",
Expand Down
Loading

0 comments on commit e872f5c

Please sign in to comment.