From b0c2c217feb024ddf4867cbbe0ac164647733545 Mon Sep 17 00:00:00 2001 From: Juan Sebastian Montoya Date: Thu, 26 Sep 2024 02:57:38 -0500 Subject: [PATCH] Fix build and non-random seed --- package.json | 5 +++-- src/routes/avatar.route.ts | 6 ++++-- src/utils/type-guards.ts | 7 ++++--- tsconfig.json | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index c3c9950..f263148 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "version": "1.0.0", "description": "", "main": "dist/index.js", + "type": "module", "scripts": { "build": "npx tsc", - "start": "node dist/index.js", + "start": "node --experimental-specifier-resolution=node dist/index.js", "dev": "tsx watch src/index.ts", "preinstall": "yarn config set ignore-engines true" }, @@ -36,4 +37,4 @@ "tsx": "^4.19.1", "typescript": "^4.7.4" } -} +} \ No newline at end of file diff --git a/src/routes/avatar.route.ts b/src/routes/avatar.route.ts index a988030..7043686 100644 --- a/src/routes/avatar.route.ts +++ b/src/routes/avatar.route.ts @@ -1,10 +1,11 @@ import Router from "koa-router"; import { v4 as uuidv4 } from "uuid"; +import sharp from "sharp"; + import { createAvatar, Style } from "@dicebear/core"; import * as openPeeps from "@dicebear/open-peeps"; import * as pixelArt from "@dicebear/pixel-art"; import * as thumbs from "@dicebear/thumbs"; -import sharp from "sharp"; import { isValue, isSize, isStyle } from "../utils/type-guards"; @@ -47,7 +48,8 @@ router.get("/random", async (ctx) => { }); router.get("/:seed", async (ctx) => { - const { seed, style = "thumbs", size = "100" } = ctx.query; + const { seed } = ctx.params; + const { style = "thumbs", size = "100" } = ctx.query; if (!isValue(seed) || !isValidStyle(style) || !isSize(size)) { throw Error("Invalid query"); } diff --git a/src/utils/type-guards.ts b/src/utils/type-guards.ts index 88d663b..ca59ea6 100644 --- a/src/utils/type-guards.ts +++ b/src/utils/type-guards.ts @@ -1,7 +1,8 @@ -import { ValidationError } from "joi"; +import Joi from "joi"; -export const isValidationError = (error: unknown): error is ValidationError => - error instanceof ValidationError; +export const isValidationError = ( + error: unknown +): error is Joi.ValidationError => error instanceof Joi.ValidationError; export const isValue = (value: T | Array | undefined): value is T => !!value && !Array.isArray(value); diff --git a/tsconfig.json b/tsconfig.json index e40f826..251fef8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,9 +25,9 @@ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ + "module": "esnext", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */