-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
uv.d.ts
113 lines (107 loc) · 3.81 KB
/
uv.d.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const Ultraviolet: typeof import("./src/rewrite/index").default;
const UVClient: typeof import("./src/client/index").default;
export type UltravioletCtor = typeof Ultraviolet;
export type UVClientCtor = typeof UVClient;
/**
* The proxy part of the URL.
*/
type Coded = string;
/**
* The URL encoder.
* Encoders will have to encode the result using encodeURLComponent.
*/
export type UVEncode = (input: Coded) => string;
/**
* The URL encoder.
* Decoders will have to decode the input first using decodeURLComponent.
*/
export type UVDecode = (input: Coded) => string;
export type UVInject = {
/**
* The host(s) to inject the HTML on.
* This is a regex that's tested against the proxied URL's host.
*/
host: RegExp;
/**
* Where to inject the HTML
* Possible values: `"head" | "body"`
*/
injectTo: "head" | "body";
/**
* The HTML to inject.
*/
html: string;
};
/**
* The Ultraviolet configuration object.
* This interface defines the configuration options for the Ultraviolet library.
*/
export interface UVConfig {
/**
* The prefix for Ultraviolet to listen on.
* This prefix will be used to create the URL for the service worker and the client script.
* @example `https://example.org/uv/service/`
* @example `/uv/service/`
* @defaultValue `/service/`
*/
prefix?: string;
/**
* The path to the Ultraviolet client script.
* This script will be loaded by the browser and is responsible for communicating with the service worker.
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
* @example `/uv/uv.client.js`,
* @defaultValue `/uv.client.js` or if bundle is specified and the filename is `uv.bundle.js`, the directory of the bundle + `uv.client.js` will be used automatically
*/
client?: string;
/**
* The path to the Ultraviolet service worker script.
* This script will be registered as a service worker and is responsible for handling network requests.
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
* @example `/uv/uv.sw.js`,
* @defaultValue `/uv.sw.js`
*/
handler?: string;
/**
* The path to the bundled script that contains both the Ultraviolet client and service worker scripts.
* This path is optional and can be used instead of the `client` and `handler` paths to load a single bundled script.
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
* @example `/uv/uv.bundle.js`,
* @defaultValue `/uv.bundle.js`
*/
bundle?: string;
/**
* The path to the Ultraviolet configuration script.
* This script should export a configuration object that will be used to configure the client and service worker.
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
* @example `/uv/uv.config.js`,
* @defaultValue `/uv.config.js`
*/
config?: string;
/**
* The path to the Ultraviolet service worker script.
* This path is optional and can be used instead of the `handler` path to specify a custom service worker script.
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
* @example `/uv/uv.sw.js`,
* @defaultValue `/uv.sw.js`
*/
sw?: string;
/**
* The URL encoder.
* This function will be used to encode URLs before they are sent to the server.
* The encoder should use `encodeURIComponent` to encode the URLs.
* @defaultValue `Ultraviolet.codec.xor.encode`
*/
encodeUrl?: UVEncode;
/**
* The URL decoder.
* This function will be used to decode URLs after they are received from the server.
* The decoder should use `decodeURIComponent` to decode the URLs.
* @defaultValue `Ultraviolet.codec.xor.decode`
*/
decodeUrl?: UVDecode;
/**
* HTML inject settings.
* This property expects an array of `UVInject`.
*/
inject?: UVInject[];
}