From 44fa796186fc62c962d7f261f4b48f7011424d7b Mon Sep 17 00:00:00 2001 From: Mat Sz Date: Thu, 26 Oct 2023 18:04:49 +0200 Subject: [PATCH] replace uuid with nanoid --- web/package.json | 3 +-- web/src/stores/ChatStore.ts | 4 ++-- web/src/stores/Transfer.ts | 4 ++-- ws/__tests__/ClientManager.test.ts | 3 +-- ws/package.json | 2 -- ws/src/utils/validation.ts | 8 ++++---- yarn.lock | 15 +++++---------- 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/web/package.json b/web/package.json index b7a5e83..705955f 100644 --- a/web/package.json +++ b/web/package.json @@ -16,7 +16,6 @@ "@filedrop/types": "*", "@types/react": "^18.2.31", "@types/react-dom": "^18.2.14", - "@types/uuid": "^9.0.3", "base64-js": "^1.5.1", "clsx": "^2.0.0", "eslint-config-react-app": "^7.0.1", @@ -27,6 +26,7 @@ "matcrypt": "^1.3.0", "mobx": "^6.10.2", "mobx-react-lite": "^4.0.5", + "nanoid": "^5.0.2", "preact": "^10.18.1", "preact-compat": "^3.19.0", "pwanow": "^0.0.1", @@ -38,7 +38,6 @@ "react-icons": "^4.11.0", "sass": "^1.69.4", "typesocket": "^1.0.2", - "uuid": "^9.0.0", "vite-plugin-info": "^0.4.1", "wouter": "^2.12.1" }, diff --git a/web/src/stores/ChatStore.ts b/web/src/stores/ChatStore.ts index c1ef07c..3478ee1 100644 --- a/web/src/stores/ChatStore.ts +++ b/web/src/stores/ChatStore.ts @@ -5,7 +5,7 @@ import { Message, MessageType, } from '@filedrop/types'; -import { v4 } from 'uuid'; +import { nanoid } from 'nanoid'; import type { Connection } from './Connection.js'; import { ChatItemModel } from '../types/Models.js'; @@ -108,7 +108,7 @@ export class ChatStore { const array = this.channelItems.get(channel)!; array.push({ - id: v4(), + id: nanoid(), date: new Date(), clientId: senderId, message, diff --git a/web/src/stores/Transfer.ts b/web/src/stores/Transfer.ts index 4db3523..6fe58db 100644 --- a/web/src/stores/Transfer.ts +++ b/web/src/stores/Transfer.ts @@ -1,5 +1,5 @@ import { makeAutoObservable, runInAction } from 'mobx'; -import { v4 } from 'uuid'; +import { nanoid } from 'nanoid'; import { ActionMessageActionType, ActionMessageModel, @@ -36,7 +36,7 @@ export class Transfer { public fileSize: number, public fileType: string, public preview?: string, - public transferId: string = v4(), + public transferId: string = nanoid(), public receiving = false ) { this.state = receiving ? TransferState.INCOMING : TransferState.OUTGOING; diff --git a/ws/__tests__/ClientManager.test.ts b/ws/__tests__/ClientManager.test.ts index fe5b6fa..344a46c 100644 --- a/ws/__tests__/ClientManager.test.ts +++ b/ws/__tests__/ClientManager.test.ts @@ -1,4 +1,3 @@ -import { v4 as uuid } from 'uuid'; import { ActionMessageActionType, TargetedMessageModel, @@ -168,7 +167,7 @@ describe('ClientManager', () => { type: MessageType.ACTION, action: ActionMessageActionType.ACCEPT, targetId: client2.clientId!, - transferId: uuid(), + transferId: 'ay3UIn8k4QsznfyHCt9mh', }; clientManager.handleMessage(client1, targetedMessage); diff --git a/ws/package.json b/ws/package.json index 87c77ec..6b2f08c 100755 --- a/ws/package.json +++ b/ws/package.json @@ -10,7 +10,6 @@ "@fastify/websocket": "^8.2.0", "@filedrop/types": "*", "@types/node": "^20.4.5", - "@types/uuid": "^9.0.3", "@types/ws": "^8.5.3", "@typescript-eslint/eslint-plugin": "^6.2.0", "@typescript-eslint/parser": "^6.2.0", @@ -19,7 +18,6 @@ "fastify": "^4.21.0", "joi": "^17.6.0", "tsx": "^3.12.8", - "uuid": "^9.0.0", "ws": "^8.6.0" }, "scripts": { diff --git a/ws/src/utils/validation.ts b/ws/src/utils/validation.ts index c211e47..6d7f68c 100644 --- a/ws/src/utils/validation.ts +++ b/ws/src/utils/validation.ts @@ -48,7 +48,7 @@ const chatMessageModelSchema = Joi.object({ const transferMessageModelSchema = Joi.object({ type: Joi.string().equal(MessageType.TRANSFER).required(), - transferId: Joi.string().uuid().required(), + transferId: Joi.string().max(36).required(), targetId: Joi.string().hex().required(), fileName: Joi.string().required(), fileSize: Joi.number().required(), @@ -59,7 +59,7 @@ const transferMessageModelSchema = Joi.object({ const validActions = Object.values(ActionMessageActionType); const actionMessageModelSchema = Joi.object({ type: Joi.string().equal(MessageType.ACTION).required(), - transferId: Joi.string().uuid().required(), + transferId: Joi.string().max(36).required(), targetId: Joi.string().hex().required(), action: Joi.string() .equal(...validActions) @@ -68,7 +68,7 @@ const actionMessageModelSchema = Joi.object({ const rtcDescriptionMessageModelSchema = Joi.object({ type: Joi.string().equal(MessageType.RTC_DESCRIPTION).required(), - transferId: Joi.string().uuid().required(), + transferId: Joi.string().max(36).required(), targetId: Joi.string().hex().required(), data: Joi.object({ type: Joi.string().required(), @@ -78,7 +78,7 @@ const rtcDescriptionMessageModelSchema = Joi.object({ const rtcCandidateMessageModelSchema = Joi.object({ type: Joi.string().equal(MessageType.RTC_CANDIDATE).required(), - transferId: Joi.string().uuid().required(), + transferId: Joi.string().max(36).required(), targetId: Joi.string().hex().required(), data: Joi.object().required(), }).required(); diff --git a/yarn.lock b/yarn.lock index 72c771d..9ec37db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1719,11 +1719,6 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.4.tgz#0a41252ad431c473158b22f9bfb9a63df7541cff" integrity sha512-MMzuxN3GdFwskAnb6fz0orFvhfqi752yjaXylr0Rp4oDg5H0Zn1IuyRhDVvYOwAXoJirx2xuS16I3WjxnAIHiQ== -"@types/uuid@^9.0.3": - version "9.0.6" - resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.6.tgz#c91ae743d8344a54b2b0c691195f5ff5265f6dfb" - integrity sha512-BT2Krtx4xaO6iwzwMFUYvWBWkV2pr37zD68Vmp1CDV196MzczBRxuEpD6Pr395HAgebC/co7hOphs53r8V7jew== - "@types/ws@^8.5.3": version "8.5.8" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.8.tgz#13efec7bd439d0bdf2af93030804a94f163b1430" @@ -4498,6 +4493,11 @@ nanoid@^3.3.6: resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c" integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA== +nanoid@^5.0.2: + version "5.0.2" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.2.tgz#97588ebc70166d0feaf73ccd2799bb4ceaebf692" + integrity sha512-2ustYUX1R2rL/Br5B/FMhi8d5/QzvkJ912rBYxskcpu0myTHzSZfTr1LAS2Sm7jxRUObRrSBFoyzwAhL49aVSg== + natural-compare-lite@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" @@ -5981,11 +5981,6 @@ util-deprecate@^1.0.1, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== -uuid@^9.0.0: - version "9.0.1" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" - integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== - v8-compile-cache@2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"