Skip to content

Commit 09a41f3

Browse files
authored
Merge pull request #334 from tayloraswift/plugins-system
centralize plugin logging within `Unidoc.ServerLogger` implementation
2 parents 48b03c2 + 6fe0be0 commit 09a41f3

File tree

59 files changed

+1109
-882
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1109
-882
lines changed

Package.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "3ca1cc079c7ca5e3e9db0253fcca6ac1063c31ea5b3653bae0183ba85697f0d3",
2+
"originHash" : "14136142efb275ae01dcfeaf5849d265cd6cab460ea3b046c55ea7ccd4d3ab76",
33
"pins" : [
44
{
55
"identity" : "indexstore-db",

Package.swift

+7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ let package:Package = .init(
7676
.library(name: "UnidocClient", targets: ["UnidocClient"]),
7777
.library(name: "UnidocDB", targets: ["UnidocDB"]),
7878
.library(name: "UnidocLinker", targets: ["UnidocLinker"]),
79+
.library(name: "UnidocLinkerPlugin", targets: ["UnidocLinkerPlugin"]),
7980
.library(name: "UnidocQueries", targets: ["UnidocQueries"]),
8081
.library(name: "UnidocRecords", targets: ["UnidocRecords"]),
8182
.library(name: "UnidocServer", targets: ["UnidocServer"]),
@@ -133,6 +134,7 @@ let package:Package = .init(
133134
.target(name: "System_ArgumentParser"),
134135
.target(name: "UnidocClient"),
135136
.target(name: "UnidocServer"),
137+
.target(name: "UnidocLinkerPlugin"),
136138
]),
137139

138140
.executableTarget(name: "unidoc-publish",
@@ -507,6 +509,11 @@ let package:Package = .init(
507509
.target(name: "UnidocRecords"),
508510
]),
509511

512+
.target(name: "UnidocLinkerPlugin",
513+
dependencies: [
514+
.target(name: "UnidocServer"),
515+
]),
516+
510517
.target(name: "UnidocQueries",
511518
dependencies: [
512519
.target(name: "UnidocDB"),

Sources/GitHubClient/GitHub.Client.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ extension GitHub
3030
extension GitHub.Client<Void>
3131
{
3232
public static
33-
func graphql(
34-
threads:consuming MultiThreadedEventLoopGroup,
35-
niossl:consuming NIOSSLContext,
33+
func graphql(niossl:consuming NIOSSLContext,
34+
on threads:consuming MultiThreadedEventLoopGroup,
3635
as agent:String) -> GitHub.Client<Void>
3736
{
3837
.init(http2: .init(threads: threads, niossl: niossl, remote: "api.github.com"),
@@ -44,21 +43,21 @@ extension GitHub.Client where Application:GitHubApplication
4443
{
4544
public static
4645
func rest(app:consuming Application,
47-
threads:consuming MultiThreadedEventLoopGroup,
4846
niossl:consuming NIOSSLContext,
47+
on threads:consuming MultiThreadedEventLoopGroup,
4948
as agent:String) -> GitHub.Client<Application>
5049
{
5150
.init(http2: .init(threads: threads, niossl: niossl, remote: "api.github.com"),
5251
agent: agent,
5352
app: app)
5453
}
5554

56-
/// This is almost the same as ``rest(app:threads:niossl:as:)``, but it is bound to
55+
/// This is almost the same as ``rest(app:niossl:on:as:)``, but it is bound to
5756
/// the `github.com` apex domain, which is used for initial authentication.
5857
public static
5958
func auth(app:consuming Application,
60-
threads:consuming MultiThreadedEventLoopGroup,
6159
niossl:consuming NIOSSLContext,
60+
on threads:consuming MultiThreadedEventLoopGroup,
6261
as agent:String) -> GitHub.Client<Application>
6362
{
6463
.init(http2: .init(threads: threads, niossl: niossl, remote: "github.com"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
extension Unidoc
2+
{
3+
@frozen public
4+
enum LinkerRoute:String
5+
{
6+
case uplink
7+
case unlink
8+
case delete
9+
}
10+
}
11+
extension Unidoc.LinkerRoute:CustomStringConvertible
12+
{
13+
@inlinable public
14+
var description:String { self.rawValue }
15+
}
16+
extension Unidoc.LinkerRoute:LosslessStringConvertible
17+
{
18+
@inlinable public
19+
init?(_ description:String) { self.init(rawValue: description) }
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Unidoc
2+
import S3
3+
import S3Client
4+
5+
extension Unidoc.DB
6+
{
7+
func uplink(_ edition:Unidoc.Edition,
8+
from s3:AWS.S3.Client?) async throws -> Unidoc.UplinkStatus?
9+
{
10+
guard
11+
let s3:AWS.S3.Client
12+
else
13+
{
14+
return try await self.uplink(edition,
15+
loader: nil as AWS.S3.GraphLoader?)
16+
}
17+
18+
return try await s3.connect
19+
{
20+
try await self.uplink(edition,
21+
loader: AWS.S3.GraphLoader.init(s3: $0))
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import FNV1
2+
import HTML
3+
import UnidocAPI
4+
import UnidocServer
5+
6+
extension Unidoc.GraphLinker
7+
{
8+
@frozen public
9+
enum Event:Sendable
10+
{
11+
case uplinked(Unidoc.UplinkStatus)
12+
case unlinked(Unidoc.UnlinkStatus)
13+
case deleted(Unidoc.DeleteStatus)
14+
case failed(Unidoc.Edition, action:Unidoc.LinkerAction)
15+
}
16+
}
17+
extension Unidoc.GraphLinker.Event:Unidoc.PluginEvent
18+
{
19+
public
20+
func h3(_ h3:inout HTML.ContentEncoder)
21+
{
22+
switch self
23+
{
24+
case .uplinked: h3 += "Volume uplinked"
25+
case .unlinked: h3 += "Volume unlinked"
26+
case .deleted: h3 += "Volume deleted"
27+
case .failed: h3 += "Action failed"
28+
}
29+
}
30+
31+
public
32+
func dl(_ dl:inout HTML.ContentEncoder)
33+
{
34+
switch self
35+
{
36+
case .uplinked(let uplinked):
37+
dl[.dt] = "Edition"
38+
dl[.dd] = "\(uplinked.edition)"
39+
40+
dl[.dt] = "Volume"
41+
dl[.dd] = "\(uplinked.volume)"
42+
43+
dl[.dt] = "Hidden?"
44+
dl[.dd] = uplinked.hidden ? "yes" : "no"
45+
46+
guard
47+
let delta:Unidoc.SurfaceDelta = uplinked.delta
48+
else
49+
{
50+
return
51+
}
52+
53+
dl[.dt] = "Delta"
54+
55+
let api:Unidoc.SitemapDelta?
56+
57+
switch delta
58+
{
59+
case .initial:
60+
dl[.dd] = "Initial"
61+
return
62+
63+
case .ignoredHistorical:
64+
dl[.dd] = "Ignored historical"
65+
return
66+
67+
case .ignoredPrivate:
68+
dl[.dd] = "Ignored private"
69+
return
70+
71+
case .ignoredRepeated(let delta):
72+
dl[.dd] = "Ignored repeated"
73+
api = delta
74+
75+
case .replaced(let delta):
76+
dl[.dd] = "Replaced"
77+
api = delta
78+
}
79+
80+
guard
81+
let api:Unidoc.SitemapDelta
82+
else
83+
{
84+
return
85+
}
86+
87+
for (list, name):([Unidoc.Shoot], String) in [
88+
(api.deletions, "Deletions"),
89+
(api.additions, "Additions")
90+
] where !list.isEmpty
91+
{
92+
dl[.dt] = name
93+
dl[.dd]
94+
{
95+
$0[.ol]
96+
{
97+
for shoot:Unidoc.Shoot in list
98+
{
99+
if let hash:FNV24 = shoot.hash
100+
{
101+
$0[.li] = "\(shoot.stem) [\(hash)]"
102+
}
103+
else
104+
{
105+
$0[.li] = "\(shoot.stem)"
106+
}
107+
}
108+
}
109+
}
110+
}
111+
112+
case .unlinked(let unlinked):
113+
switch unlinked
114+
{
115+
case .unlinked(let edition):
116+
dl[.dt] = "Unlinked"
117+
dl[.dd] = "\(edition)"
118+
119+
case .declined(let edition):
120+
dl[.dt] = "Declined"
121+
dl[.dd] = "\(edition)"
122+
}
123+
124+
case .deleted(let deleted):
125+
switch deleted
126+
{
127+
case .deleted(let edition, let fromS3):
128+
dl[.dt] = "Deleted"
129+
dl[.dd] = "\(edition)"
130+
131+
dl[.dt] = "From S3?"
132+
dl[.dd] = fromS3 ? "yes" : "no"
133+
134+
case .declined(let edition):
135+
dl[.dt] = "Declined"
136+
dl[.dd] = "\(edition)"
137+
}
138+
139+
case .failed(let edition, action: let action):
140+
dl[.dt] = "Edition"
141+
dl[.dd] = "\(edition)"
142+
143+
dl[.dt] = "Action"
144+
dl[.dd] = "\(action)"
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)