Skip to content

Commit

Permalink
restructure/simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
james-elicx committed Oct 1, 2024
1 parent 0e2df7f commit cfa1bc6
Show file tree
Hide file tree
Showing 41 changed files with 810 additions and 810 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"error",
{ "devDependencies": ["**/*.spec.ts", "vite.config.ts"] },
],
"import/extensions": ["error", "never"],
"no-console": "error",
},
"ignorePatterns": ["dist", "scripts", "fixtures/**/*.js", "fixtures/**/*.cjs"],
Expand Down
9 changes: 5 additions & 4 deletions src/router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ConfigMetadata } from './routes-matcher';
import type { RoutesGroupedByPhase } from '@/types/build-output';
import type { RequestContext } from '@/types/request-context';
import { applyHeaders, applySearchParams, isUrl } from '@/utils/http';

import type { ConfigMetadata, RoutingMatch } from './routes-matcher';
import { RoutesMatcher } from './routes-matcher';
import type { RequestContext, RoutesGroupedByPhase } from './types';
import type { RoutingMatch } from './utils';
import { applyHeaders, applySearchParams, isUrl } from './utils';

export class Router {
constructor(
Expand Down
53 changes: 32 additions & 21 deletions src/routes-matcher.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import { parse } from 'cookie';

import type {
Phase,
RequestContext,
RoutesGroupedByPhase,
SourceRoute,
VercelWildCard,
} from './types';
import type { MatchPCREResult, RoutingMatch } from './utils';
import {
applyHeaders,
applyPCREMatches,
applySearchParams,
checkHasField,
getNextPhase,
isLocaleTrailingSlashRegex,
isUrl,
matchPCRE,
parseAcceptLanguage,
} from './utils';
import type { Phase, RoutesGroupedByPhase, SourceRoute } from '@/types/build-output';
import type { RequestContext } from '@/types/request-context';
import type { WildCard } from '@/types/vercel-config';
import { applyHeaders, applySearchParams, isUrl, parseAcceptLanguage } from '@/utils/http';
import type { MatchPCREResult } from '@/utils/pcre';
import { applyPCREMatches, matchPCRE } from '@/utils/pcre';
import { checkHasField, getNextPhase, isLocaleTrailingSlashRegex } from '@/utils/routing';

export type ConfigMetadata = {
locales: Set<string>;
wildcardConfig: VercelWildCard[] | undefined;
wildcardConfig: WildCard[] | undefined;
};

export type RoutingMatch = {
path: string;
status: number | undefined;
headers: {
/**
* The headers present on a source route.
* Gets applied to the final response before the response headers from running a function.
*/
normal: Headers;
/**
* The *important* headers - the ones present on a source route that specifies `important: true`.
* Gets applied to the final response after the response headers from running a function.
*/
important: Headers;
/**
* Tracks if a location header is found, and what the value is, after running a middleware function.
*/
middlewareLocation?: string | null;
};
searchParams: URLSearchParams;
body: BodyInit | undefined | null;
};

export type CheckRouteStatus = 'skip' | 'next' | 'done' | 'error';
Expand All @@ -39,7 +50,7 @@ export class RoutesMatcher {
private cookies: Record<string, string>;

/** Wildcard match from the Vercel build output config */
private wildcardMatch: VercelWildCard | undefined;
private wildcardMatch: WildCard | undefined;

/** Path for the matched route */
public path: string;
Expand Down
177 changes: 0 additions & 177 deletions src/utils/http.spec.ts

This file was deleted.

127 changes: 0 additions & 127 deletions src/utils/http.ts

This file was deleted.

Loading

0 comments on commit cfa1bc6

Please sign in to comment.