@napps/nodes and describe the browser-like APIs available inside the Expresso runtime.
Timers and console
function setTimeout(handler: (...args: any[]) => void, timeout?: number, ...args: any[]): number;
function clearTimeout(id?: number): void;
function setInterval(handler: (...args: any[]) => void, timeout?: number, ...args: any[]): number;
function clearInterval(id?: number): void;
function queueMicrotask(callback: () => void): void;
interface Console {
log(...data: unknown[]): void;
info(...data: unknown[]): void;
warn(...data: unknown[]): void;
error(...data: unknown[]): void;
debug(...data: unknown[]): void;
trace(...data: unknown[]): void;
dir(item?: unknown, options?: unknown): void;
table(tabularData?: unknown, properties?: string[]): void;
assert(condition?: boolean, ...data: unknown[]): void;
count(label?: string): void;
countReset(label?: string): void;
group(...data: unknown[]): void;
groupCollapsed(...data: unknown[]): void;
groupEnd(): void;
time(label?: string): void;
timeEnd(label?: string): void;
clear(): void;
}
declare const console: Console;
Performance
type PerformanceEntryType = "mark" | "measure";
interface PerformanceEntry {
readonly id: number;
readonly name: string;
readonly entryType: PerformanceEntryType;
readonly startTime: number;
readonly duration: number;
readonly navigationId: number;
toJSON(): Record<string, unknown>;
}
interface Performance {
readonly timeOrigin: number;
now(): number;
mark(name: string, options?: { startTime?: number; detail?: unknown }): PerformanceEntry;
measure(name: string, startMark?: string): PerformanceEntry;
clearMarks(name?: string): void;
clearMeasures(name?: string): void;
getEntries(): PerformanceEntry[];
getEntriesByType(type: PerformanceEntryType): PerformanceEntry[];
getEntriesByName(name: string, type?: PerformanceEntryType): PerformanceEntry[];
toJSON(): Record<string, unknown>;
}
declare const performance: Performance;
Fetch types
type BodyInit = string | ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams;
type HeadersInit = Headers | Record<string, string>;
type RequestInfo = string | Request;
interface RequestInit {
method?: string;
headers?: HeadersInit;
body?: BodyInit | null;
signal?: AbortSignal | null;
cache?: string;
credentials?: string;
integrity?: string;
keepalive?: boolean;
mode?: string;
redirect?: string;
referrer?: string;
referrerPolicy?: string;
}
class Headers {
constructor(init?: HeadersInit);
append(name: string, value: string): void;
set(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
has(name: string): boolean;
getSetCookie(): string[];
forEach(callback: (value: string, key: string, parent: Headers) => void, thisArg?: unknown): void;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
entries(): IterableIterator<[string, string]>;
}
class Request {
constructor(input?: RequestInfo | URL, init?: RequestInit);
readonly url: string;
readonly method: string;
readonly headers: Headers;
readonly signal: AbortSignal;
readonly cache: string;
readonly credentials: string;
readonly mode: string;
readonly redirect: string;
readonly referrer: string;
readonly referrerPolicy: string;
readonly keepalive: boolean;
readonly bodyUsed: boolean;
readonly body?: ReadableStream | null;
text(): Promise<string>;
json(): Promise<unknown>;
arrayBuffer(): Promise<ArrayBuffer>;
bytes(): Promise<Uint8Array>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
clone(): Request;
}
interface ResponseInit {
status?: number;
statusText?: string;
headers?: Headers;
}
class Response {
constructor(body?: BodyInit | null, init?: ResponseInit);
static json(data: unknown, init?: unknown): Response;
static error(): Response;
static redirect(url: string, status?: number): Response;
readonly status: number;
readonly statusText: string;
readonly url: string;
readonly redirected: boolean;
readonly type: string;
readonly headers: Headers;
readonly ok: boolean;
readonly bodyUsed: boolean;
readonly body?: ReadableStream | null;
text(): Promise<string>;
json(): Promise<unknown>;
arrayBuffer(): Promise<ArrayBuffer>;
bytes(): Promise<Uint8Array>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
clone(): Response;
}
declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
Streams and binary data
class ReadableStream {
constructor(underlyingSource?: unknown);
readonly locked: boolean;
getReader(): ReadableStreamDefaultReader;
cancel(): Promise<void>;
}
interface ReadableStreamDefaultReader {
read(): Promise<{ value?: Uint8Array; done: boolean }>;
cancel(): Promise<void>;
releaseLock(): void;
}
type BlobPart = ArrayBuffer | ArrayBufferView | Blob | string;
interface BlobOptions {
type?: string;
endings?: "transparent" | "native";
}
class Blob {
constructor(parts?: BlobPart[], options?: BlobOptions);
readonly size: number;
readonly type: string;
slice(start?: number, end?: number, contentType?: string): Blob;
text(): Promise<string>;
arrayBuffer(): Promise<ArrayBuffer>;
bytes(): Promise<Uint8Array>;
stream(): ReadableStream;
}
type FormDataEntryValue = string | Blob;
class FormData {
constructor();
append(name: string, value: FormDataEntryValue, fileName?: string): void;
set(name: string, value: FormDataEntryValue, fileName?: string): void;
get(name: string): FormDataEntryValue | null;
getAll(name: string): FormDataEntryValue[];
has(name: string): boolean;
delete(name: string): void;
keys(): IterableIterator<string>;
values(): IterableIterator<FormDataEntryValue>;
entries(): IterableIterator<[string, FormDataEntryValue]>;
}
ReadableStream sources are not supported. Network response streams are supported.
WebSocket
type WebSocketEventType = "open" | "message" | "error" | "close";
class WebSocket extends EventTarget {
constructor(url: string, protocols?: string | string[]);
readonly url: string;
protocol: string;
extensions: string;
binaryType: "arraybuffer" | "blob";
readonly readyState: 0 | 1 | 2 | 3;
readonly bufferedAmount: number;
send(data: string | ArrayBuffer | ArrayBufferView): void;
close(code?: number, reason?: string): void;
addEventListener(type: WebSocketEventType, listener: (event: unknown) => void): void;
removeEventListener(type: WebSocketEventType, listener: (event: unknown) => void): void;
onopen: ((event: unknown) => void) | null;
onmessage: ((event: { data: string | ArrayBuffer | Blob }) => void) | null;
onerror: ((event: unknown) => void) | null;
onclose: ((event: { code: number; reason: string; wasClean: boolean }) => void) | null;
}
ArrayBuffer or Blob according to binaryType.
Abort
class AbortController {
readonly signal: AbortSignal;
abort(reason?: unknown): void;
}
class AbortSignal {
readonly aborted: boolean;
readonly reason: unknown;
onabort: ((event: { type: "abort" }) => void) | null;
throwIfAborted(): void;
addEventListener(type: "abort", listener: (event: { type: "abort" }) => void): void;
removeEventListener(type: "abort", listener: (event: { type: "abort" }) => void): void;
}
URL
class URL {
constructor(input: string, base?: string);
href: string;
protocol: string;
username: string;
password: string;
host: string;
hostname: string;
port: string;
pathname: string;
search: string;
searchParams: URLSearchParams;
hash: string;
origin: string;
toString(): string;
toJSON(): string;
static canParse(input: string, base?: string): boolean;
static parse(input: string, base?: string): URL | null;
}
class URLSearchParams {
constructor(init?: string | Record<string, string> | Array<[string, string]>);
readonly size: number;
append(name: string, value: string): void;
delete(name: string, value?: string): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string, value?: string): boolean;
set(name: string, value: string): void;
sort(): void;
toString(): string;
entries(): Array<[string, string]>;
keys(): string[];
values(): string[];
}
Persistent storage
AppStorage is asynchronous, persistent, scoped, and SQLite-backed. The complete storage interfaces include AppStorageScope, AppStorageKv, AppStorageTable, AppStorageUsage, query conditions, indexes, expiration, and quota options.
interface AppStorageApi {
readonly available: boolean;
scope(name: string): AppStorageScope;
usage(): Promise<AppStorageUsage>;
scopes(): Promise<string[]>;
drop(scope: string): Promise<void>;
}
interface AppStorageScope {
readonly name: string;
kv(name?: string, options?: AppStorageContainerOptions): AppStorageKv;
table(name: string, options?: AppStorageTableOptions): AppStorageTable;
usage(): Promise<AppStorageUsage>;
clear(): Promise<void>;
purgeExpired(): Promise<number>;
}
declare const AppStorage: AppStorageApi;
sessionStorage remains the synchronous process-scoped storage API. See Runtime APIs for behavior and limits.