@executablemd/runtime 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/apis.js +5 -3
- package/esm/config.js +29 -0
- package/esm/mod.js +2 -0
- package/package.json +1 -1
- package/types/config.d.ts +24 -0
- package/types/mod.d.ts +3 -0
package/esm/apis.js
CHANGED
|
@@ -63,6 +63,7 @@ import { fetch as effectionFetch } from "@effectionx/fetch";
|
|
|
63
63
|
import { readTextFile as fsReadTextFile, stat as fsStat, globToRegExp, walk } from "@effectionx/fs";
|
|
64
64
|
import { exec as processExec } from "@effectionx/process";
|
|
65
65
|
import { each, race, sleep } from "effection";
|
|
66
|
+
import { timeout as contextualTimeout } from "./config.js";
|
|
66
67
|
function* withTimeout(label, timeout, operation) {
|
|
67
68
|
if (timeout === undefined) {
|
|
68
69
|
return yield* operation;
|
|
@@ -92,7 +93,8 @@ export const API = {
|
|
|
92
93
|
if (!cmd) {
|
|
93
94
|
throw new Error("exec: command array must not be empty");
|
|
94
95
|
}
|
|
95
|
-
const
|
|
96
|
+
const effectiveTimeout = timeout ?? (yield* contextualTimeout);
|
|
97
|
+
const result = yield* withTimeout(`exec(${cmd})`, effectiveTimeout, processExec(cmd, {
|
|
96
98
|
arguments: args,
|
|
97
99
|
cwd,
|
|
98
100
|
env,
|
|
@@ -162,7 +164,7 @@ export const API = {
|
|
|
162
164
|
*/
|
|
163
165
|
Fetch: createApi("runtime.fetch", {
|
|
164
166
|
*fetch(input, init) {
|
|
165
|
-
const timeout = init?.timeout;
|
|
167
|
+
const timeout = init?.timeout ?? (yield* contextualTimeout);
|
|
166
168
|
const response = yield* withTimeout(`fetch(${input})`, timeout, effectionFetch(input, {
|
|
167
169
|
method: init?.method,
|
|
168
170
|
headers: init?.headers,
|
|
@@ -205,7 +207,7 @@ export const API = {
|
|
|
205
207
|
*
|
|
206
208
|
* Default handler throws — platform-specific middleware must be
|
|
207
209
|
* installed via `yield* API.Compiler.around(...)` before use.
|
|
208
|
-
* See `core/src/deno-compiler.ts` for the Deno implementation.
|
|
210
|
+
* See `packages/core/src/deno-compiler.ts` for the Deno implementation.
|
|
209
211
|
*/
|
|
210
212
|
Compiler: createApi("runtime.compiler", {
|
|
211
213
|
// deno-lint-ignore require-yield
|
package/esm/config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Api — shared execution configuration with pluggable middleware.
|
|
3
|
+
*
|
|
4
|
+
* Supplies the contextual timeout in milliseconds. Process, Fetch, and
|
|
5
|
+
* Agent operations read it when a call does not provide an explicit
|
|
6
|
+
* timeout. Override it for a scope with:
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* yield* Config.around({ timeout: () => 30_000 }, { at: "min" });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
import { createApi } from "@effectionx/context-api";
|
|
13
|
+
export const Config = createApi("Config", {
|
|
14
|
+
timeout: 120_000,
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* The validated contextual timeout. Always a positive, finite number of
|
|
18
|
+
* milliseconds — a middleware-supplied value that is not valid fails loudly
|
|
19
|
+
* here rather than silently disabling or corrupting timeouts downstream.
|
|
20
|
+
*/
|
|
21
|
+
export const timeout = {
|
|
22
|
+
*[Symbol.iterator]() {
|
|
23
|
+
const value = yield* Config.operations.timeout;
|
|
24
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
25
|
+
throw new Error(`Config timeout must be a positive, finite number of milliseconds, got ${String(value)}`);
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
},
|
|
29
|
+
};
|
package/esm/mod.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* - `API.Fetch` — HTTP requests (`fetch`)
|
|
12
12
|
* - `API.Env` — environment variables and platform info (`cwd`, `env`, `platform`)
|
|
13
13
|
* - `API.Compiler` — block compilation (`compile`)
|
|
14
|
+
* - `Config` — shared execution config (`timeout`)
|
|
14
15
|
*
|
|
15
16
|
* See `apis.ts` for architecture rationale.
|
|
16
17
|
* See `@executablemd/runtime/test` for composable test stubs.
|
|
@@ -18,3 +19,4 @@
|
|
|
18
19
|
export { API } from "./apis.js";
|
|
19
20
|
export { exec, readTextFile, stat, glob, fetch, cwd, env, platform, compile } from "./apis.js";
|
|
20
21
|
export { findFreePort } from "./find-free-port.js";
|
|
22
|
+
export { Config, timeout } from "./config.js";
|
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Api — shared execution configuration with pluggable middleware.
|
|
3
|
+
*
|
|
4
|
+
* Supplies the contextual timeout in milliseconds. Process, Fetch, and
|
|
5
|
+
* Agent operations read it when a call does not provide an explicit
|
|
6
|
+
* timeout. Override it for a scope with:
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* yield* Config.around({ timeout: () => 30_000 }, { at: "min" });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
import { type Api } from "@effectionx/context-api";
|
|
13
|
+
import type { Operation } from "effection";
|
|
14
|
+
export interface ConfigApi {
|
|
15
|
+
/** Shared timeout in milliseconds. */
|
|
16
|
+
timeout: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const Config: Api<ConfigApi>;
|
|
19
|
+
/**
|
|
20
|
+
* The validated contextual timeout. Always a positive, finite number of
|
|
21
|
+
* milliseconds — a middleware-supplied value that is not valid fails loudly
|
|
22
|
+
* here rather than silently disabling or corrupting timeouts downstream.
|
|
23
|
+
*/
|
|
24
|
+
export declare const timeout: Operation<number>;
|
package/types/mod.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* - `API.Fetch` — HTTP requests (`fetch`)
|
|
12
12
|
* - `API.Env` — environment variables and platform info (`cwd`, `env`, `platform`)
|
|
13
13
|
* - `API.Compiler` — block compilation (`compile`)
|
|
14
|
+
* - `Config` — shared execution config (`timeout`)
|
|
14
15
|
*
|
|
15
16
|
* See `apis.ts` for architecture rationale.
|
|
16
17
|
* See `@executablemd/runtime/test` for composable test stubs.
|
|
@@ -19,3 +20,5 @@ export { API } from "./apis.js";
|
|
|
19
20
|
export { exec, readTextFile, stat, glob, fetch, cwd, env, platform, compile } from "./apis.js";
|
|
20
21
|
export type { ResponseHeaders, RuntimeFetchResponse, StatResult } from "./apis.js";
|
|
21
22
|
export { findFreePort } from "./find-free-port.js";
|
|
23
|
+
export { Config, timeout } from "./config.js";
|
|
24
|
+
export type { ConfigApi } from "./config.js";
|