|
1 | 1 | /** |
2 | | - * DurableRuntime — platform-agnostic runtime abstraction for durable effects. |
| 2 | + * Re-exports DurableRuntime types from @effectionx/durable-streams. |
3 | 3 | * |
4 | | - * Effects must not depend on Node-specific or Deno-specific APIs directly. |
5 | | - * This interface provides all platform operations. Every I/O method returns |
6 | | - * `Operation<T>`, not `Promise<T>`. Cancellation flows through Effection's |
7 | | - * structured concurrency — when a scope tears down, the operation is |
8 | | - * cancelled. No `AbortSignal` in the interface. |
9 | | - * |
10 | | - * Install via `scope.set(DurableRuntimeCtx, nodeRuntime())` before calling |
11 | | - * `durableRun`. Effects access the runtime inside `createDurableOperation` |
12 | | - * callbacks via `scope.expect<DurableRuntime>(DurableRuntimeCtx)`. |
13 | | - */ |
14 | | - |
15 | | -import { createContext } from "effection"; |
16 | | -import type { Context, Operation } from "effection"; |
17 | | - |
18 | | -/** |
19 | | - * Minimal response headers interface. |
20 | | - * |
21 | | - * Uses a minimal interface instead of the global `Headers` type to avoid |
22 | | - * requiring DOM lib types in tsconfig. |
23 | | - */ |
24 | | -export interface ResponseHeaders { |
25 | | - get(key: string): string | null; |
26 | | -} |
27 | | - |
28 | | -/** |
29 | | - * Response shape returned by `DurableRuntime.fetch()`. |
30 | | - * |
31 | | - * Both the response object and `text()` are Operation-native — no Promises |
32 | | - * cross the interface boundary. |
33 | | - */ |
34 | | -export interface RuntimeFetchResponse { |
35 | | - status: number; |
36 | | - headers: ResponseHeaders; |
37 | | - /** Read the response body as text. */ |
38 | | - text(): Operation<string>; |
39 | | -} |
40 | | - |
41 | | -/** |
42 | | - * Platform-agnostic runtime for durable effects. |
43 | | - * |
44 | | - * Implementations exist for Node.js (`nodeRuntime()`) and testing |
45 | | - * (`stubRuntime()`). Future implementations may cover Deno or browsers. |
| 4 | + * The canonical definitions live in durable-streams. This re-export |
| 5 | + * keeps existing imports within durable-effects working without |
| 6 | + * mass import-path changes. |
46 | 7 | */ |
47 | | -export interface DurableRuntime { |
48 | | - /** Execute a subprocess. Cancellation kills the process. */ |
49 | | - exec(options: { |
50 | | - command: string[]; |
51 | | - cwd?: string; |
52 | | - env?: Record<string, string>; |
53 | | - timeout?: number; |
54 | | - }): Operation<{ exitCode: number; stdout: string; stderr: string }>; |
55 | | - |
56 | | - /** Read a text file. */ |
57 | | - readTextFile(path: string): Operation<string>; |
58 | | - |
59 | | - /** Expand glob patterns. Returns relative paths with isFile flag. */ |
60 | | - glob(options: { |
61 | | - patterns: string[]; |
62 | | - root: string; |
63 | | - exclude?: string[]; |
64 | | - }): Operation<Array<{ path: string; isFile: boolean }>>; |
65 | | - |
66 | | - /** Make an HTTP request. Cancellation aborts the request. */ |
67 | | - fetch( |
68 | | - input: string, |
69 | | - init?: { |
70 | | - method?: string; |
71 | | - headers?: Record<string, string>; |
72 | | - body?: string; |
73 | | - timeout?: number; |
74 | | - }, |
75 | | - ): Operation<RuntimeFetchResponse>; |
76 | 8 |
|
77 | | - /** Read an environment variable. Returns undefined if not set. */ |
78 | | - env(name: string): string | undefined; |
79 | | - |
80 | | - /** Return platform information. */ |
81 | | - platform(): { os: string; arch: string }; |
82 | | -} |
83 | | - |
84 | | -/** |
85 | | - * Effection Context for the DurableRuntime. |
86 | | - * |
87 | | - * Set on the scope before calling `durableRun()`. Effects access the |
88 | | - * runtime via `scope.expect<DurableRuntime>(DurableRuntimeCtx)`. |
89 | | - */ |
90 | | -export const DurableRuntimeCtx: Context<DurableRuntime> = |
91 | | - createContext<DurableRuntime>("@effectionx/durable-effects/runtime"); |
| 9 | +export { DurableRuntimeCtx } from "@effectionx/durable-streams"; |
| 10 | +export type { |
| 11 | + DurableRuntime, |
| 12 | + ResponseHeaders, |
| 13 | + RuntimeFetchResponse, |
| 14 | +} from "@effectionx/durable-streams"; |
0 commit comments