Rewrite core around shared rows and render graphs

Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a01380-b478-77d0-84a0-102880a5c5ae
This commit is contained in:
Amp
2026-08-19 15:30:32 +00:00
co-authored by heaust
parent d34722d66d
commit f12c7c9603
118 changed files with 687 additions and 34500 deletions
+8 -63
View File
@@ -1,67 +1,12 @@
import {
createGraphAst,
reference,
serializeGraphAst,
} from "@yawn/render-graph-ast";
import { createGraphAst, serializeGraphAst } from "@yawn/render-graph-ast";
/** Compiles a plain JavaScript object description into the canonical graph AST. */
export const graphFromObject = (description) => createGraphAst(description);
/** Converts a plain JavaScript object into the canonical render-graph AST. */
export const graphFromObject = graph => createGraphAst(graph);
/** Small mutable authoring facade; `ast()` returns an immutable canonical AST. */
export class RenderGraph {
#id;
#revision;
#nodes = [];
#render = [];
#compute = [];
constructor(id, revision = 1) {
this.#id = id;
this.#revision = revision;
}
renderPipeline(declaration) {
this.#render.push(structuredClone(declaration));
return this;
}
computePipeline(declaration) {
this.#compute.push(structuredClone(declaration));
return this;
}
node(id, executor, { version = 1, parameters = {}, inputs = {}, state = "enabled" } = {}) {
this.#nodes.push({
id,
state,
executor: { key: executor, version },
parameters: structuredClone(parameters),
inputs: structuredClone(inputs),
});
return this;
}
ast() {
return createGraphAst({
id: this.#id,
revision: this.#revision,
pipelines: { render: this.#render, compute: this.#compute },
nodes: this.#nodes,
});
}
serialize() {
return serializeGraphAst(this.ast());
}
load(core) {
return core.compileGraph(this.serialize());
}
/** Serializes a JSO graph and asks Yawn Core to prepare and activate its loadout. */
export function loadGraph(core, graph) {
if (!core?.loadGraph) throw new TypeError("core must be a YawnCore instance");
return core.loadGraph(serializeGraphAst(graphFromObject(graph)));
}
/** Canonicalizes a JSO/AST and sends its S-expression wire form to Yawn core. */
export function loadGraph(core, description) {
return core.compileGraph(serializeGraphAst(graphFromObject(description)));
}
export { reference as ref, serializeGraphAst };
export { serializeGraphAst };