Skip to content

Commit f50ea18

Browse files
committed
🐛 Account for result bindings at REPL pause boundaries
1 parent b9645df commit f50ea18

8 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎packages/cli/src/repl/expansion.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export interface BoundaryPartition {
8383
* for a hold to be standing in. `hasCapture`, `hasContent` and `hasBinding`
8484
* answer a question about an invocation the walk has already reached; holding
8585
* one would stop the same walk the gate before it already stops, one question
86-
* later.
86+
* later. `bindResult` reserves a name on an invocation the walk has already
87+
* reached. The engine publishes the value after teardown.
8788
*
8889
* `expand` surrounds an element's whole expansion, which makes it a step in
8990
* the walk that reached it and not a walk of its own. Treating it as one would
@@ -114,6 +115,7 @@ export const COMPONENT_BOUNDARIES: BoundaryPartition = {
114115
"hasCapture",
115116
"hasContent",
116117
"hasBinding",
118+
"bindResult",
117119
],
118120
};
119121

‎packages/core/api.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export type { JournalAdmission } from "./src/execute.ts";
7575
* boundary: a host that wants to watch an element expand needs the descriptor
7676
* and the shapes it will be handed, and nothing of the engine behind them.
7777
*/
78-
export { Component } from "./src/component-api.ts";
78+
export { bindResult, Component } from "./src/component-api.ts";
7979
export type {
8080
ComponentApi,
8181
ComponentExpansionPhase,

‎packages/core/mod.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export {
6565
tryContent,
6666
hasCapture,
6767
hasBinding,
68+
bindResult,
6869
capture,
6970
handleFailure,
7071
} from "./src/component-api.ts";

‎packages/core/src/component-api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ export const codeBlock: Operations<ComponentApi>["codeBlock"] = Component.operat
552552
export const persistent: Operations<ComponentApi>["persistent"] = Component.operations.persistent;
553553
export const content: Operations<ComponentApi>["content"] = Component.operations.content;
554554
export const hasContent: Operations<ComponentApi>["hasContent"] = Component.operations.hasContent;
555+
export const bindResult: Operations<ComponentApi>["bindResult"] = Component.operations.bindResult;
555556
export const hasBinding: Operations<ComponentApi>["hasBinding"] = Component.operations.hasBinding;
556557
export const retain: Operations<ComponentApi>["retain"] = Component.operations.retain;
557558
export const tryContent: Operations<ComponentApi>["tryContent"] = Component.operations.tryContent;

‎packages/core/src/expand.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4557,7 +4557,9 @@ function* expandFunctionComponent(
45574557
*bindResult([bindingName]) {
45584558
const checked = validateBindingName(bindingName);
45594559
if (!checked.ok) {
4560-
throw checked.error;
4560+
throw new Error(
4561+
`Additional result binding on <${name} /> ${checked.error.message}`,
4562+
);
45614563
}
45624564
if (asBinding === undefined || checked.value === undefined) {
45634565
throw new Error(

‎packages/git/src/composition/components/GitHubSearch.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, documented, formDispatcher, isJsonObject } from "@executablemd/core";
1+
import { documented, formDispatcher, isJsonObject } from "@executablemd/core";
2+
import { bindResult } from "@executablemd/core/api";
23
import type { ComponentRegistration, Json, JsonObject } from "@executablemd/core";
34
import { createApi } from "@effectionx/context-api";
45
import type { Operation } from "effection";
@@ -81,8 +82,7 @@ function* search(props: Record<string, Json>): Operation<JsonObject> {
8182
if (order !== undefined && sort === undefined) {
8283
throw new GitOperationAdmissionError(SEARCH_ELEMENT, "order requires sort.");
8384
}
84-
const publishNext =
85-
typeof nextAs === "string" ? yield* Component.operations.bindResult(nextAs) : undefined;
85+
const publishNext = typeof nextAs === "string" ? yield* bindResult(nextAs) : undefined;
8686
const repository = yield* selectedRepository();
8787
if (repository === undefined) {
8888
throw new GitOperationAdmissionError(SEARCH_ELEMENT, "select a Repository before searching.");

‎specs/executable-mdx-spec.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,7 @@ the read that asked for it rather than appearing in it.
21672167
| File | Contents |
21682168
|---|---|
21692169
| `src/eval-transform.ts` | `transformBlock()`, `serializeExports()`, `isJson()`, `TransformResult` |
2170-
| `src/component-api.ts` | `Component` Api + `ComponentApi` interface and the direct operations (`importComponent`, `applyModifiers`, `applyBoundModifiers`, `raise`, `env`, `evalScope`, `generated`, `codeBlock`, `persistent`, `content`, `hasBinding`) — §5.5 |
2170+
| `src/component-api.ts` | `Component` Api + `ComponentApi` interface and the direct operations (`importComponent`, `applyModifiers`, `applyBoundModifiers`, `raise`, `env`, `evalScope`, `generated`, `codeBlock`, `persistent`, `content`, `hasBinding`, `bindResult`) — §5.5 |
21712171
| `src/eval-context.ts` | `compileBlock()` — delegates to `API.Env.compile` |
21722172
| `src/data-uri-compiler.ts` | `useDataUriCompiler()` — data: URI compiler middleware for Deno/Bun; owns `STANDARD_IMPORTS` |
21732173
| `src/temp-file-compiler.ts` | `useTempFileCompiler()` — temp-file compiler middleware for Node/Bun; owns `STANDARD_IMPORTS` |
@@ -5867,6 +5867,7 @@ interface, and each operation is also exported directly:
58675867
| `content(slot?)` | Render the invoking component's content, or a named slot of it; throws `ContentError` when that content fails (§5.1.2, §6.3) | throws a missing-provider error |
58685868
| `hasContent()` | Whether the invoking element was written with content rather than self-closed | throws a missing-provider error |
58695869
| `hasBinding()` | Whether the invocation has an engine-owned result binding — whether `as` was written (§6.10) | throws a missing-provider error |
5870+
| `bindResult(name)` | Reserve a separate JSON result binding in the caller scope and return a setter | throws: not inside a function component invocation |
58705871
| `hasCapture(name)` | Whether the invocation wrote this capture prop at all (§6.5) | `false` |
58715872
| `capture(name)` | Evaluate a capture prop now, against the caller's bindings, and deliver the result by reference (§6.5) | throws: not inside a function component invocation |
58725873
| `handleFailure(failure)` | What an ordinary function-component failure means, after complete invocation teardown (§6.9) | fails the operation with `failure.error` |
@@ -5965,8 +5966,8 @@ answers for itself: a nested invocation is not told about its caller's binding,
59655966
and two invocations that are live at once do not see each other's.
59665967

59675968
A value component with an additional JSON result can reserve its authored name
5968-
with `Component.operations.bindResult(name)`. It uses the same binding-name
5969-
rules and caller scope as `as`. Reserving requires `as` and a distinct name.
5969+
with `bindResult(name)`. It uses the same identifier validation and caller
5970+
scope as `as`. Reserving requires `as` and a distinct name.
59705971
The returned setter stages the value. The engine publishes staged values after
59715972
the invocation finishes, its resources close, and its primary return passes
59725973
validation.

‎specs/workflow-workspace-spec.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2366,7 +2366,8 @@ including `total_count`, `incomplete_results`, nullable fields and unfamiliar
23662366
members. Optional `nextAs` names a separate binding in the same scope. It
23672367
receives the complete search arguments for the next page, with the same query,
23682368
ordering and page size, or `null` when the pagination header offers no next
2369-
page within the accessible results. The two binding names must differ. The transport
2369+
page within the accessible results. Expansion validates the resolved `nextAs`
2370+
as a binding name distinct from `as`. The transport
23702371
headers and credentials stay with the adapter. An authentication or transport
23712372
failure, a malformed response, or an item from a different repository refuses
23722373
the read. A valid incomplete response

0 commit comments

Comments
 (0)