Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 7929587

Browse files
committedMay 15, 2023
Rename NewStorage to Storage
...and `storage2` to `storage`

20 files changed

+32
-36
lines changed
 

‎packages/tre/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import {
6969
defaultTimers,
7070
formatResponse,
7171
} from "./shared";
72-
import { NewStorage } from "./storage2";
72+
import { Storage } from "./storage";
7373
import { CoreHeaders } from "./workers";
7474

7575
// ===== `Miniflare` User Options =====
@@ -884,7 +884,7 @@ export class Miniflare {
884884
plugin: keyof Plugins,
885885
namespace: string,
886886
persist?: Persistence
887-
): NewStorage {
887+
): Storage {
888888
const factory = this.#gatewayFactories[plugin];
889889
assert(factory !== undefined);
890890
return factory.getStorage(namespace, persist);
@@ -912,5 +912,5 @@ export * from "./http";
912912
export * from "./plugins";
913913
export * from "./runtime";
914914
export * from "./shared";
915-
export * from "./storage2";
915+
export * from "./storage";
916916
export * from "./workers";

‎packages/tre/src/plugins/cache/gateway.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
InclusiveRange,
1010
KeyValueStorage,
1111
MultipartReadableStream,
12-
NewStorage,
13-
} from "../../storage2";
12+
Storage,
13+
} from "../../storage";
1414
import { isSitesRequest } from "../kv";
1515
import { _parseRanges } from "../shared";
1616
import {
@@ -232,7 +232,7 @@ export class CacheGateway {
232232

233233
constructor(
234234
private readonly log: Log,
235-
storage: NewStorage,
235+
storage: Storage,
236236
private readonly timers: Timers
237237
) {
238238
this.storage = new KeyValueStorage(storage, timers);

‎packages/tre/src/plugins/d1/gateway.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Database as DatabaseType } from "better-sqlite3";
77
import { z } from "zod";
88
import { Response } from "../../http";
99
import { HttpError, Log } from "../../shared";
10-
import { NewStorage } from "../../storage2";
10+
import { Storage } from "../../storage";
1111
import splitSqlQuery from "./splitter";
1212

1313
export const D1ValueSchema = z.union([
@@ -153,7 +153,7 @@ interface ChangesLastRowResult {
153153
export class D1Gateway {
154154
private readonly db: DatabaseType;
155155

156-
constructor(private readonly log: Log, storage: NewStorage) {
156+
constructor(private readonly log: Log, storage: Storage) {
157157
this.db = storage.db;
158158
}
159159

‎packages/tre/src/plugins/kv/gateway.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
millisToSeconds,
88
secondsToMillis,
99
} from "../../shared";
10-
import { KeyValueStorage, NewStorage } from "../../storage2";
10+
import { KeyValueStorage, Storage } from "../../storage";
1111
import {
1212
MAX_KEY_SIZE,
1313
MAX_LIST_KEYS,
@@ -157,7 +157,7 @@ export class KVGateway {
157157

158158
constructor(
159159
private readonly log: Log,
160-
storage: NewStorage,
160+
storage: Storage,
161161
private readonly timers: Timers
162162
) {
163163
this.storage = new KeyValueStorage(storage, timers);

‎packages/tre/src/plugins/kv/sites.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
serialiseRegExps,
1414
testRegExps,
1515
} from "../../shared";
16-
import { createFileReadableStream } from "../../storage2";
16+
import { createFileReadableStream } from "../../storage";
1717
import { CoreBindings } from "../../workers";
1818
import {
1919
BINDING_TEXT_PERSIST,

‎packages/tre/src/plugins/queues/gateway.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { stringify } from "devalue";
77
import { Colorize, bold, green, grey, red, reset, yellow } from "kleur/colors";
88
import { z } from "zod";
99
import { Log, Timers } from "../../shared";
10-
import { NewStorage } from "../../storage2";
10+
import { Storage } from "../../storage";
1111
import { CoreHeaders, structuredSerializableReducers } from "../../workers";
1212
import { DispatchFetch, QueueConsumer } from "../shared";
1313

@@ -99,7 +99,7 @@ export class QueuesGateway {
9999

100100
constructor(
101101
private readonly log: Log,
102-
_storage: NewStorage,
102+
_storage: Storage,
103103
private readonly timers: Timers,
104104
private readonly queueName: string,
105105
private readonly dispatchFetch: DispatchFetch

‎packages/tre/src/plugins/r2/gateway.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import {
1414
import {
1515
BlobId,
1616
InclusiveRange,
17-
NewStorage,
17+
Storage,
1818
TypedDatabase,
1919
escapeLike,
20-
} from "../../storage2";
20+
} from "../../storage";
2121
import {
2222
BadUpload,
2323
EntityTooSmall,
@@ -443,6 +443,7 @@ function sqlStmts(db: TypedDatabase) {
443443
parts.sort((a, b) => a.part_number - b.part_number);
444444
let partSize: number | undefined;
445445
for (const part of parts.slice(0, -1)) {
446+
// noinspection JSUnusedAssignment
446447
partSize ??= part.size;
447448
if (
448449
part.size < R2Gateway._MIN_MULTIPART_PART_SIZE ||
@@ -541,7 +542,7 @@ export class R2Gateway {
541542
/** @internal */
542543
static _MIN_MULTIPART_PART_SIZE = 5 * 1024 * 1024;
543544

544-
readonly #storage: NewStorage;
545+
readonly #storage: Storage;
545546
readonly #stmts: ReturnType<typeof sqlStmts>;
546547

547548
// Multipart uploads are stored as multiple blobs. Therefore, when reading a
@@ -568,7 +569,7 @@ export class R2Gateway {
568569

569570
constructor(
570571
private readonly log: Log,
571-
storage: NewStorage,
572+
storage: Storage,
572573
private readonly timers: Timers
573574
) {
574575
this.#storage = storage;
@@ -605,7 +606,7 @@ export class R2Gateway {
605606
}
606607

607608
#assembleMultipartValue(
608-
storage: NewStorage,
609+
storage: Storage,
609610
parts: Pick<MultipartPartRow, "blob_id" | "size">[],
610611
queryRange: InclusiveRange
611612
): ReadableStream<Uint8Array> {

‎packages/tre/src/plugins/r2/validator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22
import type { R2StringChecksums } from "@cloudflare/workers-types/experimental";
3-
import { InclusiveRange } from "../../storage2";
3+
import { InclusiveRange } from "../../storage";
44
import { _parseRanges } from "../shared";
55
import {
66
BadDigest,

‎packages/tre/src/plugins/shared/gateway.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import {
1010
Timers,
1111
sanitisePath,
1212
} from "../../shared";
13-
import {
14-
NewStorage,
15-
createFileStorage,
16-
createMemoryStorage,
17-
} from "../../storage2";
13+
import { Storage, createFileStorage, createMemoryStorage } from "../../storage";
1814

1915
// TODO: explain why persist passed as header, want options set to be atomic,
2016
// if set gateway before script update, may be using new persist before new script
@@ -40,7 +36,7 @@ export type CloudflareFetch = z.infer<typeof CloudflareFetchSchema>;
4036
export interface GatewayConstructor<Gateway> {
4137
new (
4238
log: Log,
43-
storage: NewStorage,
39+
storage: Storage,
4440
timers: Timers,
4541
namespace: string,
4642
dispatchFetch: DispatchFetch
@@ -59,7 +55,7 @@ export function maybeParseURL(url: Persistence): URL | undefined {
5955
}
6056

6157
export class GatewayFactory<Gateway> {
62-
readonly #memoryStorages = new Map<string, NewStorage>();
58+
readonly #memoryStorages = new Map<string, Storage>();
6359
readonly #gateways = new Map<string, [Persistence, Gateway]>();
6460

6561
constructor(
@@ -77,7 +73,7 @@ export class GatewayFactory<Gateway> {
7773
return storage;
7874
}
7975

80-
getStorage(namespace: string, persist: Persistence): NewStorage {
76+
getStorage(namespace: string, persist: Persistence): Storage {
8177
// If persistence is disabled, use memory storage
8278
if (persist === undefined || persist === false) {
8379
return this.#getMemoryStorage(namespace);

‎packages/tre/src/plugins/shared/range.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InclusiveRange } from "../../storage2";
1+
import { InclusiveRange } from "../../storage";
22

33
// Matches case-insensitive string "bytes", ignoring surrounding whitespace,
44
// followed by "=" (example matches: "bytes=...", "ByTeS=...", " bytes =...")
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎packages/tre/src/storage2/keyvalue.ts ‎packages/tre/src/storage/keyvalue.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
MultipartReadableStream,
1414
} from "./blob";
1515
import { TypedDatabase } from "./sql";
16-
import { NewStorage } from "./storage";
16+
import { Storage } from "./storage";
1717

1818
export interface KeyEntry<Metadata = unknown> {
1919
key: string;
@@ -121,7 +121,7 @@ export class KeyValueStorage<Metadata = unknown> {
121121
readonly #stmts: ReturnType<typeof sqlStmts>;
122122

123123
constructor(
124-
private readonly storage: NewStorage,
124+
private readonly storage: Storage,
125125
private readonly timers: Timers = defaultTimers
126126
) {
127127
storage.db.pragma("case_sensitive_like = TRUE");
File renamed without changes.

‎packages/tre/src/storage2/storage.ts ‎packages/tre/src/storage/storage.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import Database from "better-sqlite3";
44
import { BlobStore, FileBlobStore, MemoryBlobStore } from "./blob";
55
import { TypedDatabase } from "./sql";
66

7-
// TODO: rename to `Storage` and move to `src/storage` once all gateways migrated
8-
export interface NewStorage {
7+
export interface Storage {
98
db: TypedDatabase;
109
blob: BlobStore;
1110
}
1211

13-
export function createMemoryStorage(): NewStorage {
12+
export function createMemoryStorage(): Storage {
1413
const db = new Database(":memory:") as TypedDatabase;
1514
const blob = new MemoryBlobStore();
1615
return { db, blob };
1716
}
1817

19-
export function createFileStorage(root: string): NewStorage {
18+
export function createFileStorage(root: string): Storage {
2019
root = path.resolve(root);
2120
fs.mkdirSync(root, { recursive: true });
2221
const db = new Database(path.join(root, "db.sqlite")) as TypedDatabase;

‎packages/tre/test/plugins/r2/index.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ import {
3333
Miniflare,
3434
MiniflareOptions,
3535
MultipartPartRow,
36-
NewStorage,
3736
ObjectRow,
3837
R2Gateway,
3938
Response,
39+
Storage,
4040
TypedDatabase,
4141
createFileStorage,
4242
viewToArray,
@@ -387,7 +387,7 @@ class TestR2MultipartUpload implements R2MultipartUpload {
387387
interface Context extends MiniflareTestContext {
388388
ns: string;
389389
r2: TestR2Bucket;
390-
storage: NewStorage;
390+
storage: Storage;
391391
}
392392

393393
const opts: Partial<MiniflareOptions> = {

0 commit comments

Comments
 (0)
This repository has been archived.