vitral 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular.d.ts +2 -2
- package/dist/angular.js +7 -7
- package/dist/auto.js +7 -7
- package/dist/{capture-JYFERAPL.js → capture-TT5WBLJ6.js} +1 -1
- package/dist/channel-2YPYGX3J.js +95 -0
- package/dist/{chunk-AKNNHQ2H.js → chunk-463H6B56.js} +5 -0
- package/dist/{chunk-IHTUM6LT.js → chunk-4Z77XNBR.js} +2 -2
- package/dist/chunk-54CBIZES.js +105 -0
- package/dist/{chunk-TD4S3IHA.js → chunk-5JNV45BB.js} +10 -8
- package/dist/{chunk-SDB5AZEI.js → chunk-C3QOBAUE.js} +2 -2
- package/dist/chunk-DAESKNQ6.js +207 -0
- package/dist/{chunk-3YXI3G34.js → chunk-K6EG7DMO.js} +16 -7
- package/dist/{chunk-ZAC6QQI6.js → chunk-KU6HF2EW.js} +4 -4
- package/dist/{chunk-I3VSKSAZ.js → chunk-KZBH5MPD.js} +29 -27
- package/dist/chunk-NZEQGRBL.js +93 -0
- package/dist/chunk-PY7P5BF4.js +404 -0
- package/dist/{chunk-GNHCZRQP.js → chunk-TW7KYJQ6.js} +1 -1
- package/dist/{chunk-AH7KNMBW.js → chunk-UYOPJ4XQ.js} +1 -1
- package/dist/cli.js +1522 -37
- package/dist/devtools.d.ts +32 -2
- package/dist/devtools.js +27 -12
- package/dist/dict.d.ts +69 -0
- package/dist/dict.js +8 -0
- package/dist/edge.d.ts +118 -0
- package/dist/edge.js +398 -0
- package/dist/element.d.ts +12 -3
- package/dist/element.js +7 -7
- package/dist/embed.js +2 -0
- package/dist/{events-D5gs7rff.d.ts → events-0rxFlWJJ.d.ts} +1 -1
- package/dist/expose-IAKYHJXF.js +15 -0
- package/dist/federation.d.ts +89 -0
- package/dist/federation.js +101 -0
- package/dist/hydrate-YVZDJ2V7.js +168 -0
- package/dist/iframe.js +7 -7
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/otel.d.ts +29 -1
- package/dist/otel.js +13 -1
- package/dist/overrides-NP754HY7.js +27 -0
- package/dist/preact.d.ts +4 -4
- package/dist/preact.js +6 -6
- package/dist/prefetch.d.ts +25 -0
- package/dist/prefetch.js +178 -0
- package/dist/react.d.ts +3 -3
- package/dist/react.js +6 -6
- package/dist/reframe-LQL4DZYP.js +251 -0
- package/dist/routes.d.ts +2 -2
- package/dist/routes.js +5 -5
- package/dist/{shadow-6HELCHCJ.js → shadow-S4SKHTA7.js} +66 -5
- package/dist/single-spa.d.ts +40 -0
- package/dist/single-spa.js +52 -0
- package/dist/{slot-DqXTwGbs.d.ts → slot-D49L1rdU.d.ts} +1 -1
- package/dist/solid.d.ts +3 -3
- package/dist/solid.js +6 -6
- package/dist/{sri-JMX6JLQP.js → sri-576GTDIA.js} +41 -10
- package/dist/svelte.d.ts +4 -4
- package/dist/svelte.js +6 -6
- package/dist/testing.d.ts +171 -3
- package/dist/testing.js +193 -6
- package/dist/{types-Czvm-siZ.d.ts → types-DUtcF3HO.d.ts} +124 -5
- package/dist/vitals.d.ts +29 -0
- package/dist/vitals.js +152 -0
- package/dist/vite.d.ts +18 -0
- package/dist/vite.js +329 -417
- package/dist/vue.d.ts +3 -3
- package/dist/vue.js +6 -6
- package/package.json +170 -21
- package/dist/chunk-DXORSF4X.js +0 -42
- package/dist/expose-JUOUN5N5.js +0 -15
- package/dist/overrides-NZAIUGK5.js +0 -15
package/dist/devtools.d.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
|
+
/** Remove todos os overrides: os da aba e os do navegador. */
|
|
2
|
+
declare function clearOverrides(): void;
|
|
3
|
+
/** Override ativo. `url` fica vazia quando um apelido não tem modelo para resolver. */
|
|
4
|
+
interface ActiveOverride {
|
|
5
|
+
name: string;
|
|
6
|
+
/** Como foi pedido: URL ou apelido (`pr-123`). */
|
|
7
|
+
value: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
/** `'aba'`: veio de `?vitral=` nesta aba. `'navegador'`: do localStorage. */
|
|
10
|
+
source: 'aba' | 'navegador';
|
|
11
|
+
}
|
|
12
|
+
/** Overrides que valem nesta página. Os da aba têm prioridade sobre os do navegador. */
|
|
13
|
+
declare function activeOverrides(): ActiveOverride[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Painel de desenvolvimento: troca a URL de um remote por um `vite dev`
|
|
17
|
+
* local (ou pelo preview de um PR) sem mexer no código do host.
|
|
18
|
+
*
|
|
19
|
+
* import { devtools } from 'vitral/devtools'
|
|
20
|
+
* if (import.meta.env.DEV) devtools()
|
|
21
|
+
*
|
|
22
|
+
* O painel lista os overrides ativos: os de `?vitral=` desta aba e os
|
|
23
|
+
* salvos em `localStorage['vitral:overrides']`. Só valem com
|
|
24
|
+
* `configure({ devOverrides })` ou com a página em localhost.
|
|
25
|
+
*/
|
|
26
|
+
|
|
1
27
|
/** Overrides salvos neste navegador: `{ nome: url }`. */
|
|
2
28
|
declare function getOverrides(): Record<string, string>;
|
|
3
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Salva no navegador o override de um remote: URL ou apelido (`pr-123`).
|
|
31
|
+
* `null` remove o override (da aba e do navegador). Vale a partir do próximo
|
|
32
|
+
* carregamento.
|
|
33
|
+
*/
|
|
4
34
|
declare function setOverride(name: string, url: string | null): void;
|
|
5
35
|
interface DevtoolsOptions {
|
|
6
36
|
/** Recarrega a página depois de mudar um override. Padrão: true. */
|
|
@@ -9,4 +39,4 @@ interface DevtoolsOptions {
|
|
|
9
39
|
/** Mostra o painel no canto da página. Devolve uma função que o remove. */
|
|
10
40
|
declare function devtools(options?: DevtoolsOptions): () => void;
|
|
11
41
|
|
|
12
|
-
export { type DevtoolsOptions, devtools, getOverrides, setOverride };
|
|
42
|
+
export { type ActiveOverride, type DevtoolsOptions, activeOverrides, clearOverrides, devtools, getOverrides, setOverride };
|
package/dist/devtools.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
activeOverrides,
|
|
3
|
+
clearOverrides,
|
|
4
|
+
dropOverride,
|
|
4
5
|
overridesEnabled,
|
|
6
|
+
storeOverride,
|
|
5
7
|
storedOverrides
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-54CBIZES.js";
|
|
7
9
|
import "./chunk-GNPFWISJ.js";
|
|
8
10
|
|
|
9
11
|
// src/devtools.ts
|
|
@@ -11,11 +13,8 @@ function getOverrides() {
|
|
|
11
13
|
return storedOverrides();
|
|
12
14
|
}
|
|
13
15
|
function setOverride(name, url) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else delete all[name];
|
|
17
|
-
if (Object.keys(all).length) localStorage.setItem(OVERRIDES_KEY, JSON.stringify(all));
|
|
18
|
-
else localStorage.removeItem(OVERRIDES_KEY);
|
|
16
|
+
if (url) storeOverride(name, url);
|
|
17
|
+
else dropOverride(name);
|
|
19
18
|
}
|
|
20
19
|
var STYLE = `
|
|
21
20
|
:host { position: fixed; right: 12px; bottom: 12px; z-index: 2147483647; font: 13px/1.4 system-ui, sans-serif; color: #111 }
|
|
@@ -27,6 +26,8 @@ li { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; word-brea
|
|
|
27
26
|
form { display: grid; gap: 4px }
|
|
28
27
|
input { font: inherit; padding: 3px 6px }
|
|
29
28
|
.aviso { color: #a40000; margin: 0 0 8px }
|
|
29
|
+
.ativo { background: #fde68a; border-color: #b45309 }
|
|
30
|
+
.limpar { margin-top: 8px }
|
|
30
31
|
`;
|
|
31
32
|
function devtools(options = {}) {
|
|
32
33
|
const host = document.createElement("div");
|
|
@@ -43,9 +44,16 @@ function devtools(options = {}) {
|
|
|
43
44
|
toggle.textContent = "vitral";
|
|
44
45
|
toggle.onclick = () => panel.hidden = !panel.hidden;
|
|
45
46
|
root.append(style, panel, toggle);
|
|
46
|
-
const changed = () =>
|
|
47
|
+
const changed = () => {
|
|
48
|
+
const q = new URLSearchParams(location.search);
|
|
49
|
+
if (q.has("vitral")) q.delete("vitral"), history.replaceState(history.state, "", `${location.pathname}${q.size ? `?${q}` : ""}${location.hash}`);
|
|
50
|
+
options.reload === false ? draw() : location.reload();
|
|
51
|
+
};
|
|
47
52
|
function draw() {
|
|
48
53
|
panel.replaceChildren();
|
|
54
|
+
const active = activeOverrides();
|
|
55
|
+
toggle.textContent = active.length ? `vitral (${active.length})` : "vitral";
|
|
56
|
+
toggle.classList.toggle("ativo", active.length > 0);
|
|
49
57
|
if (!overridesEnabled()) {
|
|
50
58
|
const p = document.createElement("p");
|
|
51
59
|
p.className = "aviso";
|
|
@@ -53,19 +61,19 @@ function devtools(options = {}) {
|
|
|
53
61
|
panel.append(p);
|
|
54
62
|
}
|
|
55
63
|
const list = document.createElement("ul");
|
|
56
|
-
for (const
|
|
64
|
+
for (const { name: name2, value, url: url2, source } of active) {
|
|
57
65
|
const item = document.createElement("li");
|
|
58
66
|
const remove = document.createElement("button");
|
|
59
67
|
remove.type = "button";
|
|
60
68
|
remove.textContent = "remover";
|
|
61
69
|
remove.setAttribute("aria-label", `remover override de ${name2}`);
|
|
62
70
|
remove.onclick = () => (setOverride(name2, null), changed());
|
|
63
|
-
item.append(`${name2} \u2192 ${url2}`, remove);
|
|
71
|
+
item.append(`${name2} \u2192 ${url2 ?? `${value} (sem devOverrides.preview)`} [${source}]`, remove);
|
|
64
72
|
list.append(item);
|
|
65
73
|
}
|
|
66
74
|
const form = document.createElement("form");
|
|
67
75
|
const name = Object.assign(document.createElement("input"), { placeholder: "nome (ex.: carrinho)", required: true, name: "name" });
|
|
68
|
-
const url = Object.assign(document.createElement("input"), { placeholder: "http://localhost:5174", required: true, name: "url" });
|
|
76
|
+
const url = Object.assign(document.createElement("input"), { placeholder: "http://localhost:5174 ou pr-123", required: true, name: "url" });
|
|
69
77
|
const save = Object.assign(document.createElement("button"), { type: "submit", textContent: "Salvar" });
|
|
70
78
|
form.append(name, url, save);
|
|
71
79
|
form.onsubmit = (e) => {
|
|
@@ -74,12 +82,19 @@ function devtools(options = {}) {
|
|
|
74
82
|
changed();
|
|
75
83
|
};
|
|
76
84
|
panel.append(list, form);
|
|
85
|
+
if (active.length) {
|
|
86
|
+
const clear = Object.assign(document.createElement("button"), { type: "button", textContent: "Limpar todos", className: "limpar" });
|
|
87
|
+
clear.onclick = () => (clearOverrides(), changed());
|
|
88
|
+
panel.append(clear);
|
|
89
|
+
}
|
|
77
90
|
}
|
|
78
91
|
draw();
|
|
79
92
|
document.body.append(host);
|
|
80
93
|
return () => host.remove();
|
|
81
94
|
}
|
|
82
95
|
export {
|
|
96
|
+
activeOverrides,
|
|
97
|
+
clearOverrides,
|
|
83
98
|
devtools,
|
|
84
99
|
getOverrides,
|
|
85
100
|
setOverride
|
package/dist/dict.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vitral/dict`: serve os remotes com dicionários de compressão
|
|
3
|
+
* (Compression Dictionary Transport, RFC 9842).
|
|
4
|
+
*
|
|
5
|
+
* Cada `.js` e `.css` do dist sai com `Use-As-Dictionary`. No deploy seguinte,
|
|
6
|
+
* o navegador pede o arquivo novo com `Available-Dictionary` (o hash do arquivo
|
|
7
|
+
* antigo que ele tem em cache) e recebe só a diferença, pré-comprimida por
|
|
8
|
+
* `vitral dict` em `.dcz` (zstd) ou `.dcb` (brotli).
|
|
9
|
+
*
|
|
10
|
+
* Só usa `Request`, `Response` e `Headers` da Web: roda em Node, Deno, Bun,
|
|
11
|
+
* Cloudflare Workers e outros edges. O navegador descomprime sozinho.
|
|
12
|
+
*/
|
|
13
|
+
/** Variantes pré-comprimidas de um arquivo para um dicionário. Caminhos relativos ao dist. */
|
|
14
|
+
interface DictVariant {
|
|
15
|
+
dcz?: string;
|
|
16
|
+
dcb?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Um arquivo do dist no índice. */
|
|
19
|
+
interface DictFile {
|
|
20
|
+
/** `Content-Type` do arquivo. */
|
|
21
|
+
type: string;
|
|
22
|
+
/** Variantes por hash do dicionário, no formato de `Available-Dictionary` (`:base64:`). */
|
|
23
|
+
deltas: Record<string, DictVariant>;
|
|
24
|
+
}
|
|
25
|
+
/** O `vitral-dict.json` que `vitral dict` grava no dist. */
|
|
26
|
+
interface DictIndex {
|
|
27
|
+
version: 1;
|
|
28
|
+
/** Por caminho relativo ao dist (`remote-a1b2c3d4.js`, `split/chunk-x-a1b2c3d4.js`). */
|
|
29
|
+
files: Record<string, DictFile>;
|
|
30
|
+
}
|
|
31
|
+
type Body = Uint8Array | ArrayBuffer | ReadableStream<Uint8Array> | string;
|
|
32
|
+
interface DictOptions {
|
|
33
|
+
/** Conteúdo do `vitral-dict.json`. */
|
|
34
|
+
index: DictIndex;
|
|
35
|
+
/** Lê um arquivo do dist pelo caminho relativo. `null` se não existir. */
|
|
36
|
+
read: (path: string) => Body | null | undefined | Promise<Body | null | undefined>;
|
|
37
|
+
/** Caminho em que o dist é servido. Padrão: `/`. */
|
|
38
|
+
base?: string;
|
|
39
|
+
/** `Cache-Control` das respostas com dicionário. Padrão: um ano, `immutable` (os nomes têm hash). */
|
|
40
|
+
cacheControl?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Request do Node (`http.IncomingMessage`), só o que o middleware usa. */
|
|
43
|
+
interface NodeRequest {
|
|
44
|
+
method?: string;
|
|
45
|
+
url?: string;
|
|
46
|
+
headers: Record<string, string | string[] | undefined>;
|
|
47
|
+
}
|
|
48
|
+
/** Response do Node (`http.ServerResponse`), só o que o middleware usa. */
|
|
49
|
+
interface NodeResponse {
|
|
50
|
+
setHeader(name: string, value: string): unknown;
|
|
51
|
+
writeHead(status: number, headers: Record<string, string>): unknown;
|
|
52
|
+
end(body?: Uint8Array | string): unknown;
|
|
53
|
+
}
|
|
54
|
+
interface Dict {
|
|
55
|
+
/**
|
|
56
|
+
* Responde com a variante `dcz`/`dcb` quando o navegador tem o dicionário certo.
|
|
57
|
+
* `undefined`: sirva o arquivo como sempre, com os cabeçalhos de `headers()`.
|
|
58
|
+
*/
|
|
59
|
+
fetch(request: Request): Promise<Response | undefined>;
|
|
60
|
+
/** `Use-As-Dictionary` e `Vary` para a resposta normal de um caminho. `undefined` se o caminho não está no índice. */
|
|
61
|
+
headers(pathname: string): Record<string, string> | undefined;
|
|
62
|
+
/** Middleware para Node, Express e Connect: responde a variante ou põe os cabeçalhos e chama `next`. */
|
|
63
|
+
node(req: NodeRequest, res: NodeResponse, next: (err?: unknown) => void): void;
|
|
64
|
+
}
|
|
65
|
+
/** Padrão de `match` para um caminho: o hash do nome vira `*`. */
|
|
66
|
+
declare function dictMatch(pathname: string): string;
|
|
67
|
+
declare function createDict(o: DictOptions): Dict;
|
|
68
|
+
|
|
69
|
+
export { type Dict, type DictFile, type DictIndex, type DictOptions, type DictVariant, type NodeRequest, type NodeResponse, createDict, dictMatch };
|
package/dist/dict.js
ADDED
package/dist/edge.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { P as Props } from './types-DUtcF3HO.js';
|
|
2
|
+
import './errors-kjBv6IH_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Rewriter de HTML em streaming, para runtimes sem `HTMLRewriter` (Node, Deno,
|
|
6
|
+
* Bun). Faz só o que o gateway precisa: acha as tags de abertura de um
|
|
7
|
+
* elemento (`<vitral-remote>`) e dos filhos diretos dele, deixa ler e trocar
|
|
8
|
+
* atributos e inserir HTML logo depois da tag. O resto passa como veio.
|
|
9
|
+
*
|
|
10
|
+
* Ignora comentários e o conteúdo de `<script>`, `<style>`, `<textarea>` e
|
|
11
|
+
* `<title>`. Não monta árvore: dentro do elemento, conta a profundidade pelas
|
|
12
|
+
* tags de abertura e fechamento (elementos vazios, como `<img>`, não contam).
|
|
13
|
+
*/
|
|
14
|
+
/** O subconjunto do `Element` do `HTMLRewriter` que o gateway usa. */
|
|
15
|
+
interface EdgeElement {
|
|
16
|
+
readonly tagName: string;
|
|
17
|
+
getAttribute(name: string): string | null;
|
|
18
|
+
hasAttribute(name: string): boolean;
|
|
19
|
+
setAttribute(name: string, value: string): void;
|
|
20
|
+
/** Insere conteúdo logo depois da tag de abertura. */
|
|
21
|
+
prepend(content: string, options?: {
|
|
22
|
+
html?: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Gateway de edge: host e remotes servidos de uma origem só, com Early Hints
|
|
28
|
+
* e SSR opcional dos remotes em Declarative Shadow DOM.
|
|
29
|
+
*
|
|
30
|
+
* import { gateway } from 'vitral/edge'
|
|
31
|
+
*
|
|
32
|
+
* const handler = gateway({
|
|
33
|
+
* origin: 'https://app.empresa.com',
|
|
34
|
+
* remotes: { carrinho: 'https://cdn.empresa.com/carrinho/vitral.json' },
|
|
35
|
+
* })
|
|
36
|
+
* export default { fetch: handler } // Cloudflare Workers
|
|
37
|
+
*
|
|
38
|
+
* - `/_vitral/<nome>/<caminho>` vira `<pasta do remote>/<caminho>`. O
|
|
39
|
+
* `vitral.json` sai com as URLs absolutas do CDN trocadas por caminhos desta
|
|
40
|
+
* origem; os hashes de SRI ficam iguais, porque os bytes são os mesmos.
|
|
41
|
+
* - O resto vai para `origin`. No HTML, `<vitral-remote src>` do CDN passa a
|
|
42
|
+
* apontar para cá, e a resposta ganha `Link: rel=modulepreload` (ou
|
|
43
|
+
* `preload`) para os remotes que a página usou da última vez.
|
|
44
|
+
* - Remote com `render` sai renderizado: um `<template shadowrootmode>` com o
|
|
45
|
+
* HTML e o CSS dele dentro do `<vitral-remote>`. No cliente, o remote que
|
|
46
|
+
* exporta `hydrate` hidrata esse HTML em vez de montar de novo.
|
|
47
|
+
*
|
|
48
|
+
* Só usa APIs Web (`fetch`, `Request`, `Response`, streams). Usa o
|
|
49
|
+
* `HTMLRewriter` quando o runtime tem (Cloudflare Workers); senão, um
|
|
50
|
+
* rewriter próprio em streaming. No Node, `toNodeListener(handler)`.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/** HTML do remote para estas props, no servidor. */
|
|
54
|
+
type ServerRender = (props: Props) => string | Promise<string>;
|
|
55
|
+
/** Isolamento do remote na página (o mesmo de `isolate` no cliente). */
|
|
56
|
+
type EdgeIsolation = 'shadow' | 'none';
|
|
57
|
+
interface EdgeRemote {
|
|
58
|
+
/** URL do `vitral.json` (ou do JS) do remote no CDN. */
|
|
59
|
+
url: string;
|
|
60
|
+
/**
|
|
61
|
+
* SSR: devolve o HTML do remote. O mesmo `render` que o remote exporta
|
|
62
|
+
* para o servidor (ex.: `import { render } from 'carrinho/server'`).
|
|
63
|
+
*/
|
|
64
|
+
render?: ServerRender;
|
|
65
|
+
/** Isolamento usado no SSR quando a tag não tem `isolate`. */
|
|
66
|
+
isolate?: EdgeIsolation;
|
|
67
|
+
}
|
|
68
|
+
interface GatewayOptions {
|
|
69
|
+
/** Origem do host (o app que serve as páginas). */
|
|
70
|
+
origin: string;
|
|
71
|
+
/** Remotes por nome: a URL do `vitral.json` ou a entrada completa. */
|
|
72
|
+
remotes: Record<string, string | EdgeRemote>;
|
|
73
|
+
/** Prefixo dos caminhos dos remotes. Padrão `/_vitral/`. */
|
|
74
|
+
prefix?: string;
|
|
75
|
+
/** Isolamento padrão do SSR (o `isolate` do `configure` do host). Padrão `'none'`. */
|
|
76
|
+
isolate?: EdgeIsolation;
|
|
77
|
+
/** Remotes que esta URL usa, para os hints da primeira visita. */
|
|
78
|
+
preload?: (url: URL) => string[];
|
|
79
|
+
/** `fetch` usado para falar com o host e os CDNs. Padrão: o global. */
|
|
80
|
+
fetch?: (request: Request) => Promise<Response>;
|
|
81
|
+
/** Por quanto tempo o gateway guarda manifestos e CSS, em ms. Padrão 60000. */
|
|
82
|
+
ttl?: number;
|
|
83
|
+
/** Erro no SSR de um remote (a página sai sem o SSR dele). Padrão: `console.error`. */
|
|
84
|
+
onError?: (error: unknown, name: string) => void;
|
|
85
|
+
}
|
|
86
|
+
/** Handler do gateway: `(request) => Response`. */
|
|
87
|
+
interface Gateway {
|
|
88
|
+
(request: Request): Promise<Response>;
|
|
89
|
+
/** Valores de `Link` para esta requisição (para 103 Early Hints). */
|
|
90
|
+
hints(request: Request): Promise<string[]>;
|
|
91
|
+
}
|
|
92
|
+
declare function gateway(options: GatewayOptions): Gateway;
|
|
93
|
+
/** O que `toNodeListener` usa do `IncomingMessage`. */
|
|
94
|
+
interface NodeRequestLike extends AsyncIterable<Uint8Array> {
|
|
95
|
+
method?: string;
|
|
96
|
+
url?: string;
|
|
97
|
+
headers: Record<string, string | string[] | undefined>;
|
|
98
|
+
socket?: {
|
|
99
|
+
encrypted?: boolean;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** O que `toNodeListener` usa do `ServerResponse`. */
|
|
103
|
+
interface NodeResponseLike {
|
|
104
|
+
writeHead(status: number, headers: Record<string, string | string[]>): unknown;
|
|
105
|
+
write(chunk: Uint8Array): unknown;
|
|
106
|
+
end(chunk?: string): unknown;
|
|
107
|
+
writeEarlyHints?(hints: Record<string, string | string[]>): void;
|
|
108
|
+
headersSent?: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Listener de `http.createServer` para um handler `(request) => Response`.
|
|
112
|
+
* Com o gateway, manda 103 Early Hints antes de buscar a página.
|
|
113
|
+
*
|
|
114
|
+
* createServer(toNodeListener(gateway({ origin, remotes }))).listen(8080)
|
|
115
|
+
*/
|
|
116
|
+
declare function toNodeListener(handler: ((request: Request) => Promise<Response>) | Gateway): (req: NodeRequestLike, res: NodeResponseLike) => Promise<void>;
|
|
117
|
+
|
|
118
|
+
export { type EdgeElement, type EdgeIsolation, type EdgeRemote, type Gateway, type GatewayOptions, type NodeRequestLike, type NodeResponseLike, type ServerRender, gateway, toNodeListener };
|