feat: track images with git lfs
This commit is contained in:
13
packages/input-elements/.eslintignore
Normal file
13
packages/input-elements/.eslintignore
Normal file
@ -0,0 +1,13 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
30
packages/input-elements/.eslintrc.cjs
Normal file
30
packages/input-elements/.eslintrc.cjs
Normal file
@ -0,0 +1,30 @@
|
||||
/** @type { import("eslint").Linter.Config } */
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:svelte/recommended'
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2020,
|
||||
extraFileExtensions: ['.svelte']
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es2017: true,
|
||||
node: true
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.svelte'],
|
||||
parser: 'svelte-eslint-parser',
|
||||
parserOptions: {
|
||||
parser: '@typescript-eslint/parser'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
11
packages/input-elements/.gitignore
vendored
Normal file
11
packages/input-elements/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/dist
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
1
packages/input-elements/.npmrc
Normal file
1
packages/input-elements/.npmrc
Normal file
@ -0,0 +1 @@
|
||||
engine-strict=true
|
58
packages/input-elements/README.md
Normal file
58
packages/input-elements/README.md
Normal file
@ -0,0 +1,58 @@
|
||||
# create-svelte
|
||||
|
||||
Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
|
||||
|
||||
Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm create svelte@latest
|
||||
|
||||
# create a new project in my-app
|
||||
npm create svelte@latest my-app
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
|
||||
|
||||
## Building
|
||||
|
||||
To build your library:
|
||||
|
||||
```bash
|
||||
npm run package
|
||||
```
|
||||
|
||||
To create a production version of your showcase app:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
||||
|
||||
## Publishing
|
||||
|
||||
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
|
||||
|
||||
To publish your library to [npm](https://www.npmjs.com):
|
||||
|
||||
```bash
|
||||
npm publish
|
||||
```
|
53
packages/input-elements/package.json
Normal file
53
packages/input-elements/package.json
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "@nodes/input-elements",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build && npm run package",
|
||||
"preview": "vite preview",
|
||||
"package": "svelte-kit sync && svelte-package && publint",
|
||||
"prepublishOnly": "npm run package",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"test": "vitest",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"svelte": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"!dist/**/*.test.*",
|
||||
"!dist/**/*.spec.*"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"svelte": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^3.0.0",
|
||||
"@sveltejs/kit": "^2.0.0",
|
||||
"@sveltejs/package": "^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-plugin-svelte": "^2.35.1",
|
||||
"publint": "^0.1.9",
|
||||
"svelte": "^4.2.7",
|
||||
"svelte-check": "^3.6.0",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^5.0.0",
|
||||
"vite": "^5.0.11",
|
||||
"vitest": "^1.2.0"
|
||||
},
|
||||
"svelte": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@nodes/types": "link:../types"
|
||||
}
|
||||
}
|
13
packages/input-elements/src/app.d.ts
vendored
Normal file
13
packages/input-elements/src/app.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
12
packages/input-elements/src/app.html
Normal file
12
packages/input-elements/src/app.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div>%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
7
packages/input-elements/src/index.test.ts
Normal file
7
packages/input-elements/src/index.test.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('sum test', () => {
|
||||
it('adds 1 + 2 to equal 3', () => {
|
||||
expect(1 + 2).toBe(3);
|
||||
});
|
||||
});
|
21
packages/input-elements/src/lib/Input.svelte
Normal file
21
packages/input-elements/src/lib/Input.svelte
Normal file
@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import Checkbox from "$lib/elements/Checkbox.svelte";
|
||||
import Float from "$lib/elements/Float.svelte";
|
||||
import Integer from "$lib/elements/Integer.svelte";
|
||||
import Select from "$lib/elements/Select.svelte";
|
||||
|
||||
import type { NodeInput } from "@nodes/types";
|
||||
|
||||
export let input: NodeInput;
|
||||
export let value: any;
|
||||
</script>
|
||||
|
||||
{#if input.type === "float"}
|
||||
<Float bind:value />
|
||||
{:else if input.type === "integer"}
|
||||
<Integer bind:value />
|
||||
{:else if input.type === "boolean"}
|
||||
<Checkbox bind:value />
|
||||
{:else if input.type === "select"}
|
||||
<Select labels={input.labels} bind:value />
|
||||
{/if}
|
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Checkbox from "./Checkbox.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Checkbox checked={false} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
58
packages/input-elements/src/lib/elements/Checkbox.svelte
Normal file
58
packages/input-elements/src/lib/elements/Checkbox.svelte
Normal file
@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
export let value: boolean;
|
||||
</script>
|
||||
|
||||
<input type="checkbox" bind:checked={value} />
|
||||
|
||||
<style>
|
||||
input[type="checkbox"] {
|
||||
/* Add if not using autoprefixer */
|
||||
-webkit-appearance: none;
|
||||
/* Remove most all native input styles */
|
||||
appearance: none;
|
||||
/* For iOS < 15 */
|
||||
background-color: var(--form-background);
|
||||
/* Not removed via appearance */
|
||||
margin: 0;
|
||||
|
||||
font: inherit;
|
||||
color: currentColor;
|
||||
width: 1.15em;
|
||||
height: 1.15em;
|
||||
border: 0.15em solid currentColor;
|
||||
border-radius: 0.15em;
|
||||
transform: translateY(-0.075em);
|
||||
|
||||
display: grid;
|
||||
place-content: center;
|
||||
}
|
||||
|
||||
input[type="checkbox"]::before {
|
||||
content: "";
|
||||
width: 0.65em;
|
||||
height: 0.65em;
|
||||
clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
|
||||
transform: scale(0);
|
||||
transform-origin: bottom left;
|
||||
transition: 120ms transform ease-in-out;
|
||||
box-shadow: inset 1em 1em var(--form-control-color);
|
||||
/* Windows High Contrast Mode */
|
||||
background-color: CanvasText;
|
||||
}
|
||||
|
||||
input[type="checkbox"]:checked::before {
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
input[type="checkbox"]:focus {
|
||||
outline: max(2px, 0.15em) solid currentColor;
|
||||
outline-offset: max(2px, 0.15em);
|
||||
}
|
||||
|
||||
input[type="checkbox"]:disabled {
|
||||
--form-control-color: var(--form-control-disabled);
|
||||
|
||||
color: var(--form-control-disabled);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
17
packages/input-elements/src/lib/elements/Float.story.svelte
Normal file
17
packages/input-elements/src/lib/elements/Float.story.svelte
Normal file
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Float from "./Float.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Float value={0} min={0} max={6.9} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
19
packages/input-elements/src/lib/elements/Float.svelte
Normal file
19
packages/input-elements/src/lib/elements/Float.svelte
Normal file
@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
export let value: number = 0;
|
||||
export let min = 0;
|
||||
export let max = 10;
|
||||
export let step = 0.1;
|
||||
</script>
|
||||
|
||||
<input type="number" bind:value {min} {max} {step} />
|
||||
|
||||
<style>
|
||||
input {
|
||||
background: var(--background-color-lighter);
|
||||
color: var(--text-color);
|
||||
font-family: var(--font-family);
|
||||
padding: 0.8em 1em;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Integer from "./Integer.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Integer value={5} min={0} max={42} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
9
packages/input-elements/src/lib/elements/Integer.svelte
Normal file
9
packages/input-elements/src/lib/elements/Integer.svelte
Normal file
@ -0,0 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let value: number = 0;
|
||||
export let min = 0;
|
||||
export let max = 10;
|
||||
export let step = 1;
|
||||
</script>
|
||||
|
||||
<input type="number" bind:value {min} {max} {step} />
|
||||
|
17
packages/input-elements/src/lib/elements/Select.story.svelte
Normal file
17
packages/input-elements/src/lib/elements/Select.story.svelte
Normal file
@ -0,0 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Hst } from "@histoire/plugin-svelte";
|
||||
export let Hst: Hst;
|
||||
import Select from "./Select.svelte";
|
||||
</script>
|
||||
|
||||
<Hst.Story>
|
||||
<div>
|
||||
<Select value={"banana"} options={["strawberry", "apple", "banana"]} />
|
||||
</div>
|
||||
</Hst.Story>
|
||||
|
||||
<style>
|
||||
div {
|
||||
padding: 1em;
|
||||
}
|
||||
</style>
|
21
packages/input-elements/src/lib/elements/Select.svelte
Normal file
21
packages/input-elements/src/lib/elements/Select.svelte
Normal file
@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
export let labels: string[] = [];
|
||||
export let value: number = 0;
|
||||
</script>
|
||||
|
||||
<select bind:value>
|
||||
{#each labels as label, i}
|
||||
<option value={i}>{label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<style>
|
||||
select {
|
||||
background: var(--background-color-lighter);
|
||||
color: var(--text-color);
|
||||
font-family: var(--font-family);
|
||||
padding: 0.8em 1em;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
11
packages/input-elements/src/lib/index.ts
Normal file
11
packages/input-elements/src/lib/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// Reexport your entry components here
|
||||
import Input from './Input.svelte';
|
||||
|
||||
import Float from "./elements/Float.svelte";
|
||||
import Integer from "./elements/Integer.svelte";
|
||||
import Select from "./elements/Select.svelte";
|
||||
import Checkbox from "./elements/Checkbox.svelte";
|
||||
|
||||
export { Float, Integer, Select, Checkbox };
|
||||
|
||||
export default Input;
|
3
packages/input-elements/src/routes/+page.svelte
Normal file
3
packages/input-elements/src/routes/+page.svelte
Normal file
@ -0,0 +1,3 @@
|
||||
<h1>Welcome to your library project</h1>
|
||||
<p>Create your package using @sveltejs/package and preview/showcase your work with SvelteKit</p>
|
||||
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
|
BIN
packages/input-elements/static/favicon.png
Normal file
BIN
packages/input-elements/static/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
18
packages/input-elements/svelte.config.js
Normal file
18
packages/input-elements/svelte.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import adapter from '@sveltejs/adapter-auto';
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
||||
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
|
||||
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
15
packages/input-elements/tsconfig.json
Normal file
15
packages/input-elements/tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext"
|
||||
}
|
||||
}
|
9
packages/input-elements/vite.config.ts
Normal file
9
packages/input-elements/vite.config.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [sveltekit()],
|
||||
test: {
|
||||
include: ['src/**/*.{test,spec}.{js,ts}']
|
||||
}
|
||||
});
|
12
packages/node-registry-client/package.json
Normal file
12
packages/node-registry-client/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@node/registry-client",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
13
packages/node-registry/.eslintignore
Normal file
13
packages/node-registry/.eslintignore
Normal file
@ -0,0 +1,13 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
31
packages/node-registry/.eslintrc.cjs
Normal file
31
packages/node-registry/.eslintrc.cjs
Normal file
@ -0,0 +1,31 @@
|
||||
/** @type { import("eslint").Linter.Config } */
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:svelte/recommended',
|
||||
'prettier'
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2020,
|
||||
extraFileExtensions: ['.svelte']
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es2017: true,
|
||||
node: true
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.svelte'],
|
||||
parser: 'svelte-eslint-parser',
|
||||
parserOptions: {
|
||||
parser: '@typescript-eslint/parser'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
10
packages/node-registry/.gitignore
vendored
Normal file
10
packages/node-registry/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
1
packages/node-registry/.npmrc
Normal file
1
packages/node-registry/.npmrc
Normal file
@ -0,0 +1 @@
|
||||
engine-strict=true
|
4
packages/node-registry/.prettierignore
Normal file
4
packages/node-registry/.prettierignore
Normal file
@ -0,0 +1,4 @@
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
8
packages/node-registry/.prettierrc
Normal file
8
packages/node-registry/.prettierrc
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100,
|
||||
"plugins": ["prettier-plugin-svelte"],
|
||||
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||
}
|
38
packages/node-registry/README.md
Normal file
38
packages/node-registry/README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# create-svelte
|
||||
|
||||
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm create svelte@latest
|
||||
|
||||
# create a new project in my-app
|
||||
npm create svelte@latest my-app
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To create a production version of your app:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
39
packages/node-registry/package.json
Normal file
39
packages/node-registry/package.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
13
packages/node-registry/src/app.d.ts
vendored
Normal file
13
packages/node-registry/src/app.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
12
packages/node-registry/src/app.html
Normal file
12
packages/node-registry/src/app.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
7
packages/node-registry/src/index.test.ts
Normal file
7
packages/node-registry/src/index.test.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('sum test', () => {
|
||||
it('adds 1 + 2 to equal 3', () => {
|
||||
expect(1 + 2).toBe(3);
|
||||
});
|
||||
});
|
1
packages/node-registry/src/lib/index.ts
Normal file
1
packages/node-registry/src/lib/index.ts
Normal file
@ -0,0 +1 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
2
packages/node-registry/src/routes/+page.svelte
Normal file
2
packages/node-registry/src/routes/+page.svelte
Normal file
@ -0,0 +1,2 @@
|
||||
<h1>Welcome to SvelteKit</h1>
|
||||
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
|
@ -0,0 +1,14 @@
|
||||
import { json } from "@sveltejs/kit";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const GET: RequestHandler = async function GET({ fetch }) {
|
||||
const d = await fetch("/max/plantarium/math/wasm");
|
||||
const wrapWasm = await import("./wrap-wasm");
|
||||
const module = new WebAssembly.Module(await d.arrayBuffer());
|
||||
const instance = new WebAssembly.Instance(module, { "./math_bg.js": wrapWasm });
|
||||
wrapWasm.__wbg_set_wasm(instance.exports);
|
||||
const id = wrapWasm.get_id();
|
||||
const outputs = wrapWasm.get_outputs();
|
||||
const inputTypes = JSON.parse(wrapWasm.get_input_types());
|
||||
return json({ id, outputs, inputs: inputTypes, });
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
import type { RequestHandler } from "./$types";
|
||||
import fs from "fs/promises";
|
||||
|
||||
export const GET: RequestHandler = async function GET({ fetch, params }) {
|
||||
|
||||
const path = `../../../../../../../../nodes/${params.user}/${params.collection}/${params.node}/pkg/${params.node}_bg.wasm`;
|
||||
|
||||
const file = await fs.readFile(path);
|
||||
|
||||
console.log({ file });
|
||||
|
||||
|
||||
const bytes = new Uint8Array([]);
|
||||
return new Response(bytes, { status: 200, headers: { "Content-Type": "application/wasm" } });
|
||||
}
|
@ -0,0 +1,273 @@
|
||||
let wasm;
|
||||
export function __wbg_set_wasm(val) {
|
||||
if (wasm) return;
|
||||
wasm = val;
|
||||
}
|
||||
|
||||
const heap = new Array(128).fill(undefined);
|
||||
|
||||
heap.push(undefined, null, true, false);
|
||||
|
||||
function getObject(idx) { return heap[idx]; }
|
||||
|
||||
let heap_next = heap.length;
|
||||
|
||||
function dropObject(idx) {
|
||||
if (idx < 132) return;
|
||||
heap[idx] = heap_next;
|
||||
heap_next = idx;
|
||||
}
|
||||
|
||||
function takeObject(idx) {
|
||||
const ret = getObject(idx);
|
||||
dropObject(idx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
function isLikeNone(x) {
|
||||
return x === undefined || x === null;
|
||||
}
|
||||
|
||||
let cachedFloat64Memory0 = null;
|
||||
|
||||
function getFloat64Memory0() {
|
||||
if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {
|
||||
cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedFloat64Memory0;
|
||||
}
|
||||
|
||||
let cachedInt32Memory0 = null;
|
||||
|
||||
function getInt32Memory0() {
|
||||
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
|
||||
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedInt32Memory0;
|
||||
}
|
||||
|
||||
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
||||
|
||||
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
|
||||
cachedTextDecoder.decode();
|
||||
|
||||
let cachedUint8Memory0 = null;
|
||||
|
||||
function getUint8Memory0() {
|
||||
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
||||
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8Memory0;
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
function addHeapObject(obj) {
|
||||
if (heap_next === heap.length) heap.push(heap.length + 1);
|
||||
const idx = heap_next;
|
||||
heap_next = heap[idx];
|
||||
|
||||
heap[idx] = obj;
|
||||
return idx;
|
||||
}
|
||||
|
||||
let cachedUint32Memory0 = null;
|
||||
|
||||
function getUint32Memory0() {
|
||||
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
|
||||
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint32Memory0;
|
||||
}
|
||||
|
||||
function getArrayJsValueFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
const mem = getUint32Memory0();
|
||||
const slice = mem.subarray(ptr / 4, ptr / 4 + len);
|
||||
const result = [];
|
||||
for (let i = 0; i < slice.length; i++) {
|
||||
result.push(takeObject(slice[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @returns {(string)[]}
|
||||
*/
|
||||
export function get_outputs() {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
wasm.get_outputs(retptr);
|
||||
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
||||
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
||||
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
|
||||
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
||||
return v1;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
export function get_id() {
|
||||
let deferred1_0;
|
||||
let deferred1_1;
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
wasm.get_id(retptr);
|
||||
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
||||
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
||||
deferred1_0 = r0;
|
||||
deferred1_1 = r1;
|
||||
return getStringFromWasm0(r0, r1);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
export function get_input_types() {
|
||||
let deferred1_0;
|
||||
let deferred1_1;
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
wasm.get_input_types(retptr);
|
||||
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
||||
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
||||
deferred1_0 = r0;
|
||||
deferred1_1 = r1;
|
||||
return getStringFromWasm0(r0, r1);
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} var_op_type
|
||||
* @param {any} var_a
|
||||
* @param {any} var_b
|
||||
* @returns {number}
|
||||
*/
|
||||
export function execute(var_op_type, var_a, var_b) {
|
||||
const ret = wasm.execute(addHeapObject(var_op_type), addHeapObject(var_a), addHeapObject(var_b));
|
||||
return ret;
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
|
||||
|
||||
let cachedTextEncoder = new lTextEncoder('utf-8');
|
||||
|
||||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
||||
? function (arg, view) {
|
||||
return cachedTextEncoder.encodeInto(arg, view);
|
||||
}
|
||||
: function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
});
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len, 1) >>> 0;
|
||||
|
||||
const mem = getUint8Memory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
||||
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = encodeString(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
export function __wbg_new_abda76e883ba8a5f() {
|
||||
const ret = new Error();
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
||||
export function __wbg_stack_658279fe44541cf6(arg0, arg1) {
|
||||
const ret = getObject(arg1).stack;
|
||||
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
||||
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
||||
};
|
||||
|
||||
export function __wbg_error_f851667af71bcfc6(arg0, arg1) {
|
||||
let deferred0_0;
|
||||
let deferred0_1;
|
||||
try {
|
||||
deferred0_0 = arg0;
|
||||
deferred0_1 = arg1;
|
||||
console.error(getStringFromWasm0(arg0, arg1));
|
||||
} finally {
|
||||
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
||||
}
|
||||
};
|
||||
|
||||
export function __wbindgen_object_drop_ref(arg0) {
|
||||
takeObject(arg0);
|
||||
};
|
||||
|
||||
export function __wbindgen_is_undefined(arg0) {
|
||||
const ret = getObject(arg0) === undefined;
|
||||
return ret;
|
||||
};
|
||||
|
||||
export function __wbindgen_is_null(arg0) {
|
||||
const ret = getObject(arg0) === null;
|
||||
return ret;
|
||||
};
|
||||
|
||||
export function __wbindgen_number_get(arg0, arg1) {
|
||||
const obj = getObject(arg1);
|
||||
const ret = typeof (obj) === 'number' ? obj : undefined;
|
||||
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
|
||||
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
|
||||
};
|
||||
|
||||
export function __wbindgen_string_new(arg0, arg1) {
|
||||
const ret = getStringFromWasm0(arg0, arg1);
|
||||
return addHeapObject(ret);
|
||||
};
|
||||
|
BIN
packages/node-registry/static/favicon.png
Normal file
BIN
packages/node-registry/static/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
18
packages/node-registry/svelte.config.js
Normal file
18
packages/node-registry/svelte.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import adapter from '@sveltejs/adapter-auto';
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
||||
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
|
||||
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
19
packages/node-registry/tsconfig.json
Normal file
19
packages/node-registry/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
}
|
||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||
// except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
|
||||
//
|
||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||
// from the referenced tsconfig.json - TypeScript does not merge them in
|
||||
}
|
10
packages/node-registry/vite.config.ts
Normal file
10
packages/node-registry/vite.config.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vitest/config';
|
||||
import wasm from 'vite-plugin-wasm';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [sveltekit(), wasm()],
|
||||
test: {
|
||||
include: ['src/**/*.{test,spec}.{js,ts}']
|
||||
}
|
||||
});
|
@ -1,9 +0,0 @@
|
||||
[package]
|
||||
name = "node_registry_rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
wasmtime = "18.0.2"
|
@ -1,107 +0,0 @@
|
||||
use std::{
|
||||
ffi::{c_char, CStr},
|
||||
fs,
|
||||
};
|
||||
use wasmtime::*;
|
||||
|
||||
pub struct NodeRegistryCore {
|
||||
storage_path: String,
|
||||
}
|
||||
|
||||
impl NodeRegistryCore {
|
||||
pub fn new(storage_path: &str) -> NodeRegistryCore {
|
||||
NodeRegistryCore {
|
||||
storage_path: storage_path.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_node_definition(
|
||||
&self,
|
||||
_author: &str,
|
||||
_namespace: &str,
|
||||
node_id: &str,
|
||||
) -> Result<String, String> {
|
||||
let bytes = self.get_node(_author, _namespace, node_id)?;
|
||||
|
||||
let engine = Engine::default();
|
||||
let mut store = Store::new(&engine, ());
|
||||
let module = Module::new(&engine, bytes).map_err(|err| {
|
||||
println!("{}", err);
|
||||
err.to_string()
|
||||
})?;
|
||||
let instance = Instance::new(&mut store, &module, &[]).map_err(|_| "asd".to_string())?;
|
||||
|
||||
let get_definition_len = instance
|
||||
.get_func(&mut store, "get_definition_len")
|
||||
.ok_or("Failed to find 'get_definition_len' function export")?;
|
||||
let get_definition_len_func = get_definition_len
|
||||
.typed::<(), i32>(&store)
|
||||
.map_err(|err| err.to_string())?;
|
||||
let len = get_definition_len_func
|
||||
.call(&mut store, ())
|
||||
.map_err(|err| err.to_string())?;
|
||||
|
||||
// Access the exports
|
||||
let get_definition_ptr = instance
|
||||
.get_func(&mut store, "get_definition")
|
||||
.ok_or("Failed to find 'get_definition' function export")?;
|
||||
let get_definition_func = get_definition_ptr
|
||||
.typed::<(), i32>(&store)
|
||||
.map_err(|err| err.to_string())?;
|
||||
let ptr = get_definition_func
|
||||
.call(&mut store, ())
|
||||
.map_err(|err| err.to_string())?;
|
||||
|
||||
println!("{} {}", ptr, len);
|
||||
|
||||
Ok("Dude".to_string())
|
||||
}
|
||||
|
||||
// Function that takes a string and returns bytes
|
||||
pub fn get_node(
|
||||
&self,
|
||||
_author: &str,
|
||||
_namespace: &str,
|
||||
node_id: &str,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let res = fs::read_dir(&self.storage_path).map_err(|_| "Could not read dir")?;
|
||||
|
||||
let file_names = res
|
||||
.filter_map(|entry| match entry {
|
||||
Ok(entry) => {
|
||||
let file_type = entry.file_type().ok()?;
|
||||
let file_path = entry.path();
|
||||
|
||||
// Skip directories
|
||||
if file_type.is_dir() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Extract file name and extension
|
||||
let file_name = entry.file_name().to_string_lossy().into_owned();
|
||||
let extension = file_path.extension()?.to_string_lossy().into_owned();
|
||||
|
||||
if !file_name.starts_with(node_id) {
|
||||
return None;
|
||||
}
|
||||
|
||||
if extension != "wasm" {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(file_name)
|
||||
}
|
||||
Err(_) => None,
|
||||
})
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
if let Some(file_name) = file_names.get(0) {
|
||||
let bytes = fs::read(self.storage_path.clone() + "/" + file_name)
|
||||
.map_err(|_| "Could not read file".to_string())?;
|
||||
|
||||
Ok(bytes)
|
||||
} else {
|
||||
Err("Not Found".into())
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
[package]
|
||||
name = "node_registry_server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
async-std = { version = "1.6.0", features = ["attributes"] }
|
||||
node_registry_rust = { path = "../node_registry_rust" }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
tide = "0.16.0"
|
@ -1,39 +0,0 @@
|
||||
use node_registry_rust::NodeRegistryCore;
|
||||
use tide::Request;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> tide::Result<()> {
|
||||
let mut app = tide::new();
|
||||
app.at("/").get(index);
|
||||
app.at("/nodes/:author/:namespace/:node_id").get(get_node);
|
||||
app.listen("0.0.0.0:8080").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_node(req: Request<()>) -> tide::Result {
|
||||
let author = req.param("author")?;
|
||||
let namespace = req.param("namespace")?;
|
||||
let node_id = req.param("node_id")?;
|
||||
let node_registry = NodeRegistryCore::new("../../target/wasm32-unknown-unknown/release");
|
||||
|
||||
if node_id.ends_with(".json") {
|
||||
let res =
|
||||
node_registry.get_node_definition(author, namespace, &node_id.replace(".json", ""));
|
||||
|
||||
match res {
|
||||
Ok(res) => Ok(format!("Hello {}", res).into()),
|
||||
Err(er) => Ok(format!("Err: {}", er).into()),
|
||||
}
|
||||
} else {
|
||||
let res = node_registry.get_node(author, namespace, node_id);
|
||||
|
||||
match res {
|
||||
Ok(res) => Ok(format!("Hello {}", res.len()).into()),
|
||||
Err(er) => Ok(format!("Err: {}", er).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn index(_req: Request<()>) -> tide::Result {
|
||||
Ok(format!("Hello {}", "World").into())
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "runtime_executor_rust"
|
||||
name = "plantarium"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
wasmtime = "18.0.1"
|
||||
wasm-bindgen = "0.2.92"
|
15
packages/plantarium/src/helpers.rs
Normal file
15
packages/plantarium/src/helpers.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub fn unwrap_int(val: JsValue) -> u8 {
|
||||
if val.is_undefined() || val.is_null() {
|
||||
panic!("Value is undefined");
|
||||
}
|
||||
return val.as_f64().unwrap() as u8;
|
||||
}
|
||||
|
||||
pub fn unwrap_float(val: JsValue) -> f64 {
|
||||
if val.is_undefined() || val.is_null() {
|
||||
panic!("Value is undefined");
|
||||
}
|
||||
return val.as_f64().unwrap();
|
||||
}
|
2
packages/plantarium/src/lib.rs
Normal file
2
packages/plantarium/src/lib.rs
Normal file
@ -0,0 +1,2 @@
|
||||
mod helpers;
|
||||
pub use helpers::*;
|
@ -1,9 +0,0 @@
|
||||
[package]
|
||||
name = "runtime_executor_rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
wasmtime = "18.0.1"
|
@ -1,63 +0,0 @@
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use wasmtime::*;
|
||||
|
||||
fn get_current_working_dir() -> std::io::Result<PathBuf> {
|
||||
env::current_dir()
|
||||
}
|
||||
|
||||
pub fn run_nodes() -> Result<i32, String> {
|
||||
// An engine stores and configures global compilation settings like
|
||||
// optimization level, enabled wasm features, etc.
|
||||
let engine = Engine::default();
|
||||
|
||||
let pwd = get_current_working_dir().expect("Cant get wkring dir");
|
||||
println!(
|
||||
"{}",
|
||||
pwd.into_os_string().into_string().expect("cant unwrap")
|
||||
);
|
||||
|
||||
// We start off by creating a `Module` which represents a compiled form
|
||||
// of our input wasm module. In this case it'll be JIT-compiled after
|
||||
// we parse the text format.
|
||||
let module =
|
||||
Module::from_file(&engine, "src/hello.wat").expect("Could not instatiate hello.wat");
|
||||
|
||||
// A `Store` is what will own instances, functions, globals, etc. All wasm
|
||||
// items are stored within a `Store`, and it's what we'll always be using to
|
||||
// interact with the wasm world. Custom data can be stored in stores but for
|
||||
// now we just use `()`.
|
||||
let mut store = Store::new(&engine, ());
|
||||
|
||||
// With a compiled `Module` we can then instantiate it, creating
|
||||
// an `Instance` which we can actually poke at functions on.
|
||||
let instance = Instance::new(&mut store, &module, &[]).expect("Could not instatiate module");
|
||||
|
||||
// The `Instance` gives us access to various exported functions and items,
|
||||
// which we access here to pull out our `answer` exported function and
|
||||
// run it.
|
||||
let answer = instance
|
||||
.get_func(&mut store, "answer")
|
||||
.expect("`answer` was not an exported function");
|
||||
|
||||
// There's a few ways we can call the `answer` `Func` value. The easiest
|
||||
// is to statically assert its signature with `typed` (in this case
|
||||
// asserting it takes no arguments and returns one i32) and then call it.
|
||||
let answer = answer
|
||||
.typed::<(), i32>(&store)
|
||||
.expect("Can't access answer function");
|
||||
|
||||
// And finally we can call our function! Note that the error propagation
|
||||
// with `?` is done to handle the case where the wasm function traps.
|
||||
let result = answer
|
||||
.call(&mut store, ())
|
||||
.expect("Could not call function");
|
||||
println!("Answer: {:?}", result);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Duude");
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
pub struct NodeRegistryCore {
|
||||
storage_path: String,
|
||||
}
|
||||
|
||||
impl NodeRegistryCore {
|
||||
pub fn new(storage_path: &str) -> NodeRegistryCore {
|
||||
NodeRegistryCore {
|
||||
storage_path: storage_path.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
// Function that takes a string and returns bytes
|
||||
pub fn string_to_bytes(&self, input: &str) -> Vec<u8> {
|
||||
// Combine the initialization argument and input string into bytes
|
||||
let result: Vec<u8> = format!("{} {}", self.storage_path, input).into_bytes();
|
||||
result
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
use wasmtime::{Config, Engine, component::Component, component::Instance};
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn get_current_working_dir() -> std::io::Result<PathBuf> {
|
||||
env::current_dir()
|
||||
}
|
||||
|
||||
pub fn run_nodes() -> Result<i32, String> {
|
||||
|
||||
let mut config = Config::new();
|
||||
config.wasm_multi_memory(true);
|
||||
config.wasm_component_model(true);
|
||||
|
||||
// An engine stores and configures global compilation settings like
|
||||
// optimization level, enabled wasm features, etc.
|
||||
let engine = Engine::new(&config).expect("Could not create engine");
|
||||
|
||||
|
||||
let component = Component::from_file(&engine, "../../target/wasm32-unknown-unknown/release/add.wasm").expect("Could not load add.wasm");
|
||||
|
||||
let resources = component.resources_required()
|
||||
.expect("this component does not import any core modules or instances");
|
||||
|
||||
println!("{}", resources.num_memories);
|
||||
|
||||
let instance = Instance::new(&engine, component);
|
||||
|
||||
|
||||
Ok(12)
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let _ = run_nodes();
|
||||
}
|
@ -1,3 +1,67 @@
|
||||
interface Node {
|
||||
import type { NodeInput } from "./inputs";
|
||||
export type { NodeInput } from "./inputs";
|
||||
|
||||
export type Node = {
|
||||
id: number;
|
||||
type: string;
|
||||
props?: Record<string, any>,
|
||||
tmp?: {
|
||||
depth?: number;
|
||||
mesh?: any;
|
||||
parents?: Node[],
|
||||
children?: Node[],
|
||||
inputNodes?: Record<string, Node>
|
||||
type?: NodeType;
|
||||
downX?: number;
|
||||
downY?: number;
|
||||
x?: number;
|
||||
y?: number;
|
||||
ref?: HTMLElement;
|
||||
visible?: boolean;
|
||||
isMoving?: boolean;
|
||||
},
|
||||
meta?: {
|
||||
title?: string;
|
||||
lastModified?: string;
|
||||
},
|
||||
position: [x: number, y: number]
|
||||
}
|
||||
|
||||
export type NodeType = {
|
||||
id: string;
|
||||
inputs?: Record<string, NodeInput>
|
||||
outputs?: string[];
|
||||
meta?: {
|
||||
title?: string;
|
||||
},
|
||||
execute?: (inputs: Record<string, string | number | boolean>) => unknown;
|
||||
}
|
||||
|
||||
export type Socket = {
|
||||
node: Node;
|
||||
index: number | string;
|
||||
position: [number, number];
|
||||
};
|
||||
|
||||
|
||||
export interface NodeRegistry {
|
||||
getNode: (id: string) => NodeType | undefined;
|
||||
getAllNodes: () => NodeType[];
|
||||
}
|
||||
|
||||
export interface RuntimeExecutor {
|
||||
execute: (graph: Graph) => void;
|
||||
}
|
||||
|
||||
|
||||
export type Edge = [Node, number, Node, string];
|
||||
|
||||
export type Graph = {
|
||||
id: number;
|
||||
meta?: {
|
||||
title?: string;
|
||||
lastModified?: string;
|
||||
},
|
||||
nodes: Node[];
|
||||
edges: [number, number, number, string][];
|
||||
}
|
||||
|
36
packages/types/inputs.ts
Normal file
36
packages/types/inputs.ts
Normal file
@ -0,0 +1,36 @@
|
||||
type NodeInputFloat = {
|
||||
type: "float";
|
||||
value?: number;
|
||||
min?: number;
|
||||
max?: number;
|
||||
step?: number;
|
||||
}
|
||||
|
||||
type NodeInputInteger = {
|
||||
type: "integer";
|
||||
value?: number;
|
||||
min?: number;
|
||||
max?: number;
|
||||
}
|
||||
|
||||
type NodeInputBoolean = {
|
||||
type: "boolean";
|
||||
value?: boolean;
|
||||
}
|
||||
|
||||
type NodeInputSelect = {
|
||||
type: "select";
|
||||
labels: string[];
|
||||
value?: number;
|
||||
}
|
||||
|
||||
type DefaultOptions = {
|
||||
internal?: boolean;
|
||||
}
|
||||
|
||||
export type NodeInput = (NodeInputBoolean | NodeInputFloat | NodeInputInteger | NodeInputSelect) & DefaultOptions;
|
||||
|
||||
|
||||
export type NodeInputType<T extends Record<string, NodeInput>> = {
|
||||
[K in keyof T]: T[K]["value"]
|
||||
};
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "types",
|
||||
"name": "@nodes/types",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
Reference in New Issue
Block a user