-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
53 lines (49 loc) · 1.53 KB
/
index.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
import { Cache, ILogger } from "@zkchainhub/shared";
import {
GithubMetadataProvider,
IMetadataProvider,
LocalFileMetadataProvider,
MetadataConfig,
MetadataSource,
StaticMetadataProvider,
} from "../internal.js";
export class MetadataProviderFactory {
static create(
metadata: MetadataConfig<MetadataSource>,
deps?: {
logger?: ILogger;
cache?: Cache;
},
): IMetadataProvider {
let metadataProvider: IMetadataProvider;
switch (metadata.source) {
case "github":
if (!deps?.cache || !deps?.logger) {
throw new Error("Missing dependencies");
}
metadataProvider = new GithubMetadataProvider(
metadata.tokenUrl,
metadata.chainUrl,
deps.logger,
deps.cache,
);
break;
case "local":
if (!deps?.logger) {
throw new Error("Missing dependencies");
}
metadataProvider = new LocalFileMetadataProvider(
metadata.tokenJsonPath,
metadata.chainJsonPath,
deps.logger,
);
break;
case "static":
metadataProvider = new StaticMetadataProvider();
break;
default:
throw new Error("Invalid metadata source");
}
return metadataProvider;
}
}