do all the boring ts stuff to make this actually work

This commit is contained in:
2026-04-08 15:04:41 -05:00
parent 2a9ef16425
commit 242fb37a67
7 changed files with 113 additions and 3 deletions
+1
View File
@@ -0,0 +1 @@
node_modules
+9
View File
@@ -0,0 +1,9 @@
export declare class TetherClient {
private ws;
private subscribedQueries;
connect: (url: string) => void;
disconnect: () => void;
subscribe: (query: string, callback: (data: any) => void) => void;
unsubscribe: (query: string) => void;
sendMutation: (mutationName: string, params: any) => void;
}
+49
View File
@@ -0,0 +1,49 @@
export class TetherClient {
ws = null;
subscribedQueries = new Map();
connect = (url) => {
this.ws = new WebSocket(url);
this.ws.onopen = () => {
console.log('Connected to Tether');
};
this.ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'query') {
this.subscribedQueries.forEach((callback, query) => {
if (data.query === query) {
callback(data.data);
}
});
}
else if (data.type === 'error') {
console.error(data.error);
}
};
this.ws.onclose = () => {
console.log('Disconnected from Tether');
};
};
disconnect = () => {
if (!this.ws) {
throw new Error('Not connected to Tether');
}
this.ws.close();
this.ws = null;
};
subscribe = (query, callback) => {
this.subscribedQueries.set(query, callback);
};
unsubscribe = (query) => {
this.subscribedQueries.delete(query);
};
sendMutation = (mutationName, params) => {
if (!this.ws) {
throw new Error('Not connected to Tether');
}
this.ws.send(JSON.stringify({
type: 'mutation',
name: mutationName,
payload: params,
}));
};
}
+30
View File
@@ -0,0 +1,30 @@
{
"name": "tether-ts",
"version": "1.0.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "tether-ts",
"version": "1.0.3",
"license": "ISC",
"devDependencies": {
"typescript": "^6.0.2"
}
},
"node_modules/typescript": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.2.tgz",
"integrity": "sha512-bGdAIrZ0wiGDo5l8c++HWtbaNCWTS4UTv7RaTH/ThVIgjkveJt83m74bBHMJkuCbslY8ixgLBVZJIOiQlQTjfQ==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
}
}
}
+9 -3
View File
@@ -1,12 +1,18 @@
{ {
"name": "tether-ts", "name": "tether-ts",
"version": "1.0.2", "version": "1.0.3",
"description": "TypeScript client for Tether", "description": "TypeScript client for Tether",
"license": "ISC", "license": "ISC",
"author": "wisplite", "author": "wisplite",
"type": "module", "type": "module",
"main": "index.ts", "main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"watch": "tsc --watch"
},
"devDependencies": {
"typescript": "^6.0.2"
} }
} }
View File
+15
View File
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "./src",
"outDir": "./dist",
"declaration": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
}