Skip to content

Commit e35b8c1

Browse files
committed
Rename KVAssets to Assets
1 parent 1bb9196 commit e35b8c1

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/cli/commands/manage/clean.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'node:path';
77

88
import { type OptionDefinition } from 'command-line-args';
99

10-
import { type KVAssetEntryMap } from '../../../models/assets/kvstore-assets.js';
10+
import { type AssetEntryMap } from '../../../models/assets/index.js';
1111
import { type IndexMetadata } from '../../../models/server/index.js';
1212
import { isExpired } from '../../../models/time/index.js';
1313
import { type FastlyApiContext, loadApiToken } from '../../util/api-token.js';
@@ -251,7 +251,7 @@ export async function action(actionArgs: string[]) {
251251
}
252252

253253
liveCollections.add(collection);
254-
const kvAssetsIndex = (await kvAssetsIndexResponse.response.json()) as KVAssetEntryMap;
254+
const kvAssetsIndex = (await kvAssetsIndexResponse.response.json()) as AssetEntryMap;
255255
for (const [_assetKey, assetEntry] of Object.entries(kvAssetsIndex)) {
256256
if (assetEntry.key.startsWith('sha256:')) {
257257
assetsIdsInUse.add(`sha256_${assetEntry.key.slice('sha256:'.length)}`);

src/cli/commands/manage/publish-content.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as path from 'node:path';
88

99
import { type OptionDefinition } from 'command-line-args';
1010

11-
import { type KVAssetEntryMap, type KVAssetVariantMetadata, isKVAssetVariantMetadata } from '../../../models/assets/kvstore-assets.js';
11+
import { type AssetEntryMap, type AssetVariantMetadata, isAssetVariantMetadata } from '../../../models/assets/index.js';
1212
import { type ContentCompressionTypes } from '../../../models/compression/index.js';
1313
import { type PublisherServerConfigNormalized } from '../../../models/config/publisher-server-config.js';
1414
import { type ContentTypeDef } from '../../../models/config/publish-content-config.js';
@@ -322,10 +322,10 @@ export async function action(actionArgs: string[]) {
322322
const kvStoreItemDescriptions: KVStoreItemDesc[] = [];
323323

324324
// Assets included in the publishing, keyed by asset key
325-
const kvAssetsIndex: KVAssetEntryMap = {};
325+
const kvAssetsIndex: AssetEntryMap = {};
326326

327327
// All the metadata of the variants we know about during this publishing, keyed on the base version's hash.
328-
type VariantMetadataEntry = KVAssetVariantMetadata & {
328+
type VariantMetadataEntry = AssetVariantMetadata & {
329329
existsInKvStore: boolean,
330330
};
331331
type VariantMetadataMap = Map<Variants, VariantMetadataEntry>;
@@ -406,7 +406,7 @@ export async function action(actionArgs: string[]) {
406406

407407
} else {
408408

409-
let kvStoreItemMetadata: KVAssetVariantMetadata | null = null;
409+
let kvStoreItemMetadata: AssetVariantMetadata | null = null;
410410

411411
if (!localMode && !overwriteKvStoreItems) {
412412
const items = [{
@@ -430,7 +430,7 @@ export async function action(actionArgs: string[]) {
430430
// treat it as though it didn't exist.
431431
}
432432
}
433-
if (isKVAssetVariantMetadata(itemMetadata)) {
433+
if (isAssetVariantMetadata(itemMetadata)) {
434434
let exists = false;
435435
if (itemMetadata.size <= KV_STORE_CHUNK_SIZE) {
436436
// For an item equal to or smaller than the chunk size, if it exists
@@ -461,7 +461,7 @@ export async function action(actionArgs: string[]) {
461461
);
462462
}
463463

464-
if ((kvStoreItemMetadata as KVAssetVariantMetadata | null) != null) {
464+
if ((kvStoreItemMetadata as AssetVariantMetadata | null) != null) {
465465

466466
console.log(` ・ Asset found in KV Store with key "${variantKey}".`);
467467
// And we already know its hash and size.

src/models/assets/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55

66
import { type ContentCompressionTypes, isCompressionType } from '../compression/index.js';
77

8-
export type KVAssetEntry = {
8+
export type AssetEntry = {
99
key: string,
1010
size: number,
1111
contentType: string,
1212
lastModifiedTime: number,
1313
variants: ContentCompressionTypes[],
1414
};
1515

16-
export type KVAssetEntryMap = Record<string, KVAssetEntry>;
16+
export type AssetEntryMap = Record<string, AssetEntry>;
1717

18-
export type KVAssetVariantMetadata = {
18+
export type AssetVariantMetadata = {
1919
contentEncoding?: ContentCompressionTypes,
2020
size: number,
2121
hash: string,
2222
numChunks?: number,
2323
};
2424

25-
export function isKVAssetVariantMetadata(obj: unknown): obj is KVAssetVariantMetadata {
25+
export function isAssetVariantMetadata(obj: unknown): obj is AssetVariantMetadata {
2626
if (obj == null || typeof obj !== 'object') {
2727
return false;
2828
}

src/server/publisher-server/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import {
1616
type ContentCompressionTypes,
1717
} from '../../models/compression/index.js';
1818
import {
19-
isKVAssetVariantMetadata,
20-
type KVAssetEntry,
21-
type KVAssetEntryMap,
22-
type KVAssetVariantMetadata,
23-
} from '../../models/assets/kvstore-assets.js';
19+
isAssetVariantMetadata,
20+
type AssetEntry,
21+
type AssetEntryMap,
22+
type AssetVariantMetadata,
23+
} from '../../models/assets/index.js';
2424
import { type IndexMetadata } from '../../models/server/index.js';
2525
import { isExpired } from '../../models/time/index.js';
2626
import { getKVStoreEntry } from '../util/kv-store.js';
@@ -29,7 +29,7 @@ import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if
2929

3030
type KVAssetVariant = {
3131
kvStoreEntry: KVStoreEntry,
32-
} & KVAssetVariantMetadata;
32+
} & AssetVariantMetadata;
3333

3434
export function buildHeadersSubset(responseHeaders: Headers, keys: Readonly<string[]>) {
3535
const resultHeaders = new Headers();
@@ -98,7 +98,7 @@ export class PublisherServer {
9898
settingsCached: PublisherServerConfigNormalized | null | undefined;
9999

100100
// Cached index
101-
kvAssetsIndex: KVAssetEntryMap | null | undefined;
101+
kvAssetsIndex: AssetEntryMap | null | undefined;
102102

103103
setActiveCollectionName(collectionName: string) {
104104
this.activeCollectionName = collectionName;
@@ -180,11 +180,11 @@ export class PublisherServer {
180180
return null;
181181
}
182182

183-
this.kvAssetsIndex = (await indexFile.json()) as KVAssetEntryMap;
183+
this.kvAssetsIndex = (await indexFile.json()) as AssetEntryMap;
184184
return this.kvAssetsIndex;
185185
}
186186

187-
async getMatchingAsset(assetKey: string, applyAuto: boolean = false): Promise<KVAssetEntry | null> {
187+
async getMatchingAsset(assetKey: string, applyAuto: boolean = false): Promise<AssetEntry | null> {
188188

189189
const serverConfig = await this.getServerConfig();
190190
if (serverConfig == null) {
@@ -309,7 +309,7 @@ export class PublisherServer {
309309
});
310310
}
311311

312-
handlePreconditions(request: Request, asset: KVAssetEntry, responseHeaders: Headers): Response | null {
312+
handlePreconditions(request: Request, asset: AssetEntry, responseHeaders: Headers): Response | null {
313313
// Handle preconditions according to https://httpwg.org/specs/rfc9110.html#rfc.section.13.2.2
314314

315315
// A recipient cache or origin server MUST evaluate the request preconditions defined by this specification in the following order:
@@ -370,7 +370,7 @@ export class PublisherServer {
370370
return null;
371371
}
372372

373-
public async loadKvAssetVariant(entry: KVAssetEntry, variant: ContentCompressionTypes | null): Promise<KVAssetVariant | null> {
373+
public async loadKvAssetVariant(entry: AssetEntry, variant: ContentCompressionTypes | null): Promise<KVAssetVariant | null> {
374374

375375
const kvStore = new KVStore(this.kvStoreName);
376376

@@ -392,7 +392,7 @@ export class PublisherServer {
392392
} catch {
393393
return null;
394394
}
395-
if (!isKVAssetVariantMetadata(metadata)) {
395+
if (!isAssetVariantMetadata(metadata)) {
396396
return null;
397397
}
398398
if (metadata.size == null) {
@@ -404,7 +404,7 @@ export class PublisherServer {
404404
};
405405
}
406406

407-
private async findKVAssetVariantForAcceptEncodingsGroups(entry: KVAssetEntry, acceptEncodingsGroups: ContentCompressionTypes[][] = []): Promise<KVAssetVariant> {
407+
private async findKVAssetVariantForAcceptEncodingsGroups(entry: AssetEntry, acceptEncodingsGroups: ContentCompressionTypes[][] = []): Promise<KVAssetVariant> {
408408

409409
if (!entry.key.startsWith('sha256:')) {
410410
throw new TypeError(`Key must start with 'sha256:': ${entry.key}`);
@@ -445,7 +445,7 @@ export class PublisherServer {
445445
return baseKvStoreEntry;
446446
}
447447

448-
async serveAsset(request: Request, asset: KVAssetEntry, init?: AssetInit): Promise<Response> {
448+
async serveAsset(request: Request, asset: AssetEntry, init?: AssetInit): Promise<Response> {
449449

450450
const headers = new Headers(init?.headers);
451451
headers.set('Content-Type', asset.contentType);

0 commit comments

Comments
 (0)