@fireproof/database
Advanced tools
Comparing version
@@ -1,3 +0,2 @@ | ||
/// <reference types="node" /> | ||
import { ByteView } from '@ipld/dag-json'; | ||
import { ToString } from '@ipld/dag-json'; | ||
import { AnyBlock, AnyLink, DbMeta, IndexCars } from './types'; | ||
@@ -8,4 +7,4 @@ export declare abstract class HeaderStore { | ||
constructor(name: string); | ||
makeHeader(car: AnyLink, indexes: IndexCars): ByteView<DbMeta>; | ||
parseHeader(headerData: Buffer): DbMeta; | ||
makeHeader(car: AnyLink, indexes: IndexCars): ToString<DbMeta>; | ||
parseHeader(headerData: ToString<DbMeta>): DbMeta; | ||
abstract load(branch?: string): Promise<DbMeta | null>; | ||
@@ -12,0 +11,0 @@ abstract save(carCid: AnyLink, indexes: IndexCars, branch?: string): Promise<void>; |
{ | ||
"name": "@fireproof/database", | ||
"version": "0.10.24", | ||
"version": "0.10.26", | ||
"description": "Immutable embedded distributed database for the web", | ||
@@ -5,0 +5,0 @@ "main": "dist/fireproof.cjs", |
@@ -82,8 +82,8 @@ import { openDB, IDBPDatabase } from 'idb' | ||
// Convert the string to a Uint8Array | ||
const uint8Array = new TextEncoder().encode(bytesString) | ||
// const uint8Array = new TextEncoder().encode(bytesString) | ||
// Convert the Uint8Array to a Buffer-like object | ||
const bufferLikeObject = Buffer.from(uint8Array.buffer) | ||
// const bufferLikeObject = Buffer.from(uint8Array.buffer) | ||
return this.parseHeader(bufferLikeObject) | ||
return this.parseHeader(bytesString) | ||
} catch (e) { | ||
@@ -98,6 +98,6 @@ return null | ||
const headerKey = this.headerKey(branch) | ||
const bytes = this.makeHeader(carCid, indexes) as Uint8Array | ||
return localStorage.setItem(headerKey, bytes.toString()) | ||
const bytes = this.makeHeader(carCid, indexes) | ||
return localStorage.setItem(headerKey, bytes) | ||
} catch (e) {} | ||
} | ||
} |
@@ -24,3 +24,3 @@ import { join, dirname } from 'path' | ||
}) | ||
return bytes ? this.parseHeader(bytes) : null | ||
return bytes ? this.parseHeader(bytes.toString()) : null | ||
} | ||
@@ -30,3 +30,3 @@ | ||
const filepath = join(defaultConfig.dataDir, this.name, branch + '.json') | ||
const bytes = this.makeHeader(carCid, indexes) as Uint8Array | ||
const bytes = this.makeHeader(carCid, indexes) | ||
await writePathFile(filepath, bytes) | ||
@@ -56,5 +56,5 @@ } | ||
async function writePathFile(path: string, data: Uint8Array) { | ||
async function writePathFile(path: string, data: Uint8Array | string) { | ||
await mkdir(dirname(path), { recursive: true }) | ||
return await writeFile(path, data) | ||
} |
@@ -1,2 +0,2 @@ | ||
import { encode, decode, ByteView } from '@ipld/dag-json' | ||
import { format, parse, encode, decode, ByteView, ToString } from '@ipld/dag-json' | ||
import { AnyBlock, AnyLink, DbMeta, IndexCars } from './types' | ||
@@ -11,6 +11,8 @@ | ||
makeHeader(car: AnyLink, indexes: IndexCars): ByteView<DbMeta> { | ||
makeHeader(car: AnyLink, indexes: IndexCars): ToString<DbMeta> { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
console.log('make header', { car, indexes }) | ||
const encoded = encode({ car, indexes } as DbMeta) | ||
const encoded = format({ car, indexes } as DbMeta) | ||
// const encoded = encode({ car, indexes } as DbMeta) | ||
// const encoded = JSON.stringify({ car, indexes }) | ||
console.log('made header', encoded) | ||
@@ -20,8 +22,10 @@ return encoded | ||
parseHeader(headerData: Buffer): DbMeta { | ||
parseHeader(headerData: ToString<DbMeta>): DbMeta { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
console.log('parse header', headerData) | ||
const got = decode(headerData) | ||
const got = parse<DbMeta>(headerData) | ||
// const got = decode(headerData) | ||
// const got = JSON.parse(headerData.toString()) | ||
console.log('parsed header', got) | ||
return got as DbMeta | ||
return got | ||
} | ||
@@ -28,0 +32,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
11226559
0.01%119656
0