From ef1c20e67042676f32c858e8ab6e9fa5ae65101b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?FAY=E3=82=B7?=
<103030954+FAYStarNext@users.noreply.github.com>
Date: Sun, 21 Jul 2024 13:40:40 +0700
Subject: [PATCH] chore: Add initial project structure and configuration files
---
.github/workflows/codeql.yml | 93 +++++++++++++
.github/workflows/dependency-review.yml | 39 ++++++
.github/workflows/npm-publish.yml | 31 +++++
.gitignore | 176 ++++++++++++++++++++++++
.vscode/settings.json | 3 +
LICENSE | 21 +++
README.md | 100 ++++++++++++++
babel.config.json | 9 ++
eslint.config.d.ts | 2 +
eslint.config.js | 12 ++
package.json | 31 +++++
src/index.ts | 2 +
src/structures/Manager.ts | 7 +
src/structures/Node.ts | 106 ++++++++++++++
src/structures/Player.ts | 3 +
src/structures/Rest.ts | 68 +++++++++
src/types/Node.ts | 46 +++++++
src/types/Player.ts | 7 +
src/types/Rest.ts | 25 ++++
test/connect.d.ts | 1 +
test/connect.ts | 19 +++
tsconfig.json | 28 ++++
22 files changed, 829 insertions(+)
create mode 100644 .github/workflows/codeql.yml
create mode 100644 .github/workflows/dependency-review.yml
create mode 100644 .github/workflows/npm-publish.yml
create mode 100644 .gitignore
create mode 100644 .vscode/settings.json
create mode 100644 LICENSE
create mode 100644 README.md
create mode 100644 babel.config.json
create mode 100644 eslint.config.d.ts
create mode 100644 eslint.config.js
create mode 100644 package.json
create mode 100644 src/index.ts
create mode 100644 src/structures/Manager.ts
create mode 100644 src/structures/Node.ts
create mode 100644 src/structures/Player.ts
create mode 100644 src/structures/Rest.ts
create mode 100644 src/types/Node.ts
create mode 100644 src/types/Player.ts
create mode 100644 src/types/Rest.ts
create mode 100644 test/connect.d.ts
create mode 100644 test/connect.ts
create mode 100644 tsconfig.json
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
new file mode 100644
index 0000000..09fd523
--- /dev/null
+++ b/.github/workflows/codeql.yml
@@ -0,0 +1,93 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+name: "CodeQL"
+
+on:
+ push:
+ branches: [ "master", "main" ]
+ pull_request:
+ branches: [ "master", "main" ]
+ schedule:
+ - cron: '38 19 * * 3'
+
+jobs:
+ analyze:
+ name: Analyze (${{ matrix.language }})
+ # Runner size impacts CodeQL analysis time. To learn more, please see:
+ # - https://gh.io/recommended-hardware-resources-for-running-codeql
+ # - https://gh.io/supported-runners-and-hardware-resources
+ # - https://gh.io/using-larger-runners (GitHub.com only)
+ # Consider using larger runners or machines with greater resources for possible analysis time improvements.
+ runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
+ timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
+ permissions:
+ # required for all workflows
+ security-events: write
+
+ # required to fetch internal or private CodeQL packs
+ packages: read
+
+ # only required for workflows in private repositories
+ actions: read
+ contents: read
+
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - language: javascript-typescript
+ build-mode: none
+ # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
+ # Use `c-cpp` to analyze code written in C, C++ or both
+ # Use 'java-kotlin' to analyze code written in Java, Kotlin or both
+ # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
+ # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
+ # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
+ # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
+ # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v3
+ with:
+ languages: ${{ matrix.language }}
+ build-mode: ${{ matrix.build-mode }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+
+ # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
+ # queries: security-extended,security-and-quality
+
+ # If the analyze step fails for one of the languages you are analyzing with
+ # "We were unable to automatically build your code", modify the matrix above
+ # to set the build mode to "manual" for that language. Then modify this step
+ # to build your code.
+ # âšī¸ Command-line programs to run using the OS shell.
+ # đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
+ - if: matrix.build-mode == 'manual'
+ shell: bash
+ run: |
+ echo 'If you are using a "manual" build mode for one or more of the' \
+ 'languages you are analyzing, replace this with the commands to build' \
+ 'your code, for example:'
+ echo ' make bootstrap'
+ echo ' make release'
+ exit 1
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v3
+ with:
+ category: "/language:${{matrix.language}}"
\ No newline at end of file
diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml
new file mode 100644
index 0000000..a15d82b
--- /dev/null
+++ b/.github/workflows/dependency-review.yml
@@ -0,0 +1,39 @@
+# Dependency Review Action
+#
+# This Action will scan dependency manifest files that change as part of a Pull Request,
+# surfacing known-vulnerable versions of the packages declared or updated in the PR.
+# Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable
+# packages will be blocked from merging.
+#
+# Source repository: https://github.com/actions/dependency-review-action
+# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
+name: 'Dependency review'
+on:
+ pull_request:
+ branches: [ "master", "main" ]
+
+# If using a dependency submission action in this workflow this permission will need to be set to:
+#
+# permissions:
+# contents: write
+#
+# https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api
+permissions:
+ contents: read
+ # Write permissions for pull-requests are required for using the `comment-summary-in-pr` option, comment out if you aren't using this option
+ pull-requests: write
+
+jobs:
+ dependency-review:
+ runs-on: ubuntu-latest
+ steps:
+ - name: 'Checkout repository'
+ uses: actions/checkout@v4
+ - name: 'Dependency Review'
+ uses: actions/dependency-review-action@v4
+ # Commonly enabled options, see https://github.com/actions/dependency-review-action#configuration-options for all available options.
+ with:
+ comment-summary-in-pr: always
+ # fail-on-severity: moderate
+ # deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later
+ # retry-on-snapshot-warnings: true
\ No newline at end of file
diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml
new file mode 100644
index 0000000..98177c0
--- /dev/null
+++ b/.github/workflows/npm-publish.yml
@@ -0,0 +1,31 @@
+# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
+# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
+
+name: Node.js Package
+on:
+ push:
+ branches: [ master ]
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 16
+ - run: npm i -g typescript --force
+ publish-npm:
+ needs: build
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 16
+ registry-url: https://registry.npmjs.org/
+ - run: npm i --force
+ - run: npx tsc
+ - run: npm run build:js
+ - run: npm publish
+ env:
+ NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0b7c40a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,176 @@
+# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
+
+# Logs
+
+logs
+_.log
+npm-debug.log_
+yarn-debug.log*
+yarn-error.log*
+lerna-debug.log*
+.pnpm-debug.log*
+
+# Caches
+
+.cache
+
+# Diagnostic reports (https://nodejs.org/api/report.html)
+
+report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
+
+# Runtime data
+
+pids
+_.pid
+_.seed
+*.pid.lock
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+
+lib-cov
+
+# Coverage directory used by tools like istanbul
+
+coverage
+*.lcov
+
+# nyc test coverage
+
+.nyc_output
+
+# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
+
+.grunt
+
+# Bower dependency directory (https://bower.io/)
+
+bower_components
+
+# node-waf configuration
+
+.lock-wscript
+
+# Compiled binary addons (https://nodejs.org/api/addons.html)
+
+build/Release
+
+# Dependency directories
+
+node_modules/
+jspm_packages/
+
+# Snowpack dependency directory (https://snowpack.dev/)
+
+web_modules/
+
+# TypeScript cache
+
+*.tsbuildinfo
+
+# Optional npm cache directory
+
+.npm
+
+# Optional eslint cache
+
+.eslintcache
+
+# Optional stylelint cache
+
+.stylelintcache
+
+# Microbundle cache
+
+.rpt2_cache/
+.rts2_cache_cjs/
+.rts2_cache_es/
+.rts2_cache_umd/
+
+# Optional REPL history
+
+.node_repl_history
+
+# Output of 'npm pack'
+
+*.tgz
+
+# Yarn Integrity file
+
+.yarn-integrity
+
+# dotenv environment variable files
+
+.env
+.env.development.local
+.env.test.local
+.env.production.local
+.env.local
+
+# parcel-bundler cache (https://parceljs.org/)
+
+.parcel-cache
+
+# Next.js build output
+
+.next
+out
+
+# Nuxt.js build / generate output
+
+.nuxt
+dist
+
+# Gatsby files
+
+# Comment in the public line in if your project uses Gatsby and not Next.js
+
+# https://nextjs.org/blog/next-9-1#public-directory-support
+
+# public
+
+# vuepress build output
+
+.vuepress/dist
+
+# vuepress v2.x temp and cache directory
+
+.temp
+
+# Docusaurus cache and generated files
+
+.docusaurus
+
+# Serverless directories
+
+.serverless/
+
+# FuseBox cache
+
+.fusebox/
+
+# DynamoDB Local files
+
+.dynamodb/
+
+# TernJS port file
+
+.tern-port
+
+# Stores VSCode versions used for testing VSCode extensions
+
+.vscode-test
+
+# yarn v2
+
+.yarn/cache
+.yarn/unplugged
+.yarn/build-state.yml
+.yarn/install-state.gz
+.pnp.*
+
+# IntelliJ based IDEs
+.idea
+
+# Finder (MacOS) folder config
+.DS_Store
+bun.lockb
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..5c58223
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "docwriter.progress.trackClasses": true
+}
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..fdebf61
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2024 FAYStarNext
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..eb9cf26
--- /dev/null
+++ b/README.md
@@ -0,0 +1,100 @@
+
+
+
+
+sunday.ts
+
+
+
+[![Status](https://img.shields.io/badge/status-active-success.svg)]()
+[![GitHub Issues](https://img.shields.io/github/issues/FAYStarNext/Sunday.ts.svg)](https://github.com/FAYStarNext/Sunday.ts/issues)
+[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/FAYStarNext/Sunday.ts.svg)](https://github.com/FAYStarNext/Sunday.ts/pulls)
+[![License](https://img.shields.io/badge/license-MIT-blue.svg)](/LICENSE)
+
+
+
+---
+
+ Sunday a lavalink wrapper
+
+
+
+## đ Table of Contents
+
+- [đ Table of Contents](#-table-of-contents)
+- [đ§ About ](#-about-)
+- [đ Getting Started ](#-getting-started-)
+ - [Installing](#installing)
+- [Features](#features)
+- [đ Usage ](#-usage-)
+- [đ Deployment ](#-deployment-)
+- [âī¸ Built Using ](#ī¸-built-using-)
+- [âī¸ Authors ](#ī¸-authors-)
+
+## đ§ About
+
+Sunday a lavalink wrapper for ( NodeJS, Bun )
+
+## đ Getting Started
+
+### Installing
+
+To install Sunday.ts, follow these steps:
+
+1. Open your terminal or command prompt.
+2. Navigate to the root directory of your project.
+3. Run the following command to install Sunday.ts:
+
+ ```sh
+ bun i sunday.ts
+ ```
+
+ This will install Sunday.ts and its dependencies.
+
+4. Once the installation is complete, you can import Sunday.ts into your project and start using it.
+
+That's it! You have successfully installed Sunday.ts and are ready to start using it in your Node.js project.
+
+## Features
+- [ ] Multi version
+- [ ] Player
+- [ ] Plugin
+
+## đ Usage
+
+```ts
+import { Node } from "sunday.ts"
+const node = new Node({
+ host: 'localhost',
+ port: 2333,
+ password: 'youshallnotpass',
+});
+
+node.on("ready", () => {
+ console.log("Ready");
+});
+node.on("stats", () => {
+ console.log(node.stats);
+});
+node.on("raw", (data) => {
+ console.log(data);
+});
+node.connect();
+node.rest?.on("get", (data) => console.log(data));
+node.rest?.get("/loadtracks?identifier=dQw4w9WgXcQ")
+```
+
+## đ Deployment
+
+Add additional notes about how to deploy this on a live system.
+
+## âī¸ Built Using
+
+- [WebSocket](https://github.com/websockets/ws) - WebSocket Client
+- [Axios](https://github.com/axios/axios) - HTTP Request
+
+## âī¸ Authors
+
+- [@FAYStarNext](hhttps://github.com/FAYStarNext) - Idea & Initial work
+
+See also the list of [contributors](https://github.com/FAYStarNext/Sunday.ts/contributors) who participated in this project.
\ No newline at end of file
diff --git a/babel.config.json b/babel.config.json
new file mode 100644
index 0000000..5f611ff
--- /dev/null
+++ b/babel.config.json
@@ -0,0 +1,9 @@
+{
+ "presets": [
+ "@babel/preset-env",
+ "@babel/preset-typescript"
+ ],
+ "plugins": [
+ "@babel/plugin-proposal-class-properties"
+ ]
+}
\ No newline at end of file
diff --git a/eslint.config.d.ts b/eslint.config.d.ts
new file mode 100644
index 0000000..f83ce32
--- /dev/null
+++ b/eslint.config.d.ts
@@ -0,0 +1,2 @@
+declare const _default: any[];
+export default _default;
diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 0000000..984be61
--- /dev/null
+++ b/eslint.config.js
@@ -0,0 +1,12 @@
+import globals from "globals";
+import pluginJs from "@eslint/js";
+import tseslint from "typescript-eslint";
+
+
+export default [
+ { files: ["**/*.{js,mjs,cjs,ts}"] },
+ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
+ { languageOptions: { globals: globals.browser } },
+ pluginJs.configs.recommended,
+ ...tseslint.configs.recommended,
+];
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..7f242d9
--- /dev/null
+++ b/package.json
@@ -0,0 +1,31 @@
+{
+ "name": "sunday.ts",
+ "module": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "type": "module",
+ "scripts": {
+ "build:js": "npx babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps inline",
+ "lint": "npx x eslint src/**/*.ts",
+ "test:connect": "bun test/connect.ts"
+ },
+ "devDependencies": {
+ "@eslint/js": "^9.7.0",
+ "@types/bun": "latest",
+ "eslint": "9.x",
+ "globals": "^15.8.0",
+ "typescript-eslint": "^7.16.1"
+ },
+ "peerDependencies": {
+ "typescript": "^5.5.3"
+ },
+ "dependencies": {
+ "@babel/cli": "^7.24.8",
+ "@babel/core": "^7.24.9",
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
+ "@babel/preset-env": "^7.24.8",
+ "@babel/preset-typescript": "^7.24.7",
+ "axios": "^1.7.2",
+ "tiny-typed-emitter": "^2.1.0",
+ "ws": "^8.18.0"
+ }
+}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
new file mode 100644
index 0000000..4f8c0fd
--- /dev/null
+++ b/src/index.ts
@@ -0,0 +1,2 @@
+export * from "./structures/Node";
+export * from "./types/Node";
\ No newline at end of file
diff --git a/src/structures/Manager.ts b/src/structures/Manager.ts
new file mode 100644
index 0000000..8ebc593
--- /dev/null
+++ b/src/structures/Manager.ts
@@ -0,0 +1,7 @@
+import { TypedEmitter } from "tiny-typed-emitter";
+
+export class Manager extends TypedEmitter {
+ constructor() {
+ super();
+ }
+}
\ No newline at end of file
diff --git a/src/structures/Node.ts b/src/structures/Node.ts
new file mode 100644
index 0000000..826be7b
--- /dev/null
+++ b/src/structures/Node.ts
@@ -0,0 +1,106 @@
+import { TypedEmitter } from "tiny-typed-emitter";
+import { WebSocket } from "ws";
+import type { NodeConfig, NodeEventEmitter, NodeStats } from "../types/Node";
+import { Rest } from "./Rest";
+
+/* This TypeScript class extends TypedEmitter with a generic type of NodeEventEmitter. */
+export class Node extends TypedEmitter {
+ /* The line `public socket: WebSocket | null = null;` in the Node class is declaring a public
+ property named `socket` with a type of `WebSocket` or `null`. This means that the `socket`
+ property can hold a value of type `WebSocket` (imported from the "ws" module) representing a
+ WebSocket connection, or it can be `null` if no value is assigned to it. This property is
+ initialized with a default value of `null` when a new instance of the Node class is created. */
+ public socket: WebSocket | null = null;
+
+ /* The line `public options: NodeConfig;` in the Node class is declaring a public property named
+ `options` with a type of `NodeConfig`. This means that the `options` property can hold values
+ that conform to the structure defined by the `NodeConfig` type. The `NodeConfig` type likely
+ represents a configuration object containing various settings or parameters related to a Node
+ instance, such as `host`, `password`, and `port`. */
+ public options: NodeConfig;
+ /* The line `public stats: NodeStats | null = null;` in the Node class is declaring a public
+ property named `stats` with a type of `NodeStats` or `null`. This means that the `stats`
+ property can hold a value of type `NodeStats` (defined elsewhere in the codebase) or it can be
+ `null` if no value is assigned to it. */
+ public stats: NodeStats | null = null;
+ session_id: string | null = null;
+ /* The line `public rest: Rest | null = null;` in the Node class is declaring a public property
+ named `rest` of type `Rest` or `null`. */
+ public rest: Rest | null = null;
+
+ /**
+ * The function checks if a WebSocket connection is open and returns a boolean value accordingly.
+ * @returns The `get connected` method returns a boolean value indicating whether the WebSocket
+ * connection is open or not. It returns `true` if the socket is open and `false` if the socket is
+ * either closed or not initialized.
+ */
+ public get connected(): boolean {
+ if (!this.socket) return false;
+ return this.socket.readyState === WebSocket.OPEN;
+ }
+ /**
+ * The constructor initializes a Rest object with the provided NodeConfig options.
+ * @param {NodeConfig} options - The `options` parameter is an object that contains configuration
+ * settings for a Node instance. It typically includes properties such as `host`, `password`, and
+ * `port` that are used to establish a connection to a server or service.
+ */
+ constructor(options: NodeConfig) {
+ super();
+ this.options = options;
+ this.rest = new Rest({
+ host: options.host,
+ password: options.password,
+ port: options.port,
+ })
+ }
+ /**
+ * The `connect` function establishes a WebSocket connection with specified headers and event
+ * handlers for connection, closure, error, and message reception.
+ * @returns If the `connect()` method is called when `this.connected` is already `true`, the method
+ * will return early without establishing a new connection.
+ */
+ public connect() {
+ if (this.connected) return;
+ const headers = Object.assign({
+ "Authorization": this.options.password,
+ "Client-Name": "Lavalink",
+ "User-Id": "213",
+ })
+ this.socket = new WebSocket(`ws${this.options.secure ? "s" : ""}://${this.options.host}:${this.options.port}/v4/websocket`, { headers });
+ this.socket.on("open", () => {
+ this.emit("connect");
+ });
+ this.socket.on("close", () => {
+ console.log("Connection closed");
+ });
+ this.socket.on("error", (error) => {
+ console.error(error);
+ });
+ this.socket.on("message", this.onMessage.bind(this));
+ }
+ /**
+ * The function `onMessage` processes incoming data, parses it as JSON, and emits events based on
+ * the payload's operation type.
+ * @param {Buffer | string} data - The `data` parameter in the `onMessage` function can be either a
+ * Buffer or a string. If it is an array, the function concatenates the buffers in the array. If it
+ * is an ArrayBuffer, it converts it to a Buffer. Then it parses the data as JSON and emits a
+ */
+ private onMessage(data: Buffer | string) {
+ if (Array.isArray(data)) data = Buffer.concat(data);
+ else if (data instanceof ArrayBuffer) data = Buffer.from(data);
+ const payload = JSON.parse(data.toString());
+ this.emit("raw", payload);
+ switch (payload?.op) {
+ case "ready": {
+ this.session_id = payload.session_id;
+ this.emit("ready");
+ break;
+ }
+ case "stats": {
+ this.stats = payload;
+ this.emit("stats", payload);
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/structures/Player.ts b/src/structures/Player.ts
new file mode 100644
index 0000000..bfb96a1
--- /dev/null
+++ b/src/structures/Player.ts
@@ -0,0 +1,3 @@
+export class Player {
+
+}
\ No newline at end of file
diff --git a/src/structures/Rest.ts b/src/structures/Rest.ts
new file mode 100644
index 0000000..0ba32df
--- /dev/null
+++ b/src/structures/Rest.ts
@@ -0,0 +1,68 @@
+import { TypedEmitter } from "tiny-typed-emitter";
+import type { RestConfig, RestEventEmitter } from "../types/Rest";
+import axios, { type AxiosInstance } from "axios";
+
+export class Rest extends TypedEmitter {
+ /* The line `public req: AxiosInstance` in the TypeScript class `Rest` is declaring a public
+ property named `req` of type `AxiosInstance`. This property is used to store an instance of
+ Axios, which is a popular JavaScript library used for making HTTP requests. By storing an
+ instance of Axios in the `req` property, the `Rest` class can utilize Axios methods to make HTTP
+ requests such as GET and POST to interact with REST APIs based on the provided configuration
+ options. */
+ public req: AxiosInstance
+ /* The line `public config: RestConfig;` in the TypeScript class `Rest` is declaring a public
+ property named `config` of type `RestConfig`. This property is used to store the configuration
+ options provided when initializing an instance of the `Rest` class. */
+ public config: RestConfig;
+ /**
+ * The constructor function initializes a REST client with the provided configuration options.
+ * @param {RestConfig} options - The `options` parameter in the constructor function seems to be an
+ * object of type `RestConfig`. It likely contains configuration options for making REST API
+ * requests. Some of the properties in the `options` object could include:
+ */
+ constructor(options: RestConfig) {
+ super();
+ this.config = options;
+ this.req = axios.create({
+ baseURL: `http${options.secure ? "s" : ""}://${options.host}:${options.port}/v4`,
+ headers: {
+ "Authorization": options.password,
+ }
+ });
+ }
+ /**
+ * The function `get` sends a GET request to a specified path and emits events based on the response
+ * or error.
+ * @param {string} path - The `path` parameter in the `get` method is a string that represents the
+ * URL path to make the GET request to.
+ * @param [options] - The `options` parameter in the `get` method is an optional object that allows
+ * you to pass additional configuration or data to the HTTP request being made. It is a key-value
+ * pair object where the keys are strings and the values can be of any type. These options can
+ * include headers, query parameters
+ */
+ public async get(path: string, options?: { [key: string]: any }) {
+ await this.req.get(path, options).then((res) => {
+ this.emit("get", res.data);
+ return res.data;
+ }).catch((err) => {
+ this.emit("error", err);
+ });
+ }
+ /**
+ * This TypeScript function sends a POST request using the provided path and options, emitting
+ * events for successful responses and errors.
+ * @param {string} path - The `path` parameter is a string that represents the URL path where the
+ * POST request will be sent.
+ * @param [options] - The `options` parameter in the `post` method is an optional object that can
+ * contain key-value pairs for additional configuration or data to be sent in the POST request. It
+ * allows for flexibility in customizing the request based on specific requirements.
+ */
+ public async post(path: string, options?: { [key: string]: any }) {
+ await this.req.post(path, options).then((res) => {
+ this.emit("post", res.data);
+ return res.data;
+ }).catch((err) => {
+ this.emit("error", err);
+ });
+ }
+}
\ No newline at end of file
diff --git a/src/types/Node.ts b/src/types/Node.ts
new file mode 100644
index 0000000..ace1dbc
--- /dev/null
+++ b/src/types/Node.ts
@@ -0,0 +1,46 @@
+/* The `interface NodeEventEmitter` is defining a structure for an object that can emit specific events
+related to a Node. It specifies four event types along with their corresponding callback functions: */
+interface NodeEventEmitter {
+ ready: () => void;
+ raw: (data: unknown) => void;
+ stats: (stats: NodeStats) => void;
+ connect: () => void;
+}
+
+/* The `interface NodeConfig` is defining a structure for configuring a Node. It specifies the
+properties that can be set for a Node, including the host (as a string), port (as a number),
+password (as a string), and an optional property secure (as a boolean). This interface provides a
+blueprint for creating objects that hold configuration settings for a Node. */
+interface NodeConfig {
+ host: string;
+ port: number;
+ password: string;
+ secure?: boolean;
+}
+
+/* The `interface NodeStats` is defining a structure for representing statistical data related to a
+Node. It includes various properties such as `frameStats`, `players`, `playingPlayers`, `uptime`,
+`memory`, and `cpu`. Each property has a specific data type associated with it: */
+interface NodeStats {
+ frameStats: string | null,
+ players: number,
+ playingPlayers: number,
+ uptime: number,
+ memory: {
+ free: number,
+ used: number,
+ allocated: number,
+ reservable: number,
+ },
+ cpu: {
+ cores: number,
+ systemLoad: number,
+ lavalinkLoad: number,
+ },
+}
+
+export type {
+ NodeEventEmitter,
+ NodeConfig,
+ NodeStats
+}
\ No newline at end of file
diff --git a/src/types/Player.ts b/src/types/Player.ts
new file mode 100644
index 0000000..400d390
--- /dev/null
+++ b/src/types/Player.ts
@@ -0,0 +1,7 @@
+interface Player {
+
+}
+
+export type {
+
+}
\ No newline at end of file
diff --git a/src/types/Rest.ts b/src/types/Rest.ts
new file mode 100644
index 0000000..b3b6f43
--- /dev/null
+++ b/src/types/Rest.ts
@@ -0,0 +1,25 @@
+/* The `interface RestEventEmitter` in the TypeScript code snippet is defining a structure for an event
+emitter related to a REST service. It specifies the types of functions that can be included in an
+object implementing the `RestEventEmitter` interface. */
+interface RestEventEmitter {
+ ready: () => void;
+ raw: (data: unknown) => void;
+ get: (data: unknown) => void;
+ error: (error: Error) => void;
+ post: (data: unknown) => void;
+}
+
+/* The `interface RestConfig` in the TypeScript code snippet defines a structure for configuration
+settings related to a REST service. It specifies the properties that can be included in a
+`RestConfig` object, which are: */
+interface RestConfig {
+ host: string;
+ port: number;
+ password: string;
+ secure?: boolean;
+}
+
+export type {
+ RestEventEmitter,
+ RestConfig
+}
\ No newline at end of file
diff --git a/test/connect.d.ts b/test/connect.d.ts
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/test/connect.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/test/connect.ts b/test/connect.ts
new file mode 100644
index 0000000..be2dfc0
--- /dev/null
+++ b/test/connect.ts
@@ -0,0 +1,19 @@
+import { Node } from '../src/index'
+const node = new Node({
+ host: 'localhost',
+ port: 2333,
+ password: 'youshallnotpass',
+});
+
+node.on("ready", () => {
+ console.log("Ready");
+});
+node.on("stats", () => {
+ console.log(node.stats);
+});
+node.on("raw", (data) => {
+ console.log(data);
+});
+node.connect();
+node.rest?.on("get", (data) => console.log(data));
+node.rest?.get("/loadtracks?identifier=dQw4w9WgXcQ").catch(console.error);
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 0000000..da53c00
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,28 @@
+{
+ "compilerOptions": {
+ "lib": ["ESNext", "DOM"],
+ "target": "ESNext",
+ "module": "ESNext",
+ "moduleDetection": "force",
+ "jsx": "react-jsx",
+ "allowJs": true,
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "verbatimModuleSyntax": true,
+ "skipLibCheck": true,
+ "noFallthroughCasesInSwitch": true,
+ "noUnusedLocals": false,
+ "noUnusedParameters": false,
+ "noPropertyAccessFromIndexSignature": false,
+ "rootDir": "src",
+ "outDir": "./dist",
+ "declaration": true,
+ "emitDeclarationOnly": true,
+ "isolatedModules": true
+ },
+ // Include the eslint.config.js explicitly
+ "include": [
+ "src/**/*", // Adjust as needed to target your source files
+ "eslint.config.js" // Include the eslint config explicitly
+ ]
+}
\ No newline at end of file