import type { CID } from "multiformats/cid" import * as Path from "../path/index.js" import { Maybe } from "../common/index.js" import { PutResult } from "../components/depot/implementation.js" import { DirectoryPath, DistinctivePath, FilePath, Partitioned, PartitionedNonEmpty, Partition } from "../path/index.js" import { Ucan } from "../ucan/types.js" // 💾 TOP LEVEL // ------------ export type API = Persistence & Properties & Posix & Sharing export interface Persistence { historyStep(): Promise publish(): Promise } export interface Properties { account: AssociatedIdentity } export interface Posix { exists(path: DistinctivePath>): Promise get(path: DistinctivePath>): Promise mv(from: DistinctivePath>, to: DistinctivePath>): Promise rm(path: DistinctivePath>): Promise resolveSymlink(link: SoftLink): Promise symlink(args: { at: DirectoryPath> referringTo: { path: Path.Distinctive> username?: string } name: string }): Promise // Directories ls(path: DirectoryPath>): Promise mkdir(path: DirectoryPath>, options?: MutationOptions): Promise // Files write( path: DistinctivePath>, content: Uint8Array | SoftLink | SoftLink[] | Record, options?: MutationOptions ): Promise read(path: FilePath>): Promise } export interface Sharing { acceptShare({ shareId, sharedBy }: { shareId: string; sharedBy: string }): Promise loadShare({ shareId, sharedBy }: { shareId: string; sharedBy: string }): Promise sharePrivate(paths: DistinctivePath>[], { sharedBy, shareWith }: { sharedBy?: SharedBy; shareWith: string | string[] }): Promise } // FILE // ----- export interface File extends Puttable { content: Uint8Array updateContent(content: Uint8Array): Promise } // LINKS // ----- export interface SimpleLink { name: string size: number cid: CID | string } export interface BaseLink { name: string size: number isFile: boolean } export interface SoftLink { ipns: string name: string key?: string privateName?: string } export interface HardLink extends SimpleLink, BaseLink { } export type Link = HardLink | SoftLink | BaseLink export interface SimpleLinks { [ name: string ]: SimpleLink } export interface BaseLinks { [ name: string ]: BaseLink } export interface HardLinks { [ name: string ]: HardLink } export interface Links { [ name: string ]: Link } // MISC // ---- export type AssociatedIdentity = { rootDID: string username?: string } export type NonEmptyPath = [ string, ...string[] ] export interface Puttable { put(): Promise putDetailed(): Promise } export type UpdateCallback = () => Promise export type PublishHook = (result: CID, proof: Ucan) => unknown export type SharedBy = { rootDid: string; username: string } export type ShareDetails = { shareId: string; sharedBy: SharedBy } export type PuttableUnixTree = UnixTree & Puttable // OPTIONS // ------- export type MutationOptions = { publish?: boolean } // TREE // ---- export interface UnixTree { readOnly: boolean ls(path: Path.Segments): Promise mkdir(path: Path.Segments): Promise cat(path: Path.Segments): Promise add(path: Path.Segments, content: Uint8Array): Promise rm(path: Path.Segments): Promise mv(from: Path.Segments, to: Path.Segments): Promise get(path: Path.Segments): Promise exists(path: Path.Segments): Promise } export interface Tree extends UnixTree, Puttable { createChildTree(name: string, onUpdate: Maybe): Promise createOrUpdateChildFile(content: Uint8Array, name: string, onUpdate: Maybe): Promise mkdirRecurse(path: Path.Segments, onUpdate: Maybe): Promise addRecurse(path: Path.Segments, content: Uint8Array, onUpdate: Maybe): Promise rmRecurse(path: Path.Segments, onUpdate: Maybe): Promise updateChild(child: Tree | File, path: Path.Segments): Promise updateDirectChild(child: Tree | File, name: string, onUpdate: Maybe): Promise removeDirectChild(name: string): this get(path: Path.Segments): Promise getDirectChild(name: string): Promise getOrCreateDirectChild(name: string, onUpdate: Maybe): Promise updateLink(name: string, result: PutResult): this getLinks(): Links }