Skip to content

Commit

Permalink
refactor(overrides): move types to top level types folder (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored Nov 6, 2024
1 parent 6f798de commit 44f3678
Show file tree
Hide file tree
Showing 40 changed files with 211 additions and 181 deletions.
8 changes: 4 additions & 4 deletions packages/open-next/src/adapters/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IncrementalCache } from "../overrides/incrementalCache/types.js";
import type { TagCache } from "../overrides/tagCache/types.js";
import { isBinaryContentType } from "./binary.js";
import { debug, error, warn } from "./logger.js";
import type { IncrementalCache, TagCache } from "types/overrides";

import { isBinaryContentType } from "./binary";
import { debug, error, warn } from "./logger";

interface CachedFetchValue {
kind: "FETCH";
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/core/createGenericHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
InternalEvent,
InternalResult,
OpenNextConfig,
OpenNextHandler,
} from "types/open-next";
import type { OpenNextHandler } from "types/overrides";

import { debug } from "../adapters/logger";
import { resolveConverter, resolveWrapper } from "./resolve";
Expand Down
5 changes: 2 additions & 3 deletions packages/open-next/src/core/createMainHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { AsyncLocalStorage } from "node:async_hooks";

import type { OpenNextConfig } from "types/open-next";
import type { IncrementalCache, Queue } from "types/overrides";
import type { DetachedPromiseRunner } from "utils/promise";

import { debug } from "../adapters/logger";
import { generateUniqueId } from "../adapters/util";
import type { IncrementalCache } from "../overrides/incrementalCache/types";
import type { Queue } from "../overrides/queue/types";
import { openNextHandler } from "./requestHandler.js";
import { openNextHandler } from "./requestHandler";
import {
resolveConverter,
resolveIncrementalCache,
Expand Down
13 changes: 7 additions & 6 deletions packages/open-next/src/core/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import type {
BaseEventOrResult,
Converter,
DefaultOverrideOptions,
ImageLoader,
InternalEvent,
InternalResult,
LazyLoadedOverride,
OriginResolver,
OverrideOptions,
} from "types/open-next";
import type {
Converter,
ImageLoader,
OriginResolver,
TagCache,
Warmer,
Wrapper,
} from "types/open-next.js";

import type { TagCache } from "../overrides/tagCache/types.js";
} from "types/overrides";

export async function resolveConverter<
E extends BaseEventOrResult = InternalEvent,
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/core/routing/cacheInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { createHash } from "node:crypto";

import { NextConfig, PrerenderManifest } from "config/index";
import type { InternalEvent, InternalResult } from "types/open-next";
import type { CacheValue } from "types/overrides";
import { emptyReadableStream, toReadableStream } from "utils/stream";

import { debug } from "../../adapters/logger";
import type { CacheValue } from "../../overrides/incrementalCache/types";
import { localizePath } from "./i18n";
import { generateMessageGroupId } from "./util";

Expand Down
3 changes: 2 additions & 1 deletion packages/open-next/src/overrides/converters/aws-apigw-v1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import type { Converter, InternalEvent, InternalResult } from "types/open-next";
import type { InternalEvent, InternalResult } from "types/open-next";
import type { Converter } from "types/overrides";
import { fromReadableStream } from "utils/stream";

import { debug } from "../../adapters/logger";
Expand Down
3 changes: 2 additions & 1 deletion packages/open-next/src/overrides/converters/aws-apigw-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type {
APIGatewayProxyResultV2,
} from "aws-lambda";
import { parseCookies } from "http/util";
import type { Converter, InternalEvent, InternalResult } from "types/open-next";
import type { InternalEvent, InternalResult } from "types/open-next";
import type { Converter } from "types/overrides";
import { fromReadableStream } from "utils/stream";

import { debug } from "../../adapters/logger";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import type {
CloudFrontRequestResult,
} from "aws-lambda";
import { parseCookies } from "http/util";
import type { Converter, InternalEvent, InternalResult } from "types/open-next";
import type { InternalEvent, InternalResult } from "types/open-next";
import type { Converter } from "types/overrides";
import { fromReadableStream } from "utils/stream";

import { debug } from "../../adapters/logger";
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/converters/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Converter } from "types/open-next";
import type { Converter } from "types/overrides";

type DummyEventOrResult = {
type: "dummy";
Expand Down
3 changes: 2 additions & 1 deletion packages/open-next/src/overrides/converters/edge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Buffer } from "node:buffer";

import { parseCookies } from "http/util";
import type { Converter, InternalEvent, InternalResult } from "types/open-next";
import type { InternalEvent, InternalResult } from "types/open-next";
import type { Converter } from "types/overrides";

import type { MiddlewareOutputEvent } from "../../core/routingHandler";

Expand Down
6 changes: 4 additions & 2 deletions packages/open-next/src/overrides/converters/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { IncomingMessage } from "http";
import type { IncomingMessage } from "node:http";

import { parseCookies } from "http/util";
import type { Converter, InternalResult } from "types/open-next";
import type { InternalResult } from "types/open-next";
import type { Converter } from "types/overrides";

const converter: Converter = {
convertFrom: async (req: IncomingMessage) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SQSEvent } from "aws-lambda";
import type { Converter } from "types/open-next";
import type { Converter } from "types/overrides";

import type { RevalidateEvent } from "../../adapters/revalidate";

Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/imageLoader/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ImageLoader } from "types/open-next";
import type { ImageLoader } from "types/overrides";
import { FatalError } from "utils/error";

const dummyLoader: ImageLoader = {
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/imageLoader/host.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Readable } from "node:stream";
import type { ReadableStream } from "node:stream/web";

