diff --git a/packages/open-next/src/adapters/cache.ts b/packages/open-next/src/adapters/cache.ts index b357d0db..7de1b883 100644 --- a/packages/open-next/src/adapters/cache.ts +++ b/packages/open-next/src/adapters/cache.ts @@ -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"; diff --git a/packages/open-next/src/core/createGenericHandler.ts b/packages/open-next/src/core/createGenericHandler.ts index 213f6269..4a78d97b 100644 --- a/packages/open-next/src/core/createGenericHandler.ts +++ b/packages/open-next/src/core/createGenericHandler.ts @@ -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"; diff --git a/packages/open-next/src/core/createMainHandler.ts b/packages/open-next/src/core/createMainHandler.ts index 89099f6d..44ba7ab4 100644 --- a/packages/open-next/src/core/createMainHandler.ts +++ b/packages/open-next/src/core/createMainHandler.ts @@ -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, diff --git a/packages/open-next/src/core/resolve.ts b/packages/open-next/src/core/resolve.ts index 56223b33..82b7c2bf 100644 --- a/packages/open-next/src/core/resolve.ts +++ b/packages/open-next/src/core/resolve.ts @@ -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, diff --git a/packages/open-next/src/core/routing/cacheInterceptor.ts b/packages/open-next/src/core/routing/cacheInterceptor.ts index 515aa1f0..d77ecf14 100644 --- a/packages/open-next/src/core/routing/cacheInterceptor.ts +++ b/packages/open-next/src/core/routing/cacheInterceptor.ts @@ -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"; diff --git a/packages/open-next/src/overrides/converters/aws-apigw-v1.ts b/packages/open-next/src/overrides/converters/aws-apigw-v1.ts index 4dbc1e2e..8dec3b73 100644 --- a/packages/open-next/src/overrides/converters/aws-apigw-v1.ts +++ b/packages/open-next/src/overrides/converters/aws-apigw-v1.ts @@ -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"; diff --git a/packages/open-next/src/overrides/converters/aws-apigw-v2.ts b/packages/open-next/src/overrides/converters/aws-apigw-v2.ts index e9eefe79..23bc239b 100644 --- a/packages/open-next/src/overrides/converters/aws-apigw-v2.ts +++ b/packages/open-next/src/overrides/converters/aws-apigw-v2.ts @@ -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"; diff --git a/packages/open-next/src/overrides/converters/aws-cloudfront.ts b/packages/open-next/src/overrides/converters/aws-cloudfront.ts index c0d19911..2ffbbf9a 100644 --- a/packages/open-next/src/overrides/converters/aws-cloudfront.ts +++ b/packages/open-next/src/overrides/converters/aws-cloudfront.ts @@ -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"; diff --git a/packages/open-next/src/overrides/converters/dummy.ts b/packages/open-next/src/overrides/converters/dummy.ts index dda76c67..5ac645ff 100644 --- a/packages/open-next/src/overrides/converters/dummy.ts +++ b/packages/open-next/src/overrides/converters/dummy.ts @@ -1,4 +1,4 @@ -import type { Converter } from "types/open-next"; +import type { Converter } from "types/overrides"; type DummyEventOrResult = { type: "dummy"; diff --git a/packages/open-next/src/overrides/converters/edge.ts b/packages/open-next/src/overrides/converters/edge.ts index 43346d81..35e05512 100644 --- a/packages/open-next/src/overrides/converters/edge.ts +++ b/packages/open-next/src/overrides/converters/edge.ts @@ -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"; diff --git a/packages/open-next/src/overrides/converters/node.ts b/packages/open-next/src/overrides/converters/node.ts index 50251d0f..9a97da98 100644 --- a/packages/open-next/src/overrides/converters/node.ts +++ b/packages/open-next/src/overrides/converters/node.ts @@ -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) => { diff --git a/packages/open-next/src/overrides/converters/sqs-revalidate.ts b/packages/open-next/src/overrides/converters/sqs-revalidate.ts index c8c29c02..617c93b9 100644 --- a/packages/open-next/src/overrides/converters/sqs-revalidate.ts +++ b/packages/open-next/src/overrides/converters/sqs-revalidate.ts @@ -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"; diff --git a/packages/open-next/src/overrides/imageLoader/dummy.ts b/packages/open-next/src/overrides/imageLoader/dummy.ts index 177cff80..ea1fe19e 100644 --- a/packages/open-next/src/overrides/imageLoader/dummy.ts +++ b/packages/open-next/src/overrides/imageLoader/dummy.ts @@ -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 = { diff --git a/packages/open-next/src/overrides/imageLoader/host.ts b/packages/open-next/src/overrides/imageLoader/host.ts index a6e8b3d3..f504fe77 100644 --- a/packages/open-next/src/overrides/imageLoader/host.ts +++ b/packages/open-next/src/overrides/imageLoader/host.ts @@ -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 = { diff --git a/packages/open-next/src/overrides/imageLoader/s3.ts b/packages/open-next/src/overrides/imageLoader/s3.ts index af85de3b..47c0d29c 100644 --- a/packages/open-next/src/overrides/imageLoader/s3.ts +++ b/packages/open-next/src/overrides/imageLoader/s3.ts @@ -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"; diff --git a/packages/open-next/src/overrides/incrementalCache/dummy.ts b/packages/open-next/src/overrides/incrementalCache/dummy.ts index c6605b8d..7e84c96a 100644 --- a/packages/open-next/src/overrides/incrementalCache/dummy.ts +++ b/packages/open-next/src/overrides/incrementalCache/dummy.ts @@ -1,4 +1,4 @@ -import type { IncrementalCache } from "./types"; +import type { IncrementalCache } from "types/overrides"; const dummyIncrementalCache: IncrementalCache = { name: "dummy", diff --git a/packages/open-next/src/overrides/incrementalCache/s3-lite.ts b/packages/open-next/src/overrides/incrementalCache/s3-lite.ts index ba626db1..da56466b 100644 --- a/packages/open-next/src/overrides/incrementalCache/s3-lite.ts +++ b/packages/open-next/src/overrides/incrementalCache/s3-lite.ts @@ -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; diff --git a/packages/open-next/src/overrides/incrementalCache/s3.ts b/packages/open-next/src/overrides/incrementalCache/s3.ts index 14c583af..0ee7f6b5 100644 --- a/packages/open-next/src/overrides/incrementalCache/s3.ts +++ b/packages/open-next/src/overrides/incrementalCache/s3.ts @@ -1,3 +1,5 @@ +import path from "node:path"; + import type { S3ClientConfig } from "@aws-sdk/client-s3"; import { DeleteObjectCommand, @@ -5,12 +7,11 @@ import { 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, diff --git a/packages/open-next/src/overrides/incrementalCache/types.ts b/packages/open-next/src/overrides/incrementalCache/types.ts deleted file mode 100644 index d86c1b92..00000000 --- a/packages/open-next/src/overrides/incrementalCache/types.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { Meta } from "types/cache"; - -export type S3CachedFile = - | { - type: "redirect"; - props?: Object; - meta?: Meta; - } - | { - type: "page"; - html: string; - json: Object; - meta?: Meta; - } - | { - type: "app"; - html: string; - rsc: string; - meta?: Meta; - } - | { - type: "route"; - body: string; - meta?: Meta; - }; - -export type S3FetchCache = Object; - -export type WithLastModified = { - lastModified?: number; - value?: T; -}; - -export type CacheValue = (IsFetch extends true - ? S3FetchCache - : S3CachedFile) & { revalidate?: number | false }; - -export type IncrementalCache = { - get( - key: string, - isFetch?: IsFetch, - ): Promise>>; - set( - key: string, - value: CacheValue, - isFetch?: IsFetch, - ): Promise; - delete(key: string): Promise; - name: string; -}; diff --git a/packages/open-next/src/overrides/originResolver/dummy.ts b/packages/open-next/src/overrides/originResolver/dummy.ts index 95b561a5..d80298d5 100644 --- a/packages/open-next/src/overrides/originResolver/dummy.ts +++ b/packages/open-next/src/overrides/originResolver/dummy.ts @@ -1,4 +1,4 @@ -import type { OriginResolver } from "types/open-next"; +import type { OriginResolver } from "types/overrides"; const dummyOriginResolver: OriginResolver = { name: "dummy", diff --git a/packages/open-next/src/overrides/originResolver/pattern-env.ts b/packages/open-next/src/overrides/originResolver/pattern-env.ts index 3e889bd6..5138087a 100644 --- a/packages/open-next/src/overrides/originResolver/pattern-env.ts +++ b/packages/open-next/src/overrides/originResolver/pattern-env.ts @@ -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"; diff --git a/packages/open-next/src/overrides/queue/dummy.ts b/packages/open-next/src/overrides/queue/dummy.ts index 5e20a3d4..3d032e01 100644 --- a/packages/open-next/src/overrides/queue/dummy.ts +++ b/packages/open-next/src/overrides/queue/dummy.ts @@ -1,4 +1,4 @@ -import type { Queue } from "./types"; +import type { Queue } from "types/overrides"; const dummyQueue: Queue = { name: "dummy", diff --git a/packages/open-next/src/overrides/queue/sqs-lite.ts b/packages/open-next/src/overrides/queue/sqs-lite.ts index 813a71a6..2a46a9ef 100644 --- a/packages/open-next/src/overrides/queue/sqs-lite.ts +++ b/packages/open-next/src/overrides/queue/sqs-lite.ts @@ -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; diff --git a/packages/open-next/src/overrides/queue/sqs.ts b/packages/open-next/src/overrides/queue/sqs.ts index 43cc320b..e43f3cb8 100644 --- a/packages/open-next/src/overrides/queue/sqs.ts +++ b/packages/open-next/src/overrides/queue/sqs.ts @@ -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; diff --git a/packages/open-next/src/overrides/queue/types.ts b/packages/open-next/src/overrides/queue/types.ts deleted file mode 100644 index eaba1cb6..00000000 --- a/packages/open-next/src/overrides/queue/types.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface QueueMessage { - MessageDeduplicationId: string; - MessageBody: { - host: string; - url: string; - }; - MessageGroupId: string; -} - -export interface Queue { - send(message: QueueMessage): Promise; - name: string; -} diff --git a/packages/open-next/src/overrides/tagCache/dummy.ts b/packages/open-next/src/overrides/tagCache/dummy.ts index ab7d180d..0428938a 100644 --- a/packages/open-next/src/overrides/tagCache/dummy.ts +++ b/packages/open-next/src/overrides/tagCache/dummy.ts @@ -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 = { diff --git a/packages/open-next/src/overrides/tagCache/dynamodb-lite.ts b/packages/open-next/src/overrides/tagCache/dynamodb-lite.ts index 50ab81bd..9f748d01 100644 --- a/packages/open-next/src/overrides/tagCache/dynamodb-lite.ts +++ b/packages/open-next/src/overrides/tagCache/dynamodb-lite.ts @@ -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"; @@ -10,7 +12,6 @@ import { getDynamoBatchWriteCommandConcurrency, MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT, } from "./constants"; -import type { TagCache } from "./types"; let awsClient: AwsClient | null = null; diff --git a/packages/open-next/src/overrides/tagCache/dynamodb.ts b/packages/open-next/src/overrides/tagCache/dynamodb.ts index b035cb5c..e93a3270 100644 --- a/packages/open-next/src/overrides/tagCache/dynamodb.ts +++ b/packages/open-next/src/overrides/tagCache/dynamodb.ts @@ -1,10 +1,12 @@ +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"; @@ -12,7 +14,6 @@ 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; diff --git a/packages/open-next/src/overrides/tagCache/types.ts b/packages/open-next/src/overrides/tagCache/types.ts deleted file mode 100644 index 533e725c..00000000 --- a/packages/open-next/src/overrides/tagCache/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export type TagCache = { - getByTag(tag: string): Promise; - getByPath(path: string): Promise; - getLastModified(path: string, lastModified?: number): Promise; - writeTags( - tags: { tag: string; path: string; revalidatedAt?: number }[], - ): Promise; - name: string; -}; diff --git a/packages/open-next/src/overrides/warmer/aws-lambda.ts b/packages/open-next/src/overrides/warmer/aws-lambda.ts index 0a8af22d..eaad97e4 100644 --- a/packages/open-next/src/overrides/warmer/aws-lambda.ts +++ b/packages/open-next/src/overrides/warmer/aws-lambda.ts @@ -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 { diff --git a/packages/open-next/src/overrides/warmer/dummy.ts b/packages/open-next/src/overrides/warmer/dummy.ts index 01112f5b..15f23167 100644 --- a/packages/open-next/src/overrides/warmer/dummy.ts +++ b/packages/open-next/src/overrides/warmer/dummy.ts @@ -1,4 +1,4 @@ -import type { Warmer } from "types/open-next"; +import type { Warmer } from "types/overrides"; const dummyWarmer: Warmer = { name: "dummy", diff --git a/packages/open-next/src/overrides/wrappers/aws-lambda-streaming.ts b/packages/open-next/src/overrides/wrappers/aws-lambda-streaming.ts index 8a6e57f2..c0b38051 100644 --- a/packages/open-next/src/overrides/wrappers/aws-lambda-streaming.ts +++ b/packages/open-next/src/overrides/wrappers/aws-lambda-streaming.ts @@ -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 { diff --git a/packages/open-next/src/overrides/wrappers/aws-lambda.ts b/packages/open-next/src/overrides/wrappers/aws-lambda.ts index 833951b3..eb1a67e4 100644 --- a/packages/open-next/src/overrides/wrappers/aws-lambda.ts +++ b/packages/open-next/src/overrides/wrappers/aws-lambda.ts @@ -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, diff --git a/packages/open-next/src/overrides/wrappers/cloudflare.ts b/packages/open-next/src/overrides/wrappers/cloudflare.ts index 7c6789a0..32dc17a8 100644 --- a/packages/open-next/src/overrides/wrappers/cloudflare.ts +++ b/packages/open-next/src/overrides/wrappers/cloudflare.ts @@ -1,8 +1,5 @@ -import type { - InternalEvent, - InternalResult, - WrapperHandler, -} from "types/open-next"; +import type { InternalEvent, InternalResult } from "types/open-next"; +import type { WrapperHandler } from "types/overrides"; import type { MiddlewareOutputEvent } from "../../core/routingHandler"; diff --git a/packages/open-next/src/overrides/wrappers/dummy.ts b/packages/open-next/src/overrides/wrappers/dummy.ts index d9718997..c6492f8a 100644 --- a/packages/open-next/src/overrides/wrappers/dummy.ts +++ b/packages/open-next/src/overrides/wrappers/dummy.ts @@ -1,4 +1,4 @@ -import type { WrapperHandler } from "types/open-next"; +import type { WrapperHandler } from "types/overrides"; const dummyWrapper: WrapperHandler = async () => async () => undefined; diff --git a/packages/open-next/src/overrides/wrappers/node.ts b/packages/open-next/src/overrides/wrappers/node.ts index bc1b69c5..36c1b717 100644 --- a/packages/open-next/src/overrides/wrappers/node.ts +++ b/packages/open-next/src/overrides/wrappers/node.ts @@ -1,7 +1,7 @@ import { createServer } from "node:http"; -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"; diff --git a/packages/open-next/src/plugins/resolve.ts b/packages/open-next/src/plugins/resolve.ts index 1cd67982..a0ea01cc 100644 --- a/packages/open-next/src/plugins/resolve.ts +++ b/packages/open-next/src/plugins/resolve.ts @@ -4,15 +4,13 @@ import chalk from "chalk"; import type { Plugin } from "esbuild"; import type { DefaultOverrideOptions, - ImageLoader, IncludedImageLoader, IncludedOriginResolver, IncludedWarmer, LazyLoadedOverride, - OriginResolver, OverrideOptions, - Warmer, } from "types/open-next"; +import type { ImageLoader, OriginResolver, Warmer } from "types/overrides"; import logger from "../logger.js"; diff --git a/packages/open-next/src/types/open-next.ts b/packages/open-next/src/types/open-next.ts index 5729a893..bd975584 100644 --- a/packages/open-next/src/types/open-next.ts +++ b/packages/open-next/src/types/open-next.ts @@ -1,12 +1,16 @@ -import type { Readable } from "node:stream"; import type { ReadableStream } from "node:stream/web"; -import type { StreamCreator } from "http/index.js"; - import type { WarmerEvent, WarmerResponse } from "../adapters/warmer-function"; -import type { IncrementalCache } from "../overrides/incrementalCache/types"; -import type { Queue } from "../overrides/queue/types"; -import type { TagCache } from "../overrides/tagCache/types"; +import type { + Converter, + ImageLoader, + IncrementalCache, + OriginResolver, + Queue, + TagCache, + Warmer, + Wrapper, +} from "./overrides"; export type BaseEventOrResult = { type: T; @@ -64,57 +68,12 @@ export type BaseOverride = { }; export type LazyLoadedOverride = () => Promise; -export type OpenNextHandler< - E extends BaseEventOrResult = InternalEvent, - R extends BaseEventOrResult = InternalResult, -> = (event: E, responseStream?: StreamCreator) => Promise; - -export type Converter< - E extends BaseEventOrResult = InternalEvent, - R extends BaseEventOrResult = InternalResult, -> = BaseOverride & { - convertFrom: (event: any) => Promise; - convertTo: (result: R, originalRequest?: any) => Promise; -}; - -export type WrapperHandler< - E extends BaseEventOrResult = InternalEvent, - R extends BaseEventOrResult = InternalResult, -> = ( - handler: OpenNextHandler, - converter: Converter, -) => Promise<(...args: any[]) => any>; - -export type Wrapper< - E extends BaseEventOrResult = InternalEvent, - R extends BaseEventOrResult = InternalResult, -> = BaseOverride & { - wrapper: WrapperHandler; - supportStreaming: boolean; - edgeRuntime?: boolean; -}; - -export type Warmer = BaseOverride & { - invoke: (warmerId: string) => Promise; -}; - -export type ImageLoader = BaseOverride & { - load: (url: string) => Promise<{ - body?: Readable; - contentType?: string; - cacheControl?: string; - }>; -}; - export interface Origin { host: string; protocol: "http" | "https"; port?: number; customHeaders?: Record; } -export type OriginResolver = BaseOverride & { - resolve: (path: string) => Promise; -}; export type IncludedWrapper = | "aws-lambda" diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts new file mode 100644 index 00000000..74bc171d --- /dev/null +++ b/packages/open-next/src/types/overrides.ts @@ -0,0 +1,137 @@ +import type { Readable } from "node:stream"; + +import type { StreamCreator } from "http/index"; +import type { Meta } from "types/cache"; + +import type { + BaseEventOrResult, + BaseOverride, + InternalEvent, + InternalResult, + Origin, +} from "./open-next"; + +// Queue + +export interface QueueMessage { + MessageDeduplicationId: string; + MessageBody: { + host: string; + url: string; + }; + MessageGroupId: string; +} + +export interface Queue { + send(message: QueueMessage): Promise; + name: string; +} + +// Incremental cache + +export type S3CachedFile = + | { + type: "redirect"; + props?: Object; + meta?: Meta; + } + | { + type: "page"; + html: string; + json: Object; + meta?: Meta; + } + | { + type: "app"; + html: string; + rsc: string; + meta?: Meta; + } + | { + type: "route"; + body: string; + meta?: Meta; + }; + +export type S3FetchCache = Object; + +export type WithLastModified = { + lastModified?: number; + value?: T; +}; + +export type CacheValue = (IsFetch extends true + ? S3FetchCache + : S3CachedFile) & { revalidate?: number | false }; + +export type IncrementalCache = { + get( + key: string, + isFetch?: IsFetch, + ): Promise>>; + set( + key: string, + value: CacheValue, + isFetch?: IsFetch, + ): Promise; + delete(key: string): Promise; + name: string; +}; + +// Tag cache + +export type TagCache = { + getByTag(tag: string): Promise; + getByPath(path: string): Promise; + getLastModified(path: string, lastModified?: number): Promise; + writeTags( + tags: { tag: string; path: string; revalidatedAt?: number }[], + ): Promise; + name: string; +}; + +export type WrapperHandler< + E extends BaseEventOrResult = InternalEvent, + R extends BaseEventOrResult = InternalResult, +> = ( + handler: OpenNextHandler, + converter: Converter, +) => Promise<(...args: any[]) => any>; + +export type Wrapper< + E extends BaseEventOrResult = InternalEvent, + R extends BaseEventOrResult = InternalResult, +> = BaseOverride & { + wrapper: WrapperHandler; + supportStreaming: boolean; + edgeRuntime?: boolean; +}; + +export type OpenNextHandler< + E extends BaseEventOrResult = InternalEvent, + R extends BaseEventOrResult = InternalResult, +> = (event: E, responseStream?: StreamCreator) => Promise; + +export type Converter< + E extends BaseEventOrResult = InternalEvent, + R extends BaseEventOrResult = InternalResult, +> = BaseOverride & { + convertFrom: (event: any) => Promise; + convertTo: (result: R, originalRequest?: any) => Promise; +}; + +export type Warmer = BaseOverride & { + invoke: (warmerId: string) => Promise; +}; + +export type ImageLoader = BaseOverride & { + load: (url: string) => Promise<{ + body?: Readable; + contentType?: string; + cacheControl?: string; + }>; +}; + +export type OriginResolver = BaseOverride & { + resolve: (path: string) => Promise; +}; diff --git a/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts b/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts index 32600fb7..8dfd7346 100644 --- a/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts +++ b/packages/tests-unit/tests/core/routing/cacheInterceptor.test.ts @@ -1,8 +1,8 @@ /* eslint-disable sonarjs/no-duplicate-string */ import { cacheInterceptor } from "@opennextjs/aws/core/routing/cacheInterceptor.js"; import { convertFromQueryString } from "@opennextjs/aws/core/routing/util.js"; -import type { Queue } from "@opennextjs/aws/queue/types.js"; import type { InternalEvent } from "@opennextjs/aws/types/open-next.js"; +import type { Queue } from "@opennextjs/aws/types/overrides.js"; import { fromReadableStream } from "@opennextjs/aws/utils/stream.js"; import { vi } from "vitest";