gradio

Форк
0
/
asgi-types.ts 
37 строк · 1.5 Кб
1
import type { PyProxy } from "pyodide/ffi";
2

3
// A reference to an ASGI application instance in Python
4
// Ref: https://asgi.readthedocs.io/en/latest/specs/main.html#applications
5
export type ASGIScope = Record<string, unknown>;
6
export type ASGIApplication = (
7
	scope: ASGIScope,
8
	receive: () => Promise<ReceiveEvent>,
9
	send: (event: PyProxy) => Promise<void> // `event` is a `SendEvent` dict in Python and passed as a `PyProxy` in JS via Pyodide's type conversion (https://pyodide.org/en/stable/usage/type-conversions.html#type-translations-pyproxy-to-js).
10
) => Promise<void>;
11

12
export type ReceiveEvent = RequestReceiveEvent | DisconnectReceiveEvent;
13
// https://asgi.readthedocs.io/en/latest/specs/www.html#request-receive-event
14
export interface RequestReceiveEvent {
15
	type: "http.request";
16
	body?: Uint8Array; // `bytes` in Python
17
	more_body?: boolean;
18
}
19
// https://asgi.readthedocs.io/en/latest/specs/www.html#disconnect-receive-event
20
export interface DisconnectReceiveEvent {
21
	type: "http.disconnect";
22
}
23

24
export type SendEvent = ResponseStartSendEvent | ResponseBodySendEvent;
25
// https://asgi.readthedocs.io/en/latest/specs/www.html#response-start-send-event
26
export interface ResponseStartSendEvent {
27
	type: "http.response.start";
28
	status: number;
29
	headers: Iterable<[Uint8Array, Uint8Array]>;
30
	trailers: boolean;
31
}
32
// https://asgi.readthedocs.io/en/latest/specs/www.html#response-body-send-event
33
export interface ResponseBodySendEvent {
34
	type: "http.response.body";
35
	body: Uint8Array; // `bytes` in Python
36
	more_body: boolean;
37
}
38

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.