import type { ImageLoader } from "types/open-next";
import type { ImageLoader } from "types/overrides";
import { FatalError } from "utils/error";

const hostLoader: ImageLoader = {
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/imageLoader/s3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Readable } from "node:stream";

import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
import type { ImageLoader } from "types/open-next";
import type { ImageLoader } from "types/overrides";
import { FatalError } from "utils/error";

import { awsLogger } from "../../adapters/logger";
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/incrementalCache/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IncrementalCache } from "./types";
import type { IncrementalCache } from "types/overrides";

const dummyIncrementalCache: IncrementalCache = {
name: "dummy",
Expand Down
5 changes: 3 additions & 2 deletions packages/open-next/src/overrides/incrementalCache/s3-lite.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import path from "node:path";

import { AwsClient } from "aws4fetch";
import path from "path";
import type { Extension } from "types/cache";
import type { IncrementalCache } from "types/overrides";
import { IgnorableError, RecoverableError } from "utils/error";
import { customFetchClient } from "utils/fetch";

import { parseNumberFromEnv } from "../../adapters/util";
import type { IncrementalCache } from "./types";

let awsClient: AwsClient | null = null;

Expand Down
5 changes: 3 additions & 2 deletions packages/open-next/src/overrides/incrementalCache/s3.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import path from "node:path";

import type { S3ClientConfig } from "@aws-sdk/client-s3";
import {
DeleteObjectCommand,
GetObjectCommand,
PutObjectCommand,
S3Client,
} from "@aws-sdk/client-s3";
import path from "path";
import type { Extension } from "types/cache";
import type { IncrementalCache } from "types/overrides";

import { awsLogger } from "../../adapters/logger";
import { parseNumberFromEnv } from "../../adapters/util";
import type { IncrementalCache } from "./types";

const {
CACHE_BUCKET_REGION,
Expand Down
50 changes: 0 additions & 50 deletions packages/open-next/src/overrides/incrementalCache/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/originResolver/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OriginResolver } from "types/open-next";
import type { OriginResolver } from "types/overrides";

const dummyOriginResolver: OriginResolver = {
name: "dummy",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Origin, OriginResolver } from "types/open-next";
import type { Origin } from "types/open-next";
import type { OriginResolver } from "types/overrides";

import { debug, error } from "../../adapters/logger";

Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/queue/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Queue } from "./types";
import type { Queue } from "types/overrides";

const dummyQueue: Queue = {
name: "dummy",
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/queue/sqs-lite.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AwsClient } from "aws4fetch";
import type { Queue } from "types/overrides";
import { RecoverableError } from "utils/error";
import { customFetchClient } from "utils/fetch";

import { error } from "../../adapters/logger";
import type { Queue } from "./types";

let awsClient: AwsClient | null = null;

Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/queue/sqs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
import type { Queue } from "types/overrides";

import { awsLogger } from "../../adapters/logger";
import type { Queue } from "./types";

// Expected environment variables
const { REVALIDATION_QUEUE_REGION, REVALIDATION_QUEUE_URL } = process.env;
Expand Down
13 changes: 0 additions & 13 deletions packages/open-next/src/overrides/queue/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/tagCache/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TagCache } from "./types";
import type { TagCache } from "types/overrides";

// We don't want to throw error on this one because we might use it when we don't need tag cache
const dummyTagCache: TagCache = {
Expand Down
5 changes: 3 additions & 2 deletions packages/open-next/src/overrides/tagCache/dynamodb-lite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import path from "node:path";

import { AwsClient } from "aws4fetch";
import path from "path";
import type { TagCache } from "types/overrides";
import { RecoverableError } from "utils/error";
import { customFetchClient } from "utils/fetch";

Expand All @@ -10,7 +12,6 @@ import {
getDynamoBatchWriteCommandConcurrency,
MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT,
} from "./constants";
import type { TagCache } from "./types";

let awsClient: AwsClient | null = null;

Expand Down
5 changes: 3 additions & 2 deletions packages/open-next/src/overrides/tagCache/dynamodb.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import path from "node:path";

import type { DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
import {
BatchWriteItemCommand,
DynamoDBClient,
QueryCommand,
} from "@aws-sdk/client-dynamodb";
import path from "path";
import type { TagCache } from "types/overrides";

import { awsLogger, debug, error } from "../../adapters/logger";
import { chunk, parseNumberFromEnv } from "../../adapters/util";
import {
getDynamoBatchWriteCommandConcurrency,
MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT,
} from "./constants";
import type { TagCache } from "./types";

const { CACHE_BUCKET_REGION, CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;

Expand Down
9 changes: 0 additions & 9 deletions packages/open-next/src/overrides/tagCache/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/warmer/aws-lambda.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Warmer } from "types/open-next";
import type { Warmer } from "types/overrides";

import { debug, error } from "../../adapters/logger";
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/warmer/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Warmer } from "types/open-next";
import type { Warmer } from "types/overrides";

const dummyWarmer: Warmer = {
name: "dummy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Readable, type Writable } from "node:stream";
import zlib from "node:zlib";

import type { APIGatewayProxyEventV2 } from "aws-lambda";
import type { StreamCreator } from "http/index.js";
import type { WrapperHandler } from "types/open-next";
import type { StreamCreator } from "http/index";
import type { WrapperHandler } from "types/overrides";

import { debug, error } from "../../adapters/logger";
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/overrides/wrappers/aws-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
CloudFrontRequestResult,
} from "aws-lambda";
import type { StreamCreator } from "http/openNextResponse";
import type { WrapperHandler } from "types/open-next";
import type { WrapperHandler } from "types/overrides";

import type {
WarmerEvent,
Expand Down
Loading

0 comments on commit 44f3678

Please sign in to comment.