-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontent-assets.ts
73 lines (60 loc) · 2.19 KB
/
content-assets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import type { ContentCompressionTypes } from "../constants/compression.js";
import type { StoreEntry } from "../types/compute.js";
export type CompressedFileInfos<TData> = Partial<Record<ContentCompressionTypes, TData>>;
export type ContentFileInfo = {
hash: string, // same as hash of file
size: number,
};
// For runtime use e.g., testing
export type ContentFileInfoForBytes = ContentFileInfo & {
bytes: Uint8Array,
};
export type ContentFileInfoForString = ContentFileInfo & {
content: string,
};
// For static publishing
export type ContentFileInfoForStaticPublishing = ContentFileInfo & {
staticFilePath: string,
};
export type ContentFileInfoForWasmInline = ContentFileInfoForStaticPublishing;
export type ContentFileInfoForKVStore = ContentFileInfoForStaticPublishing & {
kvStoreKey: string,
};
export type ContentAssetMetadataMapEntryBase<TFileInfo> = {
assetKey: string,
contentType: string,
text: boolean,
lastModifiedTime: number, // as unix time
fileInfo: TFileInfo,
compressedFileInfos: CompressedFileInfos<TFileInfo>
};
export type ContentAssetMetadataMapEntryBytes = {
type: 'bytes',
} & ContentAssetMetadataMapEntryBase<ContentFileInfoForBytes>;
export type ContentAssetMetadataMapEntryString = {
type: 'string',
} & ContentAssetMetadataMapEntryBase<ContentFileInfoForString>;
export type ContentAssetMetadataMapEntryWasmInline = {
type: 'wasm-inline',
} & ContentAssetMetadataMapEntryBase<ContentFileInfoForWasmInline>;
export type ContentAssetMetadataMapEntryKVStore = {
type: 'kv-store',
} & ContentAssetMetadataMapEntryBase<ContentFileInfoForKVStore>;
export type ContentAssetMetadataMapEntry =
| ContentAssetMetadataMapEntryBytes
| ContentAssetMetadataMapEntryString
| ContentAssetMetadataMapEntryWasmInline
| ContentAssetMetadataMapEntryKVStore;
export type ContentAssetMetadataMap = {
[assetKey: string]: ContentAssetMetadataMapEntry,
};
export interface ContentAsset {
readonly type: string;
readonly isLocal: boolean;
readonly assetKey: string;
getMetadata(): ContentAssetMetadataMapEntry;
getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
getBytes(): Uint8Array;
getText(): string;
getJson<T = unknown>(): T;
}