add typedefs for uv config

This commit is contained in:
David Reed 2022-12-03 15:53:18 -05:00
parent 6ce344c267
commit 67fd1bce6a
No known key found for this signature in database
GPG key ID: 2211691D8A1EE72F
4 changed files with 99 additions and 1 deletions

1
src/global.d.ts vendored Normal file
View file

@ -0,0 +1 @@
declare const __uv$config: import('./uv').UVConfig;

View file

@ -37,7 +37,15 @@ import { openDB } from 'idb';
import BareClient from '@tomphttp/bare-client';
import EventEmitter from 'events';
/**
* @typedef {import('../uv.js').UVConfig} UVConfig
*/
class Ultraviolet {
/**
*
* @param {UVConfig} [options]
*/
constructor(options = {}) {
this.prefix = options.prefix || '/service/';
//this.urlRegex = /^(#|about:|data:|mailto:|javascript:)/;

View file

@ -1,7 +1,7 @@
/*global Ultraviolet*/
self.__uv$config = {
prefix: '/service/',
bare: 'https://uv.holyubofficial.net/',
bare: '/bare/',
encodeUrl: Ultraviolet.codec.xor.encode,
decodeUrl: Ultraviolet.codec.xor.decode,
handler: '/uv.handler.js',

89
src/uv.d.ts vendored
View file

@ -3,3 +3,92 @@ const UVClient: typeof import('./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;
/**
* The Ultraviolet configuration object.
*/
export interface UVConfig {
/**
* The Bare server(s) to use.
* If an array is specified, the service worker will randomly select a server to use.
* The selected server will be used for the duration of the session.
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL.
* @example // A Bare server running on the subdomain `bare.`, automatically correcting the apex record:
* `${location.protocol}//bare.${location.host.replace(/^www\./, "")}
* @example `http://localhost:8080/`
* @example `http://localhost:8080/bare/`
* @defaultValue `/bare/`
* @see {@link|https://github.com/tomphttp/specifications/blob/master/BareServer.md}
*/
bare?: string | string[];
/**
* The prefix for Ultraviolet to listen on.
* @example `https://example.org/uv/service/`
* @example `/uv/service/`
* @defaultValue `/service/`
*/
prefix?: string;
/**
* The path to the Ultraviolet client script.
* 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.
* 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 Ultraviolet 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`
*/
bundle?: string;
/**
* The path to the Ultraviolet service worker script.
* 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.
* 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.
* @defaultValue `Ultraviolet.codec.xor.encode`
*/
encodeUrl?: UVEncode;
/**
* The URL decoder.
* @defaultValue `Ultraviolet.codec.xor.encode`
*
*/
decodeUrl?: UVDecode;
}