Skip to content

Commit

Permalink
chore: remove scoped blockstore, assert is now gone
Browse files Browse the repository at this point in the history
  • Loading branch information
mabels committed Jul 4, 2024
1 parent 7797ebd commit 077a7da
Show file tree
Hide file tree
Showing 20 changed files with 826 additions and 899 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ logs
smoke/package.json
smoke/pnpm-lock.yaml
smoke/react/package.json
smoke/react/pnpm-lock.yaml
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/pnpm-lock.yaml
scripts/
8 changes: 1 addition & 7 deletions package-fireproof-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@
"require": "./index.cjs",
"script": "./index.global.js",
"types": "./index.d.ts"
},
"./blockstore": {
"import": "./blockstore/index.js",
"require": "./blockstore/index.cjs",
"script": "./blockstore/index.global.js",
"types": "./blockstore/index.d.ts"
}
},
"scripts": {},
"keywords": ["database", "JSON", "document", "IPLD", "CID", "IPFS"],
"contributors": ["J Chris Anderson", "Alan Shaw", "Travis Vachon", "Mikeal Rogers"],
"contributors": ["J Chris Anderson", "Alan Shaw", "Travis Vachon", "Mikeal Rogers", "Meno Abels"],
"author": "J Chris Anderson",
"license": "Apache-2.0 OR MIT",
"homepage": "https://use-fireproof.com",
Expand Down
5 changes: 3 additions & 2 deletions src/crdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
IndexKeyType,
DocWithId,
DocTypes,
Falsy,
} from "./types.js";
import { index, type Index } from "./indexer.js";
import { CRDTClock } from "./crdt-clock.js";
Expand Down Expand Up @@ -142,10 +143,10 @@ export class CRDT<T extends DocTypes> {
return await getBlock(this.blockstore, cidString);
}

async get(key: string): Promise<DocValue<T> | null> {
async get(key: string): Promise<DocValue<T> | Falsy> {
await this.ready();
const result = await getValueFromCrdt<T>(this.blockstore, this.clock.head, key);
if (result.del) return null;
if (result.del) return undefined;
return result;
}

Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export * from "./database.js";
export * from "./types.js";

export { CRDT } from "./crdt.js";
export * from "./crdt.js";

export * from "./indexer.js";

export * as blockstore from "./blockstore/index.js";

export * as bs from "./blockstore/index.js";
export * as rt from "./runtime/index.js";
1 change: 1 addition & 0 deletions src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
IndexTransactionMeta,
} from "./types.js";
import { BaseBlockstore } from "./blockstore/index.js";

import {
bulkIndex,
indexEntriesForChanges,
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node-sys-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function createNodeSysContainer(): Promise<NodeMap> {
const nodeURL = "node:url";
const nodeFS = "node:fs";
const fs = (await saveImport(nodeFS)).promises;
const assert = "assert";
// const assert = "assert";
const path = await saveImport(nodePath);
return {
state: "node",
Expand All @@ -18,6 +18,6 @@ export async function createNodeSysContainer(): Promise<NodeMap> {
readdir: fs.readdir as NodeMap["readdir"],
readfile: fs.readFile as NodeMap["readfile"],
writefile: fs.writeFile as NodeMap["writefile"],
assert: (await saveImport(assert)).default,
// assert: (await saveImport(assert)).default,
};
}
26 changes: 13 additions & 13 deletions src/runtime/sys-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface NodeMap {
dirname: (path: string) => string;
homedir: () => string;
fileURLToPath: (url: string | URL) => string;
assert: (condition: unknown, message?: string | Error) => void;
// assert: (condition: unknown, message?: string | Error) => void;

mkdir: (path: PathLike, options?: { recursive: boolean }) => Promise<string | undefined>;
readdir: (path: PathLike, options?: unknown) => Promise<unknown[]>;
Expand All @@ -26,9 +26,9 @@ export interface NodeMap {
writefile: (path: PathLike, data: Uint8Array | string) => Promise<void>;
}

export function assert(condition: unknown, message?: string | Error): asserts condition {
SysContainer.freight?.assert(condition, message);
}
// export function assert(condition: unknown, message?: string | Error): asserts condition {
// SysContainer.freight?.assert(condition, message);
// }

const onceStart = new ResolveOnce<void>();

Expand All @@ -53,15 +53,15 @@ class sysContainer {
}
return url.pathname;
},
assert: (condition: unknown, message?: string | Error) => {
if (!condition) {
if (message instanceof Error) {
throw message;
} else {
throw new Error(message);
}
}
},
// assert: (condition: unknown, message?: string | Error) => {
// if (!condition) {
// if (message instanceof Error) {
// throw message;
// } else {
// throw new Error(message);
// }
// }
// },
mkdir: () => Promise.reject(new Error("SysContainer:mkdir is not available in seeded state")),
readdir: () => Promise.reject(new Error("SysContainer:readdir is not available in seeded state")),
rm: () => Promise.reject(new Error("SysContainer:rm is not available in seeded state")),
Expand Down
Loading

0 comments on commit 077a7da

Please sign in to comment.