-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathindex.ts
More file actions
73 lines (67 loc) · 1.57 KB
/
index.ts
File metadata and controls
73 lines (67 loc) · 1.57 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
import { z } from "zod";
import { Worker_Binding } from "../../runtime";
import {
getUserBindingServiceName,
Plugin,
ProxyNodeBinding,
remoteProxyClientWorker,
RemoteProxyConnectionString,
} from "../shared";
const FlagshipSchema = z.object({
app_id: z.string(),
remoteProxyConnectionString: z
.custom<RemoteProxyConnectionString>()
.optional(),
});
export const FlagshipOptionsSchema = z.object({
flagship: z.record(FlagshipSchema).optional(),
});
export const FLAGSHIP_PLUGIN_NAME = "flagship";
export const FLAGSHIP_PLUGIN: Plugin<typeof FlagshipOptionsSchema> = {
options: FlagshipOptionsSchema,
async getBindings(options) {
if (!options.flagship) {
return [];
}
return Object.entries(options.flagship).map<Worker_Binding>(
([name, config]) => ({
name,
service: {
name: getUserBindingServiceName(
FLAGSHIP_PLUGIN_NAME,
name,
config.remoteProxyConnectionString
),
},
})
);
},
getNodeBindings(options: z.infer<typeof FlagshipOptionsSchema>) {
if (!options.flagship) {
return {};
}
return Object.fromEntries(
Object.keys(options.flagship).map((name) => [
name,
new ProxyNodeBinding(),
])
);
},
async getServices({ options }) {
if (!options.flagship) {
return [];
}
return Object.entries(options.flagship).map(
([name, { remoteProxyConnectionString }]) => {
return {
name: getUserBindingServiceName(
FLAGSHIP_PLUGIN_NAME,
name,
remoteProxyConnectionString
),
worker: remoteProxyClientWorker(remoteProxyConnectionString, name),
};
}
);
},
};