From 242fb37a671027ea670fd251243d71b598e0fe88 Mon Sep 17 00:00:00 2001 From: wisplite Date: Wed, 8 Apr 2026 15:04:41 -0500 Subject: [PATCH] do all the boring ts stuff to make this actually work --- .gitignore | 1 + dist/index.d.ts | 9 ++++++++ dist/index.js | 49 ++++++++++++++++++++++++++++++++++++++++ package-lock.json | 30 ++++++++++++++++++++++++ package.json | 12 +++++++--- index.ts => src/index.ts | 0 tsconfig.json | 15 ++++++++++++ 7 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 dist/index.d.ts create mode 100644 dist/index.js create mode 100644 package-lock.json rename index.ts => src/index.ts (100%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..65da3ec --- /dev/null +++ b/dist/index.d.ts @@ -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; +} diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..ca330e4 --- /dev/null +++ b/dist/index.js @@ -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, + })); + }; +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a06b34f --- /dev/null +++ b/package-lock.json @@ -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" + } + } + } +} diff --git a/package.json b/package.json index 2cbd099..6ae14e4 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,18 @@ { "name": "tether-ts", - "version": "1.0.2", + "version": "1.0.3", "description": "TypeScript client for Tether", "license": "ISC", "author": "wisplite", "type": "module", - "main": "index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", "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" } } diff --git a/index.ts b/src/index.ts similarity index 100% rename from index.ts rename to src/index.ts diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..72e79d1 --- /dev/null +++ b/tsconfig.json @@ -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/**/*"], + } \ No newline at end of file