feat: improve hash functions

This commit is contained in:
2024-04-16 13:30:14 +02:00
parent dec205b234
commit 3d3ea5b5f8
33 changed files with 1416 additions and 963 deletions

View File

@@ -1,39 +1,40 @@
{
"name": "node-registry",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "^8.56.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.3",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^1.2.0"
},
"type": "module",
"dependencies": {
"math": "link:../../nodes/math/pkg"
}
"name": "node-registry",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test": "vitest",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/kit": "^2.5.6",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@types/eslint": "^8.56.9",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.37.0",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.3",
"svelte": "^4.2.14",
"svelte-check": "^3.6.9",
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"vite": "^5.2.9",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^1.5.0"
},
"type": "module",
"dependencies": {
"@nodes/utils": "link:../utils",
"utils": "link:../utils"
}
}

View File

@@ -1,19 +1,8 @@
export async function getNodeWrapper(id: `${string}/${string}/${string}`) {
import { createWasmWrapper } from "@nodes/utils"
const wrapperReponse = await fetch(`/n/${id}/wrapper`);
if (!wrapperReponse.ok) {
throw new Error(`Failed to load node ${id}`);
}
let wrapperCode = await wrapperReponse.text();
wrapperCode = wrapperCode.replace("wasm = val;", `if(wasm) return;
wasm = val;`);
const wasmWrapper = await import(/*@vite-ignore*/`data:text/javascript;base64,${btoa(wrapperCode)}#${id}${Math.random().toString().slice(2)}`);
return wasmWrapper;
}
export async function getNodeWasm(id: `${string}/${string}/${string}`): Promise<WebAssembly.Instance> {
export async function getNodeWasm(id: `${string}/${string}/${string}`) {
const wasmResponse = await fetch(`/n/${id}/wasm`);
@@ -21,13 +10,12 @@ export async function getNodeWasm(id: `${string}/${string}/${string}`): Promise<
throw new Error(`Failed to load node ${id}`);
}
const wasmWrapper = await getNodeWrapper(id);
const wrapper = createWasmWrapper();
const module = new WebAssembly.Module(await wasmResponse.arrayBuffer());
const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wasmWrapper });
wasmWrapper.__wbg_set_wasm(instance.exports);
const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wrapper });
wrapper.setInstance(instance)
return wasmWrapper;
return wrapper;
}
@@ -35,8 +23,8 @@ export async function getNode(id: `${string}/${string}/${string}`) {
const wrapper = await getNodeWasm(id);
const outputs = wrapper.get_outputs();
const rawInputs = wrapper.get_input_types();
const outputs = wrapper?.get_outputs?.() || [];
const rawInputs = wrapper.get_inputs();
try {
const inputTypes = JSON.parse(rawInputs);
return { id, outputs, inputs: inputTypes }

View File

@@ -1,19 +0,0 @@
import type { RequestHandler } from "./$types";
import fs from "fs/promises";
import path from "path";
export const GET: RequestHandler = async function GET({ params }) {
const filePath = path.resolve(`../../nodes/${params.user}/${params.collection}/${params.node}/pkg/index_bg.js`);
try {
await fs.access(filePath);
} catch (e) {
console.log("Not Found", filePath);
return new Response("Not found", { status: 404 });
}
const file = await fs.readFile(filePath);
return new Response(file, { status: 200, headers: { "Content-Type": "text/javascript" } });
}