Skip to content

Commit

Permalink
chore: rename getBag to getBagProvider
Browse files Browse the repository at this point in the history
chore: export de/serialize Meta
  • Loading branch information
mabels committed Jan 30, 2025
1 parent 622a103 commit 1075f0d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/runtime/gateways/fp-envelope-serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export interface SerializedMeta {
readonly cid: string;
}

async function dbMetaEvent2Serialized(sthis: SuperThis, dbEvents: Omit<DbMetaEvent, "eventCid">[]): Promise<SerializedMeta[]> {
export async function dbMetaEvent2Serialized(
sthis: SuperThis,
dbEvents: Omit<DbMetaEvent, "eventCid">[],
): Promise<SerializedMeta[]> {
return await Promise.all(
dbEvents.map(async (dbEvent) => {
const event = await EventBlock.create<DbMetaBinary>(
Expand All @@ -36,7 +39,7 @@ async function dbMetaEvent2Serialized(sthis: SuperThis, dbEvents: Omit<DbMetaEve
cid: event.cid.toString(),
parents: dbEvent.parents.map((i) => i.toString()),
data: base64pad.encode(event.bytes),
} as SerializedMeta;
} satisfies SerializedMeta;
}),
);
}
Expand Down Expand Up @@ -103,7 +106,10 @@ export async function fpSerialize<T>(
}
}

async function decode2DbMetaEvents(sthis: SuperThis, rserializedMeta: Result<SerializedMeta[]>): Promise<Result<DbMetaEvent[]>> {
export async function decode2DbMetaEvents(
sthis: SuperThis,
rserializedMeta: Result<SerializedMeta[]>,
): Promise<Result<DbMetaEvent[]>> {
if (rserializedMeta.isErr()) {
return Result.Err(rserializedMeta.Err());
}
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/key-bag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class KeyBag {
name,
key: key,
};
const bag = await this.rt.getBag();
const bag = await this.rt.getBagProvider();
this.logger.Debug().Str("name", name).Msg("setNamedKey");
// there should be a version that throws if key exists
await bag.set(name, item);
Expand Down Expand Up @@ -117,7 +117,7 @@ export class KeyBag {
async getNamedKey(name: string, failIfNotFound = false): Promise<Result<KeyWithFingerPrint>> {
const id = this.rt.sthis.nextId(4).str;
return this._seq.add(async () => {
const bag = await this.rt.getBag();
const bag = await this.rt.getBagProvider();
const named = await bag.get(name);
if (named) {
const fpr = await this.toKeyWithFingerPrint(named.key);
Expand Down Expand Up @@ -163,7 +163,7 @@ export interface KeyBagRuntime {
readonly sthis: SuperThis;
readonly keyLength: number;
// readonly key?: FPCryptoKey;
getBag(): Promise<KeyBagProvider>;
getBagProvider(): Promise<KeyBagProvider>;
id(): string;
}

Expand Down Expand Up @@ -267,7 +267,7 @@ export function defaultKeyBagOpts(sthis: SuperThis, kbo?: Partial<KeyBagOpts>):
sthis,
logger,
keyLength: kbo.keyLength || 16,
getBag: () => kitem.factory(url, sthis),
getBagProvider: () => kitem.factory(url, sthis),
id: () => {
return url.toString();
},
Expand Down
2 changes: 1 addition & 1 deletion tests/blockstore/keyed-crypto-indexdb-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("KeyBag indexdb and file", () => {

let diskBag: rt.kb.KeyItem;
let diskBag2: rt.kb.KeyItem;
const provider = await kb.rt.getBag();
const provider = await kb.rt.getBagProvider();
if (runtimeFn().isBrowser) {
const p = provider as KeyBagProviderIndexDB;
diskBag = await p._prepare().then((db) => db.get("bag", name));
Expand Down
2 changes: 1 addition & 1 deletion tests/blockstore/keyed-crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("KeyBag", () => {

let diskBag: rt.kb.KeyItem;
let diskBag2: rt.kb.KeyItem;
const provider = await kb.rt.getBag();
const provider = await kb.rt.getBagProvider();
if (runtimeFn().isBrowser) {
const p = provider as KeyBagProviderIndexDB;
diskBag = await p._prepare().then((db) => db.get("bag", name));
Expand Down

0 comments on commit 1075f0d

Please sign in to comment.