All files / src/fs types.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97                                                                                                                                                                                                 
import { Maybe } from '../common'
import { FileContent, CID, AddResult } from '../ipfs'
import { SemVer } from './semver'
import { Ucan } from '../ucan'
 
 
// FILE
// -----
 
export interface File extends Puttable {
  content: FileContent
  updateContent(content: FileContent): Promise<this>
}
 
 
 
// LINKS
// -----
 
export interface SimpleLink {
  name: string
  size: number
  cid: CID
}
 
export interface BaseLink {
  name: string
  size: number
  mtime?: number
  isFile: boolean
}
 
export interface Link extends SimpleLink, BaseLink {}
 
export interface SimpleLinks { [name: string]: SimpleLink }
export interface BaseLinks { [name: string]: BaseLink }
export interface Links { [name: string]: Link }
 
 
 
// MISC
// ----
 
export enum Branch {
  Public = 'public',
  Pretty = 'p',
  Private = 'private',
  PrivateLog = 'privateLog',
  Version = 'version'
}
 
export type NonEmptyPath = [string, ...string[]]
 
export interface Puttable {
  put(): Promise<CID>
  putDetailed(): Promise<AddResult>
}
 
export type UpdateCallback = () => Promise<unknown>
 
export type PublishHook = (result: CID, proof: Ucan) => unknown
 
 
 
// TREE
// ----
 
export interface UnixTree {
  ls(path: string): Promise<BaseLinks>
  mkdir(path: string, onUpdate?: UpdateCallback): Promise<this>
  cat(path: string): Promise<FileContent>
  add(path: string, content: FileContent): Promise<this>
  rm(path: string): Promise<this>
  mv(from: string, to: string): Promise<this>
  get(path: string): Promise<Tree | File | null>
  exists(path: string): Promise<boolean>
}
 
export interface Tree extends UnixTree, Puttable {
  version: SemVer
 
  createChildTree(name: string, onUpdate: Maybe<UpdateCallback>): Promise<Tree>
  createOrUpdateChildFile(content: FileContent, name: string, onUpdate: Maybe<UpdateCallback>): Promise<File>
 
  mkdirRecurse(path: string, onUpdate: Maybe<UpdateCallback>): Promise<this>
  addRecurse(path: string, content: FileContent, onUpdate: Maybe<UpdateCallback>): Promise<this>
  rmRecurse(path: string, onUpdate: Maybe<UpdateCallback>): Promise<this>
 
  updateDirectChild(child: Tree | File, name: string, onUpdate: Maybe<UpdateCallback>): Promise<this>
  removeDirectChild(name: string): this
  getDirectChild(name: string): Promise<Tree | File | null>
  getOrCreateDirectChild(name: string, onUpdate: Maybe<UpdateCallback>): Promise<Tree | File>
 
  updateLink(name: string, result: AddResult): this
  getLinks(): BaseLinks
}