From 622a103e85c4d57c453b455da1b751236cee1318 Mon Sep 17 00:00:00 2001 From: Meno Abels Date: Thu, 30 Jan 2025 13:55:43 +0100 Subject: [PATCH] chore: expose LedgerOpts for tests --- src/crdt.ts | 2 +- src/ledger.ts | 29 +++++++++-------------------- src/types.ts | 28 +++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/crdt.ts b/src/crdt.ts index 201b00ee..35153df1 100644 --- a/src/crdt.ts +++ b/src/crdt.ts @@ -27,11 +27,11 @@ import type { CRDTClock, BaseBlockstore, CarTransaction, + LedgerOpts, } from "./types.js"; import { index, type Index } from "./indexer.js"; // import { blockstoreFactory } from "./blockstore/transaction.js"; import { ensureLogger } from "./utils.js"; -import type { LedgerOpts } from "./ledger.js"; import { CRDTClockImpl } from "./crdt-clock.js"; export class CRDTImpl implements CRDT { diff --git a/src/ledger.ts b/src/ledger.ts index 8bb139c5..bace7061 100644 --- a/src/ledger.ts +++ b/src/ledger.ts @@ -1,6 +1,6 @@ import { BuildURI, CoerceURI, KeyedResolvOnce, Logger, ResolveOnce, URI } from "@adviser/cement"; -import { defaultWriteQueueOpts, writeQueue, WriteQueueParams } from "./write-queue.js"; +import { defaultWriteQueueOpts, writeQueue } from "./write-queue.js"; import type { DocUpdate, ConfigOpts, @@ -12,13 +12,14 @@ import type { Ledger, WriteQueue, CRDT, + LedgerOpts, } from "./types.js"; import { PARAM } from "./types.js"; -import { DbMeta, SerdeGatewayInterceptor, StoreEnDeFile, StoreURIRuntime, StoreUrlsOpts } from "./blockstore/index.js"; +import { StoreURIRuntime, StoreUrlsOpts } from "./blockstore/index.js"; import { ensureLogger, ensureSuperThis, toSortedArray } from "./utils.js"; import { decodeFile, encodeFile } from "./runtime/files.js"; -import { defaultKeyBagOpts, KeyBagRuntime } from "./runtime/key-bag.js"; +import { defaultKeyBagOpts } from "./runtime/key-bag.js"; import { getDefaultURI } from "./blockstore/register-store-protocol.js"; import { DatabaseImpl } from "./database.js"; import { CRDTImpl } from "./crdt.js"; @@ -35,22 +36,6 @@ export function keyConfigOpts(sthis: SuperThis, name?: string, opts?: ConfigOpts ); } -export interface LedgerOpts { - readonly name?: string; - // readonly public?: boolean; - readonly meta?: DbMeta; - readonly gatewayInterceptor?: SerdeGatewayInterceptor; - - readonly writeQueue: WriteQueueParams; - // readonly factoryUnreg?: () => void; - // readonly persistIndexes?: boolean; - // readonly autoCompact?: number; - readonly storeUrls: StoreURIRuntime; - readonly storeEnDe: StoreEnDeFile; - readonly keyBag: KeyBagRuntime; - // readonly threshold?: number; -} - export function isLedger(db: unknown): db is Ledger { return db instanceof LedgerImpl || db instanceof LedgerShell; } @@ -92,6 +77,10 @@ export class LedgerShell implements Ledger { ref.addShell(this); } + get opts(): LedgerOpts { + return this.ref.opts; + } + get context(): Context { return this.ref.context; } @@ -147,7 +136,7 @@ class LedgerImpl implements Ledger { readonly context = new Context(); get name(): string { - return this.opts.storeUrls.data.data.getParam(PARAM.NAME) || "default"; + return this.opts.storeUrls.data.data.getParam(PARAM.NAME) ?? "default"; } addShell(shell: LedgerShell) { diff --git a/src/types.ts b/src/types.ts index 76be6321..f57b6e57 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ import type { EventLink } from "@fireproof/vendor/@web3-storage/pail/clock/api"; import type { Operation } from "@fireproof/vendor/@web3-storage/pail/crdt/api"; import type { Block, UnknownLink, Version } from "multiformats"; +import type { EnvFactoryOpts, Env, Logger, CryptoRuntime, Result } from "@adviser/cement"; import type { CarTransactionOpts, @@ -14,14 +15,14 @@ import type { TransactionMeta, TransactionWrapper, BlockstoreRuntime, + StoreURIRuntime, } from "./blockstore/index.js"; -import { EnvFactoryOpts, Env, Logger, CryptoRuntime, Result } from "@adviser/cement"; // import type { MakeDirectoryOptions, PathLike, Stats } from "fs"; -import { KeyBagOpts } from "./runtime/key-bag.js"; -import { WriteQueueParams } from "./write-queue.js"; -import { Index } from "./indexer.js"; -import { Context } from "./context.js"; +import type { KeyBagOpts, KeyBagRuntime } from "./runtime/key-bag.js"; +import type { WriteQueueParams } from "./write-queue.js"; +import type { Index } from "./indexer.js"; +import type { Context } from "./context.js"; export type { DbMeta }; @@ -486,7 +487,24 @@ export interface WriteQueue, S extends DocTypes = DocType close(): Promise; } +export interface LedgerOpts { + readonly name?: string; + // readonly public?: boolean; + readonly meta?: DbMeta; + readonly gatewayInterceptor?: SerdeGatewayInterceptor; + + readonly writeQueue: WriteQueueParams; + // readonly factoryUnreg?: () => void; + // readonly persistIndexes?: boolean; + // readonly autoCompact?: number; + readonly storeUrls: StoreURIRuntime; + readonly storeEnDe: StoreEnDeFile; + readonly keyBag: KeyBagRuntime; + // readonly threshold?: number; +} + export interface Ledger extends HasCRDT { + readonly opts: LedgerOpts; // readonly name: string; readonly writeQueue: WriteQueue>;