Merge branch 'node-migration' of https://github.com/discordeno/discordeno into node-migration

This commit is contained in:
Skillz4Killz
2022-12-20 17:05:40 +00:00
39 changed files with 154 additions and 124 deletions

View File

@@ -45,3 +45,40 @@ jobs:
with:
files: ./packages/${{ inputs.package }}/coverage/lcov.info
flags: ${{ inputs.package }}-unit
deno-unit-test:
name: Deno Unit Test
runs-on: ubuntu-latest
needs: unit-test
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: denoland/setup-deno@main
with:
deno-version: "v1.29"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install --immutable
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-test:deno-unit-${{ inputs.package }}-${{ github.sha }}
- name: Build dist cache
if: steps.turbo-cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-build-${{ github.sha }}
- name: Deno Unit Test
run: yarn test:deno-unit --cache-dir=".turbo" --filter=./packages/${{ inputs.package }}

1
.gitignore vendored
View File

@@ -22,6 +22,7 @@ coverage
# build
dist
denoTestsDist
out
build
.docusaurus

13
denoImportMap.json Normal file
View File

@@ -0,0 +1,13 @@
{
"imports": {
"node:buffer": "https://deno.land/std@0.168.0/node/buffer.ts",
"node:fs": "https://deno.land/std@0.168.0/node/fs.ts",
"tweetnacl": "npm:tweetnacl",
"mocha": "https://deno.land/std@0.168.0/testing/bdd.ts",
"chai": "https://cdn.skypack.dev/chai@4.3.4?dts",
"sinon": "https://cdn.skypack.dev/sinon@15.0.0?dts",
"@discordeno/utils": "./packages/utils/dist/index.js",
"@discordeno/constant": "./packages/constant/dist/index.js",
"@discordeno/types": "./packages/types/dist/index.js"
}
}

View File

@@ -10,7 +10,7 @@
"devr": "nodemon --ignore ./src/bot/**/* --ignore ./src/gateway/**/* --ignore ./dist/**/* -e ts dist/rest/index.js",
"devb": "nodemon --ignore ./src/rest/**/* --ignore ./src/gateway/**/* --ignore ./dist/**/* -e ts dist/bot/index.js",
"type": "tsc --noEmit",
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"startr": "node dist/rest/index.js",
"startg": "node dist/gateway/index.js",
"startb": "node dist/bot/index.js"

View File

