Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add biome #120

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Code quality
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
- name: Run Biome
run: biome ci .
15 changes: 15 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"ignore": ["**/dist/*", "**/docs/*"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"organizeImports": {
"enabled": true
}
}
56 changes: 28 additions & 28 deletions examples/canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "ts-topology-examples-canvas",
"version": "0.0.23-5",
"license": "MIT",
"scripts": {
"build": "webpack",
"clean": "rm -rf dist/ node_modules/",
"dev": "webpack serve",
"start": "ts-node ./src/index.ts"
},
"dependencies": {
"@topology-foundation/crdt": "0.0.23-5",
"@topology-foundation/network": "0.0.23-5",
"@topology-foundation/node": "0.0.23-5",
"@topology-foundation/object": "0.0.23-5",
"crypto-browserify": "^3.12.0",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"ts-node": "^10.9.2",
"vm-browserify": "^1.1.2"
},
"devDependencies": {
"@types/node": "^22.4.1",
"ts-loader": "^9.3.1",
"typescript": "^5.5.4",
"webpack": "^5.74.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
}
"name": "ts-topology-examples-canvas",
"version": "0.0.23-5",
"license": "MIT",
"scripts": {
"build": "webpack",
"clean": "rm -rf dist/ node_modules/",
"dev": "webpack serve",
"start": "ts-node ./src/index.ts"
},
"dependencies": {
"@topology-foundation/crdt": "0.0.23-5",
"@topology-foundation/network": "0.0.23-5",
"@topology-foundation/node": "0.0.23-5",
"@topology-foundation/object": "0.0.23-5",
"crypto-browserify": "^3.12.0",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"ts-node": "^10.9.2",
"vm-browserify": "^1.1.2"
},
"devDependencies": {
"@types/node": "^22.4.1",
"ts-loader": "^9.3.1",
"typescript": "^5.5.4",
"webpack": "^5.74.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
}
}
70 changes: 35 additions & 35 deletions examples/canvas/src/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
import { ICanvas } from "./objects/canvas";
import type { ICanvas } from "./objects/canvas";

// TODO: this should be superseded by wasm and main ts-topology library
export const handleCanvasMessages = (canvas: ICanvas, e: any) => {
if (e.detail.msg.topic === "topology::discovery") return;
const input = uint8ArrayToString(e.detail.msg.data);
const message = JSON.parse(input);
switch (message["type"]) {
case "object_update": {
const fn = uint8ArrayToString(new Uint8Array(message["data"]));
handleObjectUpdate(canvas, fn);
break;
}
default: {
break;
}
}
export const handleCanvasMessages = (canvas: ICanvas, e: CustomEvent) => {
if (e.detail.msg.topic === "topology::discovery") return;
const input = uint8ArrayToString(e.detail.msg.data);
const message = JSON.parse(input);
switch (message.type) {
case "object_update": {
const fn = uint8ArrayToString(new Uint8Array(message.data));
handleObjectUpdate(canvas, fn);
break;
}
default: {
break;
}
}
};

function handleObjectUpdate(canvas: ICanvas, fn: string) {
// In this case we only have paint
// `paint(${node.getPeerId()}, [${[x, y]}], [${painting}])`
let args = fn.replace("paint(", "").replace(")", "").split(", ");
let offset_p = args[1]
.replace("[", "")
.replace("]", "")
.split(",")
.map((s) => parseInt(s, 10));
const offset: [number, number] = [offset_p[0], offset_p[1]];
let rgb_p = args[2]
.replace("[", "")
.replace("]", "")
.split(",")
.map((s) => parseInt(s, 10));
const rgb: [number, number, number] = [rgb_p[0], rgb_p[1], rgb_p[2]];
// In this case we only have paint
// `paint(${node.getPeerId()}, [${[x, y]}], [${painting}])`
const args = fn.replace("paint(", "").replace(")", "").split(", ");
const offset_p = args[1]
.replace("[", "")
.replace("]", "")
.split(",")
.map((s) => Number.parseInt(s, 10));
const offset: [number, number] = [offset_p[0], offset_p[1]];
const rgb_p = args[2]
.replace("[", "")
.replace("]", "")
.split(",")
.map((s) => Number.parseInt(s, 10));
const rgb: [number, number, number] = [rgb_p[0], rgb_p[1], rgb_p[2]];

try {
canvas.paint(args[0], offset, rgb);
} catch (e) {
console.error(e);
}
try {
canvas.paint(args[0], offset, rgb);
} catch (e) {
console.error(e);
}
}
Loading