diff --git a/app/src/lib/graph-interface/graph-manager.svelte.ts b/app/src/lib/graph-interface/graph-manager.svelte.ts index 41519bc..5605929 100644 --- a/app/src/lib/graph-interface/graph-manager.svelte.ts +++ b/app/src/lib/graph-interface/graph-manager.svelte.ts @@ -197,12 +197,12 @@ export class GraphManager extends EventEmitter<{ this.status = "loading"; this.id = graph.id; - logger.info("loading graph", graph); + logger.info("loading graph", $state.snapshot(graph)); const nodeIds = Array.from(new Set([...graph.nodes.map((n) => n.type)])); await this.registry.load(nodeIds); - logger.info("loaded node types", this.registry.status); + logger.info("loaded node types", this.registry.getAllNodes()); for (const node of this.graph.nodes) { const nodeType = this.registry.getNode(node.type); diff --git a/packages/registry/src/node-registry-client.ts b/packages/registry/src/node-registry-client.ts index ba3839a..2e33ab5 100644 --- a/packages/registry/src/node-registry-client.ts +++ b/packages/registry/src/node-registry-client.ts @@ -13,7 +13,26 @@ export class RemoteNodeRegistry implements NodeRegistry { status: "loading" | "ready" | "error" = "loading"; private nodes: Map = new Map(); - fetch: typeof fetch = globalThis.fetch.bind(globalThis); + async fetchJson(url: string) { + const response = await fetch(`${this.url}/${url}`); + + if (!response.ok) { + log.error(`Failed to load ${url}`, { response, url, host: this.url }); + throw new Error(`Failed to load ${url}`); + } + + return response.json(); + } + + async fetchArrayBuffer(url: string) { + const response = await fetch(`${this.url}/${url}`); + if (!response.ok) { + log.error(`Failed to load ${url}`, { response, url, host: this.url }); + throw new Error(`Failed to load ${url}`); + } + + return response.arrayBuffer(); + } constructor( private url: string, @@ -21,46 +40,26 @@ export class RemoteNodeRegistry implements NodeRegistry { ) {} async fetchUsers() { - const response = await this.fetch(`${this.url}/nodes/users.json`); - if (!response.ok) { - throw new Error(`Failed to load users`); - } - return response.json(); + return this.fetchJson(`nodes/users.json`); } async fetchUser(userId: `${string}`) { - const response = await this.fetch(`${this.url}/user/${userId}.json`); - if (!response.ok) { - throw new Error(`Failed to load user ${userId}`); - } - return response.json(); + return this.fetchJson(`user/${userId}.json`); } async fetchCollection(userCollectionId: `${string}/${string}`) { - const response = await this.fetch( - `${this.url}/nodes/${userCollectionId}.json`, - ); - if (!response.ok) { - throw new Error(`Failed to load collection ${userCollectionId}`); - } - return response.json(); + return this.fetchJson(`nodes/${userCollectionId}.json`); } async fetchNodeDefinition(nodeId: `${string}/${string}/${string}`) { - const response = await this.fetch(`${this.url}/nodes/${nodeId}.json`); - if (!response.ok) { - throw new Error(`Failed to load node definition ${nodeId}`); - } - return response.json(); + return this.fetchJson(`nodes/${nodeId}.json`); } private async fetchNodeWasm(nodeId: `${string}/${string}/${string}`) { - const fetchNode = async () => { - const response = await this.fetch(`${this.url}/nodes/${nodeId}.wasm`); - return response.arrayBuffer(); - }; - - const res = await Promise.race([fetchNode(), this.cache?.get(nodeId)]); + const res = await Promise.race([ + this.fetchArrayBuffer(`nodes/${nodeId}.wasm`), + this.cache?.get(nodeId), + ]); if (!res) { throw new Error(`Failed to load node wasm ${nodeId}`);