···11-import { CID } from 'multiformats/cid'
11+import type { CID } from "multiformats/cid";
2233export class MissingBlockError extends Error {
44 constructor(
55 public cid: CID,
66 def?: string,
77 ) {
88- let msg = `block not found: ${cid.toString()}`
88+ let msg = `block not found: ${cid.toString()}`;
99 if (def) {
1010- msg += `, expected type: ${def}`
1010+ msg += `, expected type: ${def}`;
1111 }
1212- super(msg)
1212+ super(msg);
1313 }
1414}
1515···1818 public context: string,
1919 public cids: CID[],
2020 ) {
2121- const cidStr = cids.map((c) => c.toString())
2222- super(`missing ${context} blocks: ${cidStr}`)
2121+ const cidStr = cids.map((c) => c.toString());
2222+ super(`missing ${context} blocks: ${cidStr}`);
2323 }
2424}
2525···2828 public commit: CID,
2929 public cids: CID[],
3030 ) {
3131- const cidStr = cids.map((c) => c.toString())
3232- super(`missing blocks for commit ${commit.toString()}: ${cidStr}`)
3131+ const cidStr = cids.map((c) => c.toString());
3232+ super(`missing blocks for commit ${commit.toString()}: ${cidStr}`);
3333 }
3434}
3535···3838 public cid: CID,
3939 public def: string,
4040 ) {
4141- super(`unexpected object at ${cid.toString()}, expected: ${def}`)
4141+ super(`unexpected object at ${cid.toString()}, expected: ${def}`);
4242 }
4343}
+16-5
repo/mst/mst.ts
···4242 * Then the first will be described as `prefix: 0, key: 'bsky/posts/abcdefg'`,
4343 * and the second will be described as `prefix: 16, key: 'hi'.`
4444 */
4545-const subTreePointer = z.nullable(common.cid);
4646-const treeEntry = z.object({
4545+const subTreePointer: SubTreePointerType = z.nullable(common.cid);
4646+type SubTreePointerType = z.ZodNullable<typeof common.cid>;
4747+const treeEntry: TreeEntryType = z.object({
4748 p: z.number(), // prefix count of ascii chars that this key shares with the prev key
4849 k: common.bytes, // the rest of the key outside the shared prefix
4950 v: common.cid, // value
5051 t: subTreePointer, // next subtree (to the right of leaf)
5152});
5252-const nodeData = z.object({
5353+type TreeEntryType = z.ZodObject<{
5454+ p: z.ZodNumber;
5555+ k: typeof common.bytes;
5656+ v: typeof common.cid;
5757+ t: SubTreePointerType;
5858+}, z.core.$strip>;
5959+const nodeData: NodeDataType = z.object({
5360 l: subTreePointer, // left-most subtree
5461 e: z.array(treeEntry), //entries
5562});
5656-export type NodeData = z.infer<typeof nodeData>;
6363+type NodeDataType = z.ZodObject<{
6464+ l: SubTreePointerType;
6565+ e: z.ZodArray<TreeEntryType>;
6666+}, z.core.$strip>;
6767+export type NodeData = z.infer<NodeDataType>;
57685869export const nodeDataDef = {
5970 name: "mst node",
···675686 }
676687677688 // Walks tree & returns all leaves
678678- async leaves() {
689689+ async leaves(): Promise<Leaf[]> {
679690 const leaves: Leaf[] = [];
680691 for await (const entry of this.walk()) {
681692 if (entry.isLeaf()) leaves.push(entry);
+2-2
repo/mst/util.ts
···1111 type NodeEntry,
1212} from "./mst.ts";
13131414-export const leadingZerosOnHash = (key: string | Uint8Array) => {
1414+export const leadingZerosOnHash = (key: string | Uint8Array): number => {
1515 const hash = sha256(key);
1616 let leadingZeros = 0;
1717 for (let i = 0; i < hash.length; i++) {
···138138 return str.match(validCharsRegex) !== null;
139139};
140140141141-export const ensureValidMstKey = (str: string) => {
141141+export const ensureValidMstKey = (str: string): void => {
142142 if (!isValidMstKey(str)) {
143143 throw new InvalidMstKeyError(str);
144144 }
+4-4
repo/parse.ts
···11-import { CID } from "multiformats/cid";
22-import { cborDecode, check } from "@atp/common";
33-import { RepoRecord } from "@atp/lexicon";
44-import { BlockMap } from "./block-map.ts";
11+import type { CID } from "multiformats/cid";
22+import { cborDecode, type check } from "@atp/common";
33+import type { RepoRecord } from "@atp/lexicon";
44+import type { BlockMap } from "./block-map.ts";
55import { MissingBlockError, UnexpectedObjectError } from "./error.ts";
66import { cborToLexRecord } from "./util.ts";
77
+5-5
repo/readable-repo.ts
···11-import { CID } from "multiformats/cid";
22-import { RepoRecord } from "@atp/lexicon";
11+import type { CID } from "multiformats/cid";
22+import type { RepoRecord } from "@atp/lexicon";
33import { MissingBlocksError } from "./error.ts";
44import log from "./logger.ts";
55import { MST } from "./mst/index.ts";
66import * as parse from "./parse.ts";
77-import { ReadableBlockstore } from "./storage/index.ts";
88-import { Commit, def, RepoContents } from "./types.ts";
77+import type { ReadableBlockstore } from "./storage/index.ts";
88+import { type Commit, def, type RepoContents } from "./types.ts";
99import * as util from "./util.ts";
10101111type Params = {
···2828 this.cid = params.cid;
2929 }
30303131- static load(storage: ReadableBlockstore, commitCid: CID) {
3131+ static load(storage: ReadableBlockstore, commitCid: CID): ReadableRepo {
3232 const commit = storage.readObj(commitCid, def.versionedCommit);
3333 const data = MST.load(storage, (commit as { data: CID }).data);
3434 log.info("loaded repo for", { did: commit.did });
···11-import { CID } from "multiformats";
11+import type { CID } from "multiformats";
22import { z } from "zod";
33import { schema as common } from "@atp/common";
44import { def as commonDef } from "@atp/common";
55-import { RepoRecord } from "@atp/lexicon";
66-import { BlockMap } from "./block-map.ts";
77-import { CidSet } from "./cid-set.ts";
55+import type { RepoRecord } from "@atp/lexicon";
66+import type { BlockMap } from "./block-map.ts";
77+import type { CidSet } from "./cid-set.ts";
8899// Repo nodes
1010// ---------------
+22-16
repo/util.ts
···11import * as cbor from "@ipld/dag-cbor";
22import { cborDecode, check, cidForCbor, schema, TID } from "@atp/common";
33import * as crypto from "@atp/crypto";
44-import { Keypair } from "@atp/crypto";
55-import { ipldToLex, lexToIpld, LexValue, RepoRecord } from "@atp/lexicon";
66-import { DataDiff } from "./data-diff.ts";
44+import type { Keypair } from "@atp/crypto";
75import {
88- Commit,
99- LegacyV2Commit,
1010- RecordCreateDescript,
1111- RecordDeleteDescript,
1212- RecordPath,
1313- RecordUpdateDescript,
1414- RecordWriteDescript,
1515- UnsignedCommit,
66+ ipldToLex,
77+ lexToIpld,
88+ type LexValue,
99+ type RepoRecord,
1010+} from "@atp/lexicon";
1111+import type { DataDiff } from "./data-diff.ts";
1212+import {
1313+ type Commit,
1414+ type LegacyV2Commit,
1515+ type RecordCreateDescript,
1616+ type RecordDeleteDescript,
1717+ type RecordPath,
1818+ type RecordUpdateDescript,
1919+ type RecordWriteDescript,
2020+ type UnsignedCommit,
1621 WriteOpAction,
1722} from "./types.ts";
2323+import type { CID } from "multiformats/basics";
18241925export const diffToWriteDescripts = (
2026 diff: DataDiff,
···7985 return a.did === b.did && a.version === b.version;
8086};
81878282-export const signCommit = async (
8888+export const signCommit = (
8389 unsigned: UnsignedCommit,
8490 keypair: Keypair,
8585-): Promise<Commit> => {
9191+): Commit => {
8692 const encoded = cbor.encode(unsigned);
8787- const sig = await keypair.sign(encoded);
9393+ const sig = keypair.sign(encoded);
8894 return {
8995 ...unsigned,
9096 sig,
···112118 return parsed as RepoRecord;
113119};
114120115115-export const cidForRecord = (val: LexValue) => {
116116- return cidForCbor(lexToIpld(val));
121121+export const cidForRecord = async (val: LexValue): Promise<CID> => {
122122+ return await cidForCbor(lexToIpld(val));
117123};
118124119125export const ensureV3Commit = (commit: LegacyV2Commit | Commit): Commit => {