From 4a0312af0494c2cf37fbf1da879a779d51642b35 Mon Sep 17 00:00:00 2001 From: bcoll Date: Fri, 21 Jul 2023 10:47:27 +0100 Subject: [PATCH] Remove import cycle in `src/plugins/r2` This probably wasn't a problem, but generally it's not great to have cyclic dependencies. For future reference, this was found with `npx madge --circular --extensions ts packages/miniflare/src`. --- packages/miniflare/src/plugins/r2/gateway.ts | 20 +------------------ packages/miniflare/src/plugins/r2/r2Object.ts | 19 +++++++++++++++++- packages/miniflare/src/plugins/r2/router.ts | 4 ++-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/miniflare/src/plugins/r2/gateway.ts b/packages/miniflare/src/plugins/r2/gateway.ts index e67da5caa..4f03fa21c 100644 --- a/packages/miniflare/src/plugins/r2/gateway.ts +++ b/packages/miniflare/src/plugins/r2/gateway.ts @@ -27,7 +27,7 @@ import { NoSuchUpload, PreconditionFailed, } from "./errors"; -import { R2Object, R2ObjectBody } from "./r2Object"; +import { R2Object, R2ObjectBody, R2Objects } from "./r2Object"; import { MultipartPartRow, MultipartUploadRow, @@ -111,24 +111,6 @@ class DigestingStream< } } -export interface R2Objects { - // An array of objects matching the list request. - objects: R2Object[]; - // If true, indicates there are more results to be retrieved for the current - // list request. - truncated: boolean; - // A token that can be passed to future list calls to resume listing from that - // point. - // Only present if truncated is true. - cursor?: string; - // If a delimiter has been specified, contains all prefixes between the - // specified prefix and the next occurrence of the delimiter. For example, if - // no prefix is provided and the delimiter is "/", "foo/bar/baz" would return - // "foo" as a delimited prefix. If "foo/" was passed as a prefix with the same - // structure and delimiter, "foo/bar" would be returned as a delimited prefix. - delimitedPrefixes: string[]; -} - const validate = new Validator(); function generateVersion() { diff --git a/packages/miniflare/src/plugins/r2/r2Object.ts b/packages/miniflare/src/plugins/r2/r2Object.ts index c29ec9c50..886dcd306 100644 --- a/packages/miniflare/src/plugins/r2/r2Object.ts +++ b/packages/miniflare/src/plugins/r2/r2Object.ts @@ -2,7 +2,6 @@ import { Blob } from "buffer"; import { ReadableStream, TransformStream } from "stream/web"; import type { R2StringChecksums } from "@cloudflare/workers-types/experimental"; import { HEX_REGEXP } from "../../shared"; -import { R2Objects } from "./gateway"; import { ObjectRow, R2HeadResponse, R2HttpFields, R2Range } from "./schemas"; export interface EncodedMetadata { @@ -101,3 +100,21 @@ export class R2ObjectBody extends R2Object { }; } } + +export interface R2Objects { + // An array of objects matching the list request. + objects: R2Object[]; + // If true, indicates there are more results to be retrieved for the current + // list request. + truncated: boolean; + // A token that can be passed to future list calls to resume listing from that + // point. + // Only present if truncated is true. + cursor?: string; + // If a delimiter has been specified, contains all prefixes between the + // specified prefix and the next occurrence of the delimiter. For example, if + // no prefix is provided and the delimiter is "/", "foo/bar/baz" would return + // "foo" as a delimited prefix. If "foo/" was passed as a prefix with the same + // structure and delimiter, "foo/bar" would be returned as a delimited prefix. + delimitedPrefixes: string[]; +} diff --git a/packages/miniflare/src/plugins/r2/router.ts b/packages/miniflare/src/plugins/r2/router.ts index b0d87ed89..ed6cbd2ab 100644 --- a/packages/miniflare/src/plugins/r2/router.ts +++ b/packages/miniflare/src/plugins/r2/router.ts @@ -10,8 +10,8 @@ import { decodePersist, } from "../shared"; import { InternalError, InvalidMetadata } from "./errors"; -import { R2Gateway, R2Objects } from "./gateway"; -import { EncodedMetadata, R2Object, R2ObjectBody } from "./r2Object"; +import { R2Gateway } from "./gateway"; +import { EncodedMetadata, R2Object, R2ObjectBody, R2Objects } from "./r2Object"; import { R2BindingRequestSchema } from "./schemas"; async function decodeMetadata(req: Request) {