refactor: reorganize project structure and consolidate test files

Consolidate test files into centralized __tests__ directory with clearer
naming. Rename utility modules for improved clarity and consistency.
Rename Generic component to RdapObjectRouter to better reflect purpose.
This commit is contained in:
2025-10-23 16:34:05 -05:00
parent 2f23dd33e9
commit 5fcf9dd94b
18 changed files with 20 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect } from "vitest"; import { describe, it, expect } from "vitest";
import { serializeQueryToUrl, deserializeUrlToQuery, buildShareableUrl } from "@/lib/url-utils"; import { serializeQueryToUrl, deserializeUrlToQuery, buildShareableUrl } from "@/lib/urls";
describe("URL Utilities", () => { describe("URL Utilities", () => {
describe("serializeQueryToUrl", () => { describe("serializeQueryToUrl", () => {

View File

@@ -4,8 +4,8 @@ import { useBoolean } from "usehooks-ts";
import { Link2Icon, CodeIcon, DownloadIcon } from "@radix-ui/react-icons"; import { Link2Icon, CodeIcon, DownloadIcon } from "@radix-ui/react-icons";
import { Card, Flex, Box, IconButton, Code, Tooltip } from "@radix-ui/themes"; import { Card, Flex, Box, IconButton, Code, Tooltip } from "@radix-ui/themes";
import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
import type { ParsedGeneric } from "@/rdap/components/Generic"; import type { ParsedGeneric } from "@/rdap/components/RdapObjectRouter";
import { generateDownloadFilename } from "@/utils/generateFilename"; import { generateDownloadFilename } from "@/lib/filename";
import CopyButton from "@/components/CopyButton"; import CopyButton from "@/components/CopyButton";
type AbstractCardProps = { type AbstractCardProps = {

View File

@@ -1,4 +1,4 @@
import type { ParsedGeneric } from "@/rdap/components/Generic"; import type { ParsedGeneric } from "@/rdap/components/RdapObjectRouter";
/** /**
* Attempts to convert an IP range to CIDR notation * Attempts to convert an IP range to CIDR notation

View File

View File

View File

@@ -2,7 +2,7 @@ import { type NextPage } from "next";
import Head from "next/head"; import Head from "next/head";
import { useState, useEffect, useCallback } from "react"; import { useState, useEffect, useCallback } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import Generic from "@/rdap/components/Generic"; import RdapObjectRouter from "@/rdap/components/RdapObjectRouter";
import type { MetaParsedGeneric } from "@/rdap/hooks/useLookup"; import type { MetaParsedGeneric } from "@/rdap/hooks/useLookup";
import useLookup from "@/rdap/hooks/useLookup"; import useLookup from "@/rdap/hooks/useLookup";
import LookupInput from "@/rdap/components/LookupInput"; import LookupInput from "@/rdap/components/LookupInput";
@@ -12,7 +12,7 @@ import { Maybe } from "true-myth";
import { Flex, Container, Section, Text, Link, IconButton } from "@radix-ui/themes"; import { Flex, Container, Section, Text, Link, IconButton } from "@radix-ui/themes";
import { GitHubLogoIcon } from "@radix-ui/react-icons"; import { GitHubLogoIcon } from "@radix-ui/react-icons";
import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
import { serializeQueryToUrl, deserializeUrlToQuery, buildShareableUrl } from "@/lib/url-utils"; import { serializeQueryToUrl, deserializeUrlToQuery, buildShareableUrl } from "@/lib/urls";
import type { TargetType } from "@/rdap/schemas"; import type { TargetType } from "@/rdap/schemas";
const Index: NextPage = () => { const Index: NextPage = () => {
@@ -172,7 +172,7 @@ const Index: NextPage = () => {
/> />
) : null} ) : null}
{response.isJust ? ( {response.isJust ? (
<Generic <RdapObjectRouter
url={response.value.url} url={response.value.url}
data={response.value.data} data={response.value.data}
queryTimestamp={response.value.completeTime} queryTimestamp={response.value.completeTime}

View File

@@ -1,7 +1,7 @@
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import type { FunctionComponent } from "react"; import type { FunctionComponent } from "react";
import { useState, useEffect, useRef } from "react"; import { useState, useEffect, useRef } from "react";
import { onPromise, preventDefault } from "@/lib/utils"; import { onPromise, preventDefault } from "@/lib/misc";
import type { SimplifiedTargetType, SubmitProps, TargetType } from "@/rdap/schemas"; import type { SimplifiedTargetType, SubmitProps, TargetType } from "@/rdap/schemas";
import { TargetTypeEnum } from "@/rdap/schemas"; import { TargetTypeEnum } from "@/rdap/schemas";
import { MagnifyingGlassIcon, ReloadIcon, LockClosedIcon } from "@radix-ui/react-icons"; import { MagnifyingGlassIcon, ReloadIcon, LockClosedIcon } from "@radix-ui/react-icons";

View File

@@ -15,7 +15,11 @@ export type ObjectProps = {
queryTimestamp?: Date; queryTimestamp?: Date;
}; };
const Generic: FunctionComponent<ObjectProps> = ({ data, url, queryTimestamp }: ObjectProps) => { const RdapObjectRouter: FunctionComponent<ObjectProps> = ({
data,
url,
queryTimestamp,
}: ObjectProps) => {
const objectClassName = data.objectClassName; const objectClassName = data.objectClassName;
switch (objectClassName) { switch (objectClassName) {
@@ -38,4 +42,4 @@ const Generic: FunctionComponent<ObjectProps> = ({ data, url, queryTimestamp }:
} }
}; };
export default Generic; export default RdapObjectRouter;

View File

@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { useDebouncedValue } from "@mantine/hooks"; import { useDebouncedValue } from "@mantine/hooks";
import type { SubmitProps, TargetType } from "@/rdap/schemas"; import type { SubmitProps, TargetType } from "@/rdap/schemas";
import { RootRegistryEnum } from "@/rdap/schemas"; import { RootRegistryEnum } from "@/rdap/schemas";
import type { ParsedGeneric } from "@/rdap/components/Generic"; import type { ParsedGeneric } from "@/rdap/components/RdapObjectRouter";
import { Maybe, Result } from "true-myth"; import { Maybe, Result } from "true-myth";
import { loadBootstrap, getRegistry } from "@/rdap/services/registry"; import { loadBootstrap, getRegistry } from "@/rdap/services/registry";
import { import {
@@ -11,7 +11,7 @@ import {
generateValidationWarning, generateValidationWarning,
generateBootstrapWarning, generateBootstrapWarning,
} from "@/rdap/services/type-detection"; } from "@/rdap/services/type-detection";
import { executeRdapQuery, HttpSecurityError } from "@/rdap/services/rdap-query"; import { executeRdapQuery, HttpSecurityError } from "@/rdap/services/query";
export type WarningHandler = (warning: { message: string }) => void; export type WarningHandler = (warning: { message: string }) => void;
export type UrlUpdateHandler = (target: string, manuallySelectedType: TargetType | null) => void; export type UrlUpdateHandler = (target: string, manuallySelectedType: TargetType | null) => void;

View File

@@ -7,9 +7,9 @@ import {
} from "@/rdap/schemas"; } from "@/rdap/schemas";
import { Result } from "true-myth"; import { Result } from "true-myth";
import { loadBootstrap } from "@/rdap/services/registry"; import { loadBootstrap } from "@/rdap/services/registry";
import { getRegistryURL } from "@/rdap/services/url-resolver"; import { getRegistryURL } from "@/rdap/services/resolver";
import { getAndParse } from "@/rdap/services/rdap-api"; import { getAndParse } from "@/rdap/services/api";
import type { ParsedGeneric } from "@/rdap/components/Generic"; import type { ParsedGeneric } from "@/rdap/components/RdapObjectRouter";
// An array of schemas to try and parse unknown JSON data with. // An array of schemas to try and parse unknown JSON data with.
const schemas = [DomainSchema, AutonomousNumberSchema, IpNetworkSchema, EntitySchema]; const schemas = [DomainSchema, AutonomousNumberSchema, IpNetworkSchema, EntitySchema];

View File

@@ -1,7 +1,7 @@
import type { Register, RootRegistryType, TargetType } from "@/rdap/schemas"; import type { Register, RootRegistryType, TargetType } from "@/rdap/schemas";
import { getType, validateInputForType } from "@/rdap/utils"; import { getType, validateInputForType } from "@/rdap/utils";
import type { Result } from "true-myth"; import type { Result } from "true-myth";
import { truncated } from "@/lib/utils"; import { truncated } from "@/lib/misc";
/** /**
* Detect the target type for a given input string. * Detect the target type for a given input string.