refactor: unwrap FileTime namespace + self-reexport (#22966)

This commit is contained in:
Kit Langton
2026-04-16 23:50:15 +00:00
committed by GitHub
parent 218eca7c2b
commit 715786bbf9
+15 -15
View File
@@ -5,39 +5,38 @@ import { Flag } from "@/flag/flag"
import type { SessionID } from "@/session/schema" import type { SessionID } from "@/session/schema"
import { Log } from "../util" import { Log } from "../util"
export namespace FileTime { const log = Log.create({ service: "file.time" })
const log = Log.create({ service: "file.time" })
export type Stamp = { export type Stamp = {
readonly read: Date readonly read: Date
readonly mtime: number | undefined readonly mtime: number | undefined
readonly size: number | undefined readonly size: number | undefined
} }
const session = (reads: Map<SessionID, Map<string, Stamp>>, sessionID: SessionID) => { const session = (reads: Map<SessionID, Map<string, Stamp>>, sessionID: SessionID) => {
const value = reads.get(sessionID) const value = reads.get(sessionID)
if (value) return value if (value) return value
const next = new Map<string, Stamp>() const next = new Map<string, Stamp>()
reads.set(sessionID, next) reads.set(sessionID, next)
return next return next
} }
interface State { interface State {
reads: Map<SessionID, Map<string, Stamp>> reads: Map<SessionID, Map<string, Stamp>>
locks: Map<string, Semaphore.Semaphore> locks: Map<string, Semaphore.Semaphore>
} }
export interface Interface { export interface Interface {
readonly read: (sessionID: SessionID, file: string) => Effect.Effect<void> readonly read: (sessionID: SessionID, file: string) => Effect.Effect<void>
readonly get: (sessionID: SessionID, file: string) => Effect.Effect<Date | undefined> readonly get: (sessionID: SessionID, file: string) => Effect.Effect<Date | undefined>
readonly assert: (sessionID: SessionID, filepath: string) => Effect.Effect<void> readonly assert: (sessionID: SessionID, filepath: string) => Effect.Effect<void>
readonly withLock: <T>(filepath: string, fn: () => Effect.Effect<T>) => Effect.Effect<T> readonly withLock: <T>(filepath: string, fn: () => Effect.Effect<T>) => Effect.Effect<T>
} }
export class Service extends Context.Service<Service, Interface>()("@opencode/FileTime") {} export class Service extends Context.Service<Service, Interface>()("@opencode/FileTime") {}
export const layer = Layer.effect( export const layer = Layer.effect(
Service, Service,
Effect.gen(function* () { Effect.gen(function* () {
const fsys = yield* AppFileSystem.Service const fsys = yield* AppFileSystem.Service
@@ -107,7 +106,8 @@ export namespace FileTime {
return Service.of({ read, get, assert, withLock }) return Service.of({ read, get, assert, withLock })
}), }),
).pipe(Layer.orDie) ).pipe(Layer.orDie)
export const defaultLayer = layer.pipe(Layer.provide(AppFileSystem.defaultLayer)) export const defaultLayer = layer.pipe(Layer.provide(AppFileSystem.defaultLayer))
}
export * as FileTime from "./time"