Skip to content

Commit

Permalink
chore: expose LedgerOpts for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mabels committed Jan 30, 2025
1 parent 2c7911b commit 622a103
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/crdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 9 additions & 20 deletions src/ledger.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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";
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 23 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 };

Expand Down Expand Up @@ -486,7 +487,24 @@ export interface WriteQueue<T extends DocUpdate<S>, S extends DocTypes = DocType
close(): Promise<void>;
}

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<DocUpdate<DocTypes>>;

Expand Down

0 comments on commit 622a103

Please sign in to comment.