From e6d771a3a5f37ae0f4a259e913f9c074d6741ae3 Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Sat, 30 Nov 2024 11:17:11 +0100 Subject: [PATCH] patch_collector: typescript --- patch_detector/{index.js => index.ts} | 14 ++++---------- patch_detector/package-lock.json | 20 ++++++++++++++++++++ patch_detector/package.json | 3 +++ patch_detector/tsconfig.json | 6 ++++++ 4 files changed, 33 insertions(+), 10 deletions(-) rename patch_detector/{index.js => index.ts} (75%) create mode 100644 patch_detector/tsconfig.json diff --git a/patch_detector/index.js b/patch_detector/index.ts similarity index 75% rename from patch_detector/index.js rename to patch_detector/index.ts index 0f0769f..a970a0b 100644 --- a/patch_detector/index.js +++ b/patch_detector/index.ts @@ -1,4 +1,4 @@ -const { MongoClient, ServerApiVersion } = require("mongodb"); +import { MongoClient } from "mongodb"; main() @@ -18,24 +18,18 @@ async function fetchLatestPatch() { const url = "https://ddragon.leagueoflegends.com/api/versions.json" const patchDataResponse = await fetch(url); const patchData = await patchDataResponse.json(); - const patch = patchData[0]; + const patch : string = patchData[0]; return patch; } async function connectToDatabase() { // Create a MongoClient with a MongoClientOptions object to set the Stable API version - const client = new MongoClient(`mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@mongo:27017`, { - serverApi: { - version: ServerApiVersion.v1, - strict: true, - deprecationErrors: true, - } - }) + const client = new MongoClient(`mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@mongo:27017`) await client.connect() return client } -async function compareLatestSavedPatch(client, newPatch, newDate) { +async function compareLatestSavedPatch(client: MongoClient, newPatch : string, newDate : Date) { const database = client.db("patches") const patches = database.collection("patches") const latestPatch = await patches.find().limit(1).sort({date:-1}).next() diff --git a/patch_detector/package-lock.json b/patch_detector/package-lock.json index 6989e6b..3b00208 100644 --- a/patch_detector/package-lock.json +++ b/patch_detector/package-lock.json @@ -10,6 +10,9 @@ "license": "ISC", "dependencies": { "mongodb": "^6.10.0" + }, + "devDependencies": { + "@types/node": "^22.10.1" } }, "node_modules/@mongodb-js/saslprep": { @@ -21,6 +24,16 @@ "sparse-bitfield": "^3.0.3" } }, + "node_modules/@types/node": { + "version": "22.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", + "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.20.0" + } + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -137,6 +150,13 @@ "node": ">=14" } }, + "node_modules/undici-types": { + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "dev": true, + "license": "MIT" + }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/patch_detector/package.json b/patch_detector/package.json index 1537da1..e98e62f 100644 --- a/patch_detector/package.json +++ b/patch_detector/package.json @@ -11,5 +11,8 @@ "description": "", "dependencies": { "mongodb": "^6.10.0" + }, + "devDependencies": { + "@types/node": "^22.10.1" } } diff --git a/patch_detector/tsconfig.json b/patch_detector/tsconfig.json new file mode 100644 index 0000000..e9be2ed --- /dev/null +++ b/patch_detector/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "types": ["node"] + }, + } + \ No newline at end of file