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.status = "loading";
|
||||||
this.id = graph.id;
|
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)]));
|
const nodeIds = Array.from(new Set([...graph.nodes.map((n) => n.type)]));
|
||||||
await this.registry.load(nodeIds);
|
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) {
|
for (const node of this.graph.nodes) {
|
||||||
const nodeType = this.registry.getNode(node.type);
|
const nodeType = this.registry.getNode(node.type);
|
||||||
|
|||||||
@@ -13,7 +13,26 @@ export class RemoteNodeRegistry implements NodeRegistry {
|
|||||||
status: "loading" | "ready" | "error" = "loading";
|
status: "loading" | "ready" | "error" = "loading";
|
||||||
private nodes: Map<string, NodeDefinition> = new Map();
|
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(
|
constructor(
|
||||||
private url: string,
|
private url: string,
|
||||||
@@ -21,46 +40,26 @@ export class RemoteNodeRegistry implements NodeRegistry {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async fetchUsers() {
|
async fetchUsers() {
|
||||||
const response = await this.fetch(`${this.url}/nodes/users.json`);
|
return this.fetchJson(`nodes/users.json`);
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to load users`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchUser(userId: `${string}`) {
|
async fetchUser(userId: `${string}`) {
|
||||||
const response = await this.fetch(`${this.url}/user/${userId}.json`);
|
return this.fetchJson(`user/${userId}.json`);
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to load user ${userId}`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchCollection(userCollectionId: `${string}/${string}`) {
|
async fetchCollection(userCollectionId: `${string}/${string}`) {
|
||||||
const response = await this.fetch(
|
return this.fetchJson(`nodes/${userCollectionId}.json`);
|
||||||
`${this.url}/nodes/${userCollectionId}.json`,
|
|
||||||
);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to load collection ${userCollectionId}`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchNodeDefinition(nodeId: `${string}/${string}/${string}`) {
|
async fetchNodeDefinition(nodeId: `${string}/${string}/${string}`) {
|
||||||
const response = await this.fetch(`${this.url}/nodes/${nodeId}.json`);
|
return this.fetchJson(`nodes/${nodeId}.json`);
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to load node definition ${nodeId}`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fetchNodeWasm(nodeId: `${string}/${string}/${string}`) {
|
private async fetchNodeWasm(nodeId: `${string}/${string}/${string}`) {
|
||||||
const fetchNode = async () => {
|
const res = await Promise.race([
|
||||||
const response = await this.fetch(`${this.url}/nodes/${nodeId}.wasm`);
|
this.fetchArrayBuffer(`nodes/${nodeId}.wasm`),
|
||||||
return response.arrayBuffer();
|
this.cache?.get(nodeId),
|
||||||
};
|
]);
|
||||||
|
|
||||||
const res = await Promise.race([fetchNode(), this.cache?.get(nodeId)]);
|
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
throw new Error(`Failed to load node wasm ${nodeId}`);
|
throw new Error(`Failed to load node wasm ${nodeId}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user