Makros: GET/POST-Anfragen mit JSON-Ergebnis und FOR-Iteration
Erweitert die Makro-Sprache um Netzwerkzugriff: "x = GET(url)"/ "x = POST(url; body)" binden die geparste JSON-Antwort an eine Variable; FOR item IN x DO ... END iteriert, wenn x ein JSON-Array ist, über dessen Elemente; JSONGET(wert; pfad) liest ein Feld heraus (punktgetrennt, Zahl = Array-Index) und funktioniert – anders als GET/POST – überall in einem Ausdruck verschachtelt, nicht nur als ganze Zuweisung. Da ein echter Netzwerkaufruf nicht synchron laufen kann, ohne den Tab einzufrieren, bekommt der Makro-Interpreter einen separaten asynchronen Zweig (execBlockAsync/execStatementAsync); der bestehende synchrone Interpreter, den auch gewöhnliche "Mit Schleife"-Funktionen mitten in der synchronen Neuberechnung nutzen, bleibt unangetastet. Netzwerkaufrufe werden pro Makro einmalig mit Zielname bestätigt (dauerhaft gemerkt); die bestehende "ein Lauf = ein Undo-Schritt"-Garantie, die bislang auf Synchronität beruhte, wird jetzt explizit wiederhergestellt statt sich weiter auf die Zeit-Koaleszenz zu verlassen. Zwei echte Lücken erst beim eigenen Live-Test gefunden und behoben: (1) JSONGET direkt in eine Aktion verschachtelt (statt erst einer Variable zugewiesen) scheiterte zunächst an #NAME?; (2) JSONGET(...) direkt als FOR-Quelle (ohne Zwischenvariable) scheiterte sowohl an der Speicher-Zeit-Prüfung als auch zur Laufzeit, da substitute() einen Funktionsaufruf nie auswertet. Live gegen eine neue same-origin-Fixture (public/test-fixtures/sample.json) verifiziert: echter GET, echter Bestätigungsdialog, FOR/JSONGET über die echte Antwort, kein erneuter Dialog beim zweiten Lauf. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -179,3 +179,27 @@ export interface MacroWriteHost {
|
||||
renameSheet(sheetRef: string, newName: string): void;
|
||||
deleteSheet(sheetRef: string): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The document's NETWORK surface, as seen by a running macro's `GET`/`POST`
|
||||
* assignment form (`x = GET(url)` / `x = POST(url; body)`; see evaluator.
|
||||
* ts's `execStatementAsync`). Kept separate from {@link MacroWriteHost} for
|
||||
* the same reason that one is kept separate from {@link EngineHost}: this
|
||||
* engine module stays framework/DOM-agnostic (no `fetch`, no browser APIs
|
||||
* anywhere in `src/engine/`) -- the store (`document.ts#runMacro`) is the
|
||||
* only implementer, and it's the one place a network confirmation prompt
|
||||
* and the actual `fetch()` call belong.
|
||||
*
|
||||
* A single `request()` method (not separate `get`/`post` methods) because
|
||||
* both share the exact same "confirm this host once, then fetch and parse
|
||||
* JSON" flow in the implementation -- only the HTTP method and whether a
|
||||
* body is sent differ.
|
||||
*/
|
||||
export interface MacroNetworkHost {
|
||||
/** Resolves with the parsed JSON response body, or rejects with a plain
|
||||
* `Error` (network failure, a non-2xx status, a response that isn't
|
||||
* valid JSON, or the user declining a host-confirmation prompt) --
|
||||
* caught the same way as any other macro action failure, aborting the
|
||||
* run and surfacing the message as the result's `.message`. */
|
||||
request(method: 'GET' | 'POST', url: string, body?: string): Promise<unknown>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user