necoherence/file_effect

Types

pub type ContentDigest {
  ContentDigest(value: String)
}

Constructors

  • ContentDigest(value: String)
pub type DigestLookup {
  DigestFound(ContentDigest)
  DigestUnobserved(UnobservedContents)
}

Constructors

pub type Digests {
  Digests(entries: List(#(core.ResourceId, ContentDigest)))
}

Constructors

The external world normalize_path, track, read, and replace observe and update. Read and write failures stand for a boundary failure such as a permission or I/O error without modeling any particular exception type.

pub type ExternalFileState {
  ExternalFileState(
    files: List(#(NormalizedPath, FileRecord)),
    read_failures: List(NormalizedPath),
    write_failures: List(NormalizedPath),
  )
}

Constructors

pub type ExternalMutation {
  ExternalMutation(
    expected: ContentDigest,
    actual: ContentDigest,
  )
}

Constructors

pub type FileRecord {
  FileRecord(digest: ContentDigest, bytes: List(Int))
}

Constructors

pub type FileSnapshot {
  FileSnapshot(
    path: NormalizedPath,
    contents: List(Int),
    digest: ContentDigest,
  )
}

Constructors

pub type NormalizedPath {
  NormalizedPath(root: Bool, segments: List(String))
}

Constructors

  • NormalizedPath(root: Bool, segments: List(String))
pub type Read {
  Read(
    observation: core.Observation(FileSnapshot),
    world: core.World,
    digests: Digests,
  )
}

Constructors

pub type ReadFailure {
  ReadFailure(path: NormalizedPath)
}

Constructors

pub type ReadReq {
  ReadReq(
    path: NormalizedPath,
    world: core.World,
    digests: Digests,
    state: ExternalFileState,
    observed_at: Int,
  )
}

Constructors

pub type ReplaceConflict {
  ConflictStaleBasis(core.StaleBasis)
  ConflictExternalMutation(ExternalMutation)
}

Constructors

pub type ReplaceContents {
  ReplaceContents(
    new_contents: List(Int),
    new_digest: ContentDigest,
  )
}

Constructors

  • ReplaceContents(
      new_contents: List(Int),
      new_digest: ContentDigest,
    )
pub type ReplaceRejection {
  RejectMismatch(ResourcePathMismatch)
  RejectUnknownResource(core.UnknownResource)
  RejectUnobservedContents(UnobservedContents)
}

Constructors

pub type ReplaceReq {
  ReplaceReq(
    command: core.Command(ReplaceContents),
    path: NormalizedPath,
    world: core.World,
    digests: Digests,
    state: ExternalFileState,
    observed_at: Int,
  )
}

Constructors

pub type Replaced {
  Replaced(
    observation: core.Observation(FileSnapshot),
    world: core.World,
    digests: Digests,
    state: ExternalFileState,
  )
}

Constructors

pub type ResourcePathMismatch {
  ResourcePathMismatch(
    resource: core.ResourceId,
    path: NormalizedPath,
  )
}

Constructors

pub type TrackReq {
  TrackReq(
    path: NormalizedPath,
    world: core.World,
    observed_at: Int,
  )
}

Constructors

pub type Tracked {
  Tracked(
    observation: core.Observation(core.Revision),
    world: core.World,
  )
}

Constructors

pub type UnobservedContents {
  UnobservedContents(resource: core.ResourceId)
}

Constructors

pub type WriteFailure {
  WriteFailure(path: NormalizedPath)
}

Constructors

Values

pub fn lookup_digest(
  digests: Digests,
  resource: core.ResourceId,
) -> DigestLookup
pub fn normalize_path(
  root: Bool,
  raw: List(String),
) -> NormalizedPath

Reduce a raw root flag and segment list into a normalized path.

pub fn read(
  req: ReadReq,
) -> core.Outcome(
  Read,
  core.UnknownResource,
  boundary_c,
  ReadFailure,
)

Read the path from the external state. A declared read failure yields a boundary failure, checked first. Otherwise an absent path is rejected as an unknown resource; a present path yields an observation of its snapshot, and its digest is recorded.

pub fn replace(
  req: ReplaceReq,
) -> core.Outcome(
  Replaced,
  ReplaceRejection,
  ReplaceConflict,
  WriteFailure,
)

Apply the command as a compare-and-replace atomic write. The command’s resource must name the same file as the path; a mismatch is rejected before any digest, world, or file observation is made. A resource with no recorded digest is rejected before the world or file is touched. A revision mismatch is a stale-basis conflict; a digest mismatch after that is an external-mutation conflict. Only once every layer passes is the external state updated as a single total step.

pub fn set_digest(
  digests: Digests,
  resource: core.ResourceId,
  digest: ContentDigest,
) -> Digests
pub fn track(
  req: TrackReq,
) -> core.Outcome(Tracked, boundary_r, boundary_c, boundary_b)

Register the path as an owned resource and return its observation. An already-tracked path yields an observation of its current revision without changing the world.

✨ Search Document