Skip to content

Commit 2bdc4f3

Browse files
author
Taras Mankovski
committed
feat(durable-streams): add stat method and StatResult to DurableRuntime interface
Adds a stat(path) method that returns file metadata without reading contents. Returns { exists: false, isFile: false, isDirectory: false } for missing paths instead of throwing — existence checks should not require try/catch. Permission errors still propagate.
1 parent abfe832 commit 2bdc4f3

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

durable-streams/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export type {
6464
DurableRuntime,
6565
ResponseHeaders,
6666
RuntimeFetchResponse,
67+
StatResult,
6768
} from "./runtime.ts";
6869

6970
// Context

durable-streams/runtime.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ export interface RuntimeFetchResponse {
3838
text(): Operation<string>;
3939
}
4040

41+
/**
42+
* Result of a `stat` call.
43+
*
44+
* For missing paths `stat` returns `{ exists: false, isFile: false, isDirectory: false }`
45+
* instead of throwing — "does this exist?" has "no" as a valid answer.
46+
*/
47+
export interface StatResult {
48+
exists: boolean;
49+
isFile: boolean;
50+
isDirectory: boolean;
51+
}
52+
4153
/**
4254
* Platform-agnostic runtime for durable effects.
4355
*
@@ -56,6 +68,15 @@ export interface DurableRuntime {
5668
/** Read a text file. */
5769
readTextFile(path: string): Operation<string>;
5870

71+
/**
72+
* Check file/directory existence and type. Never throws for missing paths.
73+
*
74+
* Returns `{ exists: false, isFile: false, isDirectory: false }` when the
75+
* path does not exist. Permission errors and other filesystem errors still
76+
* throw — they indicate a real problem, not "file doesn't exist."
77+
*/
78+
stat(path: string): Operation<StatResult>;
79+
5980
/** Expand glob patterns. Returns relative paths with isFile flag. */
6081
glob(options: {
6182
patterns: string[];

0 commit comments

Comments
 (0)