Skip to content

Commit

Permalink
Remove import cycle in src/plugins/r2
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
mrbbot committed Jul 21, 2023
1 parent 76bd32e commit 4a0312a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
20 changes: 1 addition & 19 deletions packages/miniflare/src/plugins/r2/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
NoSuchUpload,
PreconditionFailed,
} from "./errors";
import { R2Object, R2ObjectBody } from "./r2Object";
import { R2Object, R2ObjectBody, R2Objects } from "./r2Object";
import {
MultipartPartRow,
MultipartUploadRow,
Expand Down Expand Up @@ -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() {
Expand Down
19 changes: 18 additions & 1 deletion packages/miniflare/src/plugins/r2/r2Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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[];
}
4 changes: 2 additions & 2 deletions packages/miniflare/src/plugins/r2/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4a0312a

Please sign in to comment.