-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
96 lines (90 loc) · 2.9 KB
/
app.ts
File metadata and controls
96 lines (90 loc) · 2.9 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { defineStore } from "@david/service-store";
import {
LruTestResultArtifactStore,
RealTestResultsDownloader,
type TestResultArtifactStore,
type TestResultsDownloader,
} from "./lib/test-results-downloader.ts";
import { RealRunsFetcher, type RunsFetcher } from "./lib/runs-fetcher.ts";
import {
type GitHubApiClient,
RealGitHubApiClient,
} from "./lib/github-api-client.ts";
import { ConfigProvider } from "./lib/config.ts";
import { LoggerFactory } from "./lib/logger.ts";
import { InsightsPageController } from "./routes/insights.tsx";
import { HomePageController } from "./routes/index.tsx";
import { RunPageController } from "./routes/results/[runId].tsx";
import { type FileFetcher, RealFileFetcher } from "./lib/file-fetcher.ts";
import {
type ArtifactParser,
ZipArtifactParser,
} from "./lib/artifact-parser.ts";
import { App, staticFiles } from "fresh";
export interface AppState {
store: AppStore;
}
export type AppStore = ReturnType<typeof createRequestStore>;
// services that live for the duration of the application
const appStore = defineStore()
.add("config", () => new ConfigProvider())
.add("loggerFactory", () => new LoggerFactory())
.add("artifactParser", (): ArtifactParser => {
return new ZipArtifactParser();
})
.add("testResultArtifactStore", (): TestResultArtifactStore => {
return new LruTestResultArtifactStore();
})
.add("fileFetcher", (): FileFetcher => {
return new RealFileFetcher();
})
.add("githubClient", (store): GitHubApiClient => {
return new RealGitHubApiClient(
store.get("fileFetcher"),
store.get("config").githubToken,
);
})
.add("testResultsDownloader", (store): TestResultsDownloader => {
return new RealTestResultsDownloader(
store.get("artifactParser"),
store.get("githubClient"),
store.get("testResultArtifactStore"),
);
})
.finalize();
function createRequestStore() {
// services that live for the duration of a request
return appStore.createChild()
.add("logger", (store) => {
return store.get("loggerFactory").getRequestLogger();
})
.add("runsFetcher", (store): RunsFetcher => {
return new RealRunsFetcher(store.get("githubClient"));
})
.add("controller.homePage", (store) => {
return new HomePageController(store.get("runsFetcher"));
})
.add("controller.insights", (store) => {
return new InsightsPageController(
store.get("logger"),
store.get("githubClient"),
store.get("testResultsDownloader"),
);
})
.add("controller.runPage", (store) => {
return new RunPageController(
store.get("githubClient"),
store.get("testResultsDownloader"),
);
})
.finalize();
}
export const app = new App<AppState>();
app
.use(staticFiles())
.use(async (ctx) => {
using scopedStore = createRequestStore();
ctx.state.store = scopedStore;
return await ctx.next();
})
.fsRoutes();