@@ -11,12 +11,12 @@
"fmt": "turbo run fmt",
"build:type": "turbo run build:type",
"release-build": "turbo run release-build",
"release-build:clean": "turbo run release-build:clean",
"dev": "turbo run dev --parallel",
"lint": "turbo run lint",
"test:type": "turbo run build:type",
"test:unit-coverage": "turbo run test:unit-coverage",
"test:unit": "turbo run test:unit",
"test:deno-unit": "turbo run test:deno-unit",
"test:test-type": "turbo run test:test-type",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"prepare": "husky install",

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js client",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -40,7 +40,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import fs from 'node:fs'
import {
createClientGatewayHandlers,

View File

@@ -2,6 +2,7 @@ import { expect } from 'chai'
import fs from 'node:fs'
import { createTransformers } from '../src/transformer.js'
// import { createTransformers } from '../src/transformer.js'
import { describe, it } from 'mocha'
import * as transformers from '../src/transformers/index.js'
describe('Transformers', () => {

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts'",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -38,7 +38,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js discordeno",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -41,7 +41,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -21,7 +21,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js gateway",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -40,7 +40,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -10,10 +10,9 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:type": "tsc --noEmit"
@@ -24,7 +23,6 @@
"@types/node": "^18.11.9",
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts'",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -36,7 +36,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts'",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts'",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts'",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -35,7 +35,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts'",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -40,7 +40,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { convertRestError } from '../src/convertRestError.js'
describe('[rest] convertRestError', () => {

View File

@@ -1,10 +1,8 @@
import { expect } from 'chai'
import { afterEach, beforeEach, describe, it } from 'mocha'
import sinon from 'sinon'
import {
checkRateLimits,
createRestManager,
RestManager
} from '../src/index.js'
import type { RestManager } from '../src/index.js'
import { checkRateLimits, createRestManager } from '../src/index.js'
describe('[rest] checkRateLimits', () => {
let rest: RestManager

View File

@@ -1,6 +1,8 @@
import { expect } from 'chai'
import { afterEach, beforeEach, describe, it } from 'mocha'
import sinon, { spy } from 'sinon'
import { createRestManager, RestManager } from '../src/index.js'
import type { RestManager } from '../src/index.js'
import { createRestManager } from '../src/index.js'
describe('[rest] processRateLimitedPaths', () => {
let rest: RestManager

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { simplifyUrl } from '../src/index.js'
describe('[rest] simplifyUrl', () => {

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js transformer",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -38,7 +38,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"tsconfig": "*",
"typescript": "^4.9.3"

View File

@@ -10,10 +10,9 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:type": "tsc --noEmit"
@@ -23,7 +22,6 @@
"@swc/core": "^1.3.21",
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"shx": "^0.3.4",
"tsconfig": "*",
"typescript": "^4.9.3"
},

View File

@@ -10,14 +10,14 @@
"url": "https://github.com/discordeno/discordeno.git"
},
"scripts": {
"build": "swc src --out-dir dist",
"build": "swc --delete-dir-on-start src --out-dir dist",
"build:type": "tsc --skipDefaultLibCheck --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"release-build:clean": "shx rm -rf dist && yarn build && yarn build:type",
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js utils",
"test:deno-unit": "swc tests --delete-dir-on-start --out-dir denoTestsDist && node ../../scripts/fixDenoTestExtension.js && deno test -A --import-map ../../denoImportMap.json denoTestsDist",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tsconfig.test.json"
@@ -35,7 +35,6 @@
"eslint": "^8.0.1",
"eslint-config-discordeno": "*",
"mocha": "^10.1.0",
"shx": "^0.3.4",
"sinon": "^15.0.0",
"ts-node": "^10.9.1",
"tsconfig": "*",

View File

@@ -1,7 +1,16 @@
import { Buffer } from 'node:buffer'
/** Removes the Bot before the token. */
export function removeTokenPrefix (token?: string, type: 'GATEWAY' | 'REST' = 'REST'): string {
export function removeTokenPrefix (
token?: string,
type: 'GATEWAY' | 'REST' = 'REST'
): string {
// If no token is provided, throw an error
if (token === undefined) throw new Error(`The ${type} was not given a token. Please provide a token and try again.`)
if (token === undefined) {
throw new Error(
`The ${type} was not given a token. Please provide a token and try again.`
)
}
// If the token does not have a prefix just return token
if (!token.startsWith('Bot ')) return token
// Remove the prefix and return only the token.

View File

@@ -1,3 +1,4 @@
import { Buffer } from 'node:buffer'
import nacl from 'tweetnacl'
export function verifySignature ({

View File

@@ -1,4 +1,6 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { Buffer } from 'node:buffer'
import { decode, encode } from '../src/base64.js'
describe('base64.ts', () => {

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { it } from 'mocha'
import { bigintToSnowflake, snowflakeToBigint } from '../src/bigint.js'
it('[bigint] - Transform a snowflake string to bigint', () => {

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { beforeEach, describe, it } from 'mocha'
import sinon from 'sinon'
import { Collection } from '../src/collection.js'

View File

@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { expect } from 'chai'
import { it } from 'mocha'
import { iconBigintToHash, iconHashToBigInt } from '../src/hash.js'
const iconHash = '4bbb271a13f7195031adcc06a2d867ce'

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { it } from 'mocha'
import { removeTokenPrefix } from '../src/token.js'
it('[token] Remove token prefix when Bot is prefixed.', () => {

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { afterEach, beforeEach, describe, it } from 'mocha'
import sinon from 'sinon'
import { delay, formatImageURL, hasProperty } from '../src/utils.js'

View File

@@ -1,4 +1,5 @@
import { expect } from 'chai'
import { it } from 'mocha'
import { validateLength } from '../src/validateLength.js'
it('[utils] Validate length is too low', () => {

View File

@@ -1,18 +1,19 @@
import { expect } from 'chai'
import type { KeyObject } from 'node:crypto'
import { generateKeyPairSync, sign } from 'node:crypto'
import { afterEach, beforeEach, describe, it } from 'mocha'
import { Buffer } from 'node:buffer'
import Sinon from 'sinon'
import nacl from 'tweetnacl'
import { verifySignature } from '../src/verifySignature.js'
describe('VerifySignature', () => {
let publicKey: KeyObject
let privateKey: KeyObject
let publicKey: Uint8Array
let secretKey: Uint8Array
let clock: Sinon.SinonFakeTimers
beforeEach(() => {
clock = Sinon.useFakeTimers();
({ publicKey, privateKey } = generateKeyPairSync('ed25519'))
({ publicKey, secretKey } = nacl.sign.keyPair())
})
afterEach(() => {
@@ -23,18 +24,14 @@ describe('VerifySignature', () => {
it('reutrn true if signature is verified', () => {
const timestamp = Date.now().toString()
const body = 'test body'
const signature = sign(
undefined,
const signature = nacl.sign.detached(
Buffer.from(timestamp + body),
privateKey
secretKey
)
const verifiedSignature = verifySignature({
publicKey: publicKey
.export({ type: 'spki', format: 'der' })
.toString('hex')
.substring(24),
signature: signature.toString('hex'),
publicKey: Buffer.from(publicKey).toString('hex'),
signature: Buffer.from(signature).toString('hex'),
timestamp,
body
})

View File

@@ -0,0 +1,22 @@
import fs from 'node:fs'
const dirs = ['']
for await (const dir of dirs) {
await Promise.all(
fs.readdirSync(`denoTestsDist${dir}`).map(async (file) => {
if (!file.endsWith('.js')) {
dirs.push(`${dir}/${file}`)
return
}
const content = await fs.promises.readFile(
`denoTestsDist${dir}/${file}`,
'utf-8'
)
fs.promises.writeFile(
`denoTestsDist${dir}/${file.slice(0, -7)}test.js`,
content.replace(/src\//g, 'dist/').replace(/\.ts/g, '.js')
)
fs.promises.rm(`denoTestsDist${dir}/${file}`)
})
)
}

View File

@@ -27,12 +27,6 @@
"dist/**"
]
},
"release-build:clean": {
"dependsOn": [
"^release-build:clean"
],
"cache": false
},
"test:unit-coverage": {
"dependsOn": [
"^build"
@@ -54,6 +48,15 @@
"^build:type"
]
},
"test:deno-unit": {
"dependsOn": [
"build",
"^build"
],
"outputs": [
"denoTestsDist/**"
]
},
"lint": {
"dependsOn": [
"^build:type"

View File

@@ -40,7 +40,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -64,7 +63,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -83,7 +81,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -108,7 +105,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -126,7 +122,6 @@ __metadata:
chalk: ^5.1.2
eslint: ^8.0.1
eslint-config-discordeno: "*"
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -152,7 +147,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -176,7 +170,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -192,7 +185,6 @@ __metadata:
"@types/node": ^18.11.9
eslint: ^8.0.1
eslint-config-discordeno: "*"
shx: ^0.3.4
tsconfig: "*"
typescript: ^4.9.3
languageName: unknown
@@ -214,7 +206,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
ts-node: ^10.9.1
tsconfig: "*"
@@ -1459,7 +1450,6 @@ __metadata:
eslint: ^8.0.1
eslint-config-discordeno: "*"
mocha: ^10.1.0
shx: ^0.3.4
sinon: ^15.0.0
tsconfig: "*"
typescript: ^4.9.3
@@ -2157,7 +2147,7 @@ __metadata:
languageName: node
linkType: hard
"glob@npm:^7.0.0, glob@npm:^7.1.3, glob@npm:^7.1.4":
"glob@npm:^7.1.3, glob@npm:^7.1.4":
version: 7.2.3
resolution: "glob@npm:7.2.3"
dependencies:
@@ -2438,13 +2428,6 @@ __metadata:
languageName: node
linkType: hard
"interpret@npm:^1.0.0":
version: 1.4.0
resolution: "interpret@npm:1.4.0"
checksum: 2e5f51268b5941e4a17e4ef0575bc91ed0ab5f8515e3cf77486f7c14d13f3010df9c0959f37063dcc96e78d12dc6b0bb1b9e111cdfe69771f4656d2993d36155
languageName: node
linkType: hard
"ip@npm:^2.0.0":
version: 2.0.0
resolution: "ip@npm:2.0.0"
@@ -2990,7 +2973,7 @@ __metadata:
languageName: node
linkType: hard
"minimist@npm:^1.2.0, minimist@npm:^1.2.3, minimist@npm:^1.2.5, minimist@npm:^1.2.6":
"minimist@npm:^1.2.0, minimist@npm:^1.2.5, minimist@npm:^1.2.6":
version: 1.2.7
resolution: "minimist@npm:1.2.7"
checksum: 7346574a1038ca23c32e02252f603801f09384dd1d78b69a943a4e8c2c28730b80e96193882d3d3b22a063445f460e48316b29b8a25addca2d7e5e8f75478bec
@@ -3502,15 +3485,6 @@ __metadata:
languageName: node
linkType: hard
"rechoir@npm:^0.6.2":
version: 0.6.2
resolution: "rechoir@npm:0.6.2"
dependencies:
resolve: ^1.1.6
checksum: fe76bf9c21875ac16e235defedd7cbd34f333c02a92546142b7911a0f7c7059d2e16f441fe6fb9ae203f459c05a31b2bcf26202896d89e390eda7514d5d2702b
languageName: node
linkType: hard
"regexp.prototype.flags@npm:^1.4.3":
version: 1.4.3
resolution: "regexp.prototype.flags@npm:1.4.3"
@@ -3543,7 +3517,7 @@ __metadata:
languageName: node
linkType: hard
"resolve@npm:^1.1.6, resolve@npm:^1.20.0, resolve@npm:^1.22.0, resolve@npm:^1.22.1":
"resolve@npm:^1.20.0, resolve@npm:^1.22.0, resolve@npm:^1.22.1":
version: 1.22.1
resolution: "resolve@npm:1.22.1"
dependencies:
@@ -3556,7 +3530,7 @@ __metadata:
languageName: node
linkType: hard
"resolve@patch:resolve@^1.1.6#~builtin<compat/resolve>, resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.22.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.22.1#~builtin<compat/resolve>":
"resolve@patch:resolve@^1.20.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.22.0#~builtin<compat/resolve>, resolve@patch:resolve@^1.22.1#~builtin<compat/resolve>":
version: 1.22.1
resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin<compat/resolve>::version=1.22.1&hash=c3c19d"
dependencies:
@@ -3706,19 +3680,6 @@ __metadata:
languageName: node
linkType: hard
"shelljs@npm:^0.8.5":
version: 0.8.5
resolution: "shelljs@npm:0.8.5"
dependencies:
glob: ^7.0.0
interpret: ^1.0.0
rechoir: ^0.6.2
bin:
shjs: bin/shjs
checksum: 7babc46f732a98f4c054ec1f048b55b9149b98aa2da32f6cf9844c434b43c6251efebd6eec120937bd0999e13811ebd45efe17410edb3ca938f82f9381302748
languageName: node
linkType: hard
"shiki@npm:^0.11.1":
version: 0.11.1
resolution: "shiki@npm:0.11.1"
@@ -3730,18 +3691,6 @@ __metadata:
languageName: node
linkType: hard
"shx@npm:^0.3.4":
version: 0.3.4
resolution: "shx@npm:0.3.4"
dependencies:
minimist: ^1.2.3
shelljs: ^0.8.5
bin:
shx: lib/cli.js
checksum: 0aa168bfddc11e3fe8943cce2e0d2d8514a560bd58cf2b835b4351ba03f46068f7d88286c2627f4b85604e81952154c43746369fb3f0d60df0e3b511f465e5b8
languageName: node
linkType: hard
"side-channel@npm:^1.0.4":
version: 1.0.4
resolution: "side-channel@npm:1.0.4"