chore: log some more stuff during registry
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m31s
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m31s
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -13,7 +13,26 @@ export class RemoteNodeRegistry implements NodeRegistry {
|
||||
status: "loading" | "ready" | "error" = "loading";
|
||||
private nodes: Map<string, NodeDefinition> = 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}`);
|
||||
|
||||
Reference in New Issue
Block a user