1
import type { PyProxy } from "pyodide/ffi";
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 = (
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).
12
export type ReceiveEvent = RequestReceiveEvent | DisconnectReceiveEvent;
13
// https://asgi.readthedocs.io/en/latest/specs/www.html#request-receive-event
14
export interface RequestReceiveEvent {
16
body?: Uint8Array; // `bytes` in Python
19
// https://asgi.readthedocs.io/en/latest/specs/www.html#disconnect-receive-event
20
export interface DisconnectReceiveEvent {
21
type: "http.disconnect";
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";
29
headers: Iterable<[Uint8Array, Uint8Array]>;
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