@syntropika/tembra-sdk 0.2.1 → 0.3.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/README.md +43 -17
- package/dist/authoring/types.d.ts +64 -3
- package/dist/authoring/wit.d.ts +6 -0
- package/dist/bridge/commands.d.ts +1190 -0
- package/dist/bridge/identifiers.d.ts +2 -0
- package/dist/bridge/kernel.d.ts +18 -107
- package/dist/bridge/protocol.d.ts +3 -138
- package/dist/browser.d.ts +14 -1
- package/dist/browser.js +141 -3298
- package/dist/chunks/browser-b8jamxw2.js +3399 -0
- package/dist/chunks/execution-nsqc6nrt.js +1419 -0
- package/dist/chunks/index-01zk0xqx.js +160 -0
- package/dist/chunks/index-3fjdfdfd.js +152 -0
- package/dist/chunks/index-aaymjn7v.js +787 -0
- package/dist/chunks/index-c1w7z9hx.js +356 -0
- package/dist/chunks/index-h8t0n42q.js +738 -0
- package/dist/chunks/index-hfds9mzp.js +308 -0
- package/dist/chunks/index-kr4x67wt.js +177 -0
- package/dist/chunks/index-kr6bnh34.js +117 -0
- package/dist/chunks/index-kyt9dj0a.js +1421 -0
- package/dist/chunks/index-n1wxzc9w.js +830 -0
- package/dist/chunks/index-pvac426d.js +74 -0
- package/dist/chunks/index-smyds5ce.js +3234 -0
- package/dist/chunks/index-sse8aapb.js +121 -0
- package/dist/chunks/index-v6heph77.js +643 -0
- package/dist/chunks/index-xrdvnv37.js +3448 -0
- package/dist/chunks/index-za4mg94e.js +26 -0
- package/dist/chunks/index-zkqmnjj8.js +167 -0
- package/dist/coordinator.js +9 -500
- package/dist/error.d.ts +2 -0
- package/dist/errors.d.ts +3 -0
- package/dist/guest.d.ts +173 -0
- package/dist/guest.js +26 -0
- package/dist/host.d.ts +36 -30
- package/dist/host.js +37 -3276
- package/dist/http/bytes.d.ts +8 -0
- package/dist/http/events.d.ts +7 -0
- package/dist/http.d.ts +45 -0
- package/dist/http.js +291 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -862
- package/dist/infrastructure/rpc/client.d.ts +2 -1
- package/dist/infrastructure/rpc/resources.d.ts +28 -0
- package/dist/interpreter/abi.d.ts +54 -0
- package/dist/interpreter/acquire.d.ts +18 -0
- package/dist/interpreter/browser-network.d.ts +52 -0
- package/dist/interpreter/browser-port.d.ts +55 -0
- package/dist/interpreter/browser.d.ts +79 -0
- package/dist/interpreter/cli.d.ts +5 -0
- package/dist/interpreter/codec.d.ts +42 -0
- package/dist/interpreter/component/execution.d.ts +42 -0
- package/dist/interpreter/component/host.d.ts +69 -0
- package/dist/interpreter/component/instance.d.ts +40 -0
- package/dist/interpreter/component/kernel.d.ts +120 -0
- package/dist/interpreter/component/names.d.ts +5 -0
- package/dist/interpreter/component/port.d.ts +85 -0
- package/dist/interpreter/component/prepared.d.ts +97 -0
- package/dist/interpreter/component/resources.d.ts +45 -0
- package/dist/interpreter/component/revision.d.ts +87 -0
- package/dist/interpreter/component/scope.d.ts +116 -0
- package/dist/interpreter/component/streams.d.ts +28 -0
- package/dist/interpreter/component/values.d.ts +79 -0
- package/dist/interpreter/component/wasi-filesystem.d.ts +21 -0
- package/dist/interpreter/component/wasi-host.d.ts +64 -0
- package/dist/interpreter/component/wasi-http.d.ts +33 -0
- package/dist/interpreter/component/wasi-sockets.d.ts +183 -0
- package/dist/interpreter/component/wasi.d.ts +41 -0
- package/dist/interpreter/core.d.ts +64 -0
- package/dist/interpreter/fetch-http-provider.d.ts +17 -0
- package/dist/interpreter/filesystem/contract.d.ts +85 -0
- package/dist/interpreter/filesystem/memory.d.ts +3 -0
- package/dist/interpreter/filesystem/opfs.d.ts +3 -0
- package/dist/interpreter/filesystem/scope.d.ts +35 -0
- package/dist/interpreter/filesystem.d.ts +8 -0
- package/dist/interpreter/gate.d.ts +6 -0
- package/dist/interpreter/host-protocol.d.ts +100 -0
- package/dist/interpreter/http-ingress-fetch.d.ts +7 -0
- package/dist/interpreter/http-ingress.d.ts +96 -0
- package/dist/interpreter/http-provider.d.ts +85 -0
- package/dist/interpreter/io.d.ts +20 -0
- package/dist/interpreter/mobile.d.ts +149 -0
- package/dist/interpreter/native-ingress.d.ts +95 -0
- package/dist/interpreter/node-port.d.ts +25 -0
- package/dist/interpreter/node.d.ts +36 -0
- package/dist/interpreter/revision.d.ts +64 -0
- package/dist/interpreter/scope.d.ts +89 -0
- package/dist/interpreter/socket-addresses.d.ts +50 -0
- package/dist/interpreter/socket-provider.d.ts +110 -0
- package/dist/interpreter/standard-cli.d.ts +34 -0
- package/dist/interpreter/standard-codec.d.ts +96 -0
- package/dist/interpreter/standard-filesystem.d.ts +47 -0
- package/dist/interpreter/standard-host.d.ts +71 -0
- package/dist/interpreter/standard-http-values.d.ts +159 -0
- package/dist/interpreter/standard-http.d.ts +9 -0
- package/dist/interpreter/standard-ingress.d.ts +63 -0
- package/dist/interpreter/standard-sockets.d.ts +177 -0
- package/dist/interpreter/standard-streams.d.ts +218 -0
- package/dist/interpreter/standard-system.d.ts +35 -0
- package/dist/interpreter/standard-utf8.d.ts +4 -0
- package/dist/interpreter/standard.d.ts +18 -0
- package/dist/interpreter/types.d.ts +152 -0
- package/dist/interpreter/wit-shape.d.ts +92 -0
- package/dist/manager.js +5 -332
- package/dist/msgpack.js +9 -615
- package/dist/node.d.ts +8 -1
- package/dist/node.js +248 -3287
- package/dist/rpc.js +196 -699
- package/dist/runtime/adapters.d.ts +120 -0
- package/dist/runtime/adapters.js +38 -0
- package/dist/runtime/calls.d.ts +9 -3
- package/dist/runtime/lifecycle.d.ts +3 -1
- package/dist/runtime/orbs.d.ts +5 -4
- package/dist/runtime/references.d.ts +27 -1
- package/dist/runtime/reload.d.ts +5 -3
- package/dist/runtime/scopes.d.ts +1 -1
- package/dist/runtime/signals.d.ts +4 -0
- package/dist/runtime/wit-client.d.ts +38 -0
- package/dist/telemetry.js +4 -25
- package/dist/tooling/build.d.ts +2 -2
- package/dist/tooling/client-resources.d.ts +23 -0
- package/dist/tooling/client.d.ts +10 -0
- package/dist/tooling/component-glue.d.ts +17 -0
- package/dist/tooling/component.d.ts +11 -0
- package/dist/tooling/index.d.ts +3 -1
- package/dist/tooling/index.js +1155 -102
- package/dist/tooling/resolver.d.ts +4 -4
- package/dist/tooling/typecheck.d.ts +2 -1
- package/dist/tooling/types.d.ts +27 -12
- package/dist/tooling/wit.d.ts +9 -0
- package/dist/wasi/wasi-clocks-types.d.ts +2 -0
- package/dist/wasi/wasi-http-client.d.ts +5 -0
- package/dist/wasi/wasi-http-types.d.ts +285 -0
- package/dist/wasi/wasi-sockets-ip-name-lookup.d.ts +23 -0
- package/dist/wasi/wasi-sockets-types.d.ts +146 -0
- package/package.json +62 -35
- package/src/authoring/declaration.ts +1 -1
- package/src/authoring/types.ts +53 -3
- package/src/authoring/wit.ts +15 -0
- package/src/bridge/commands.ts +1105 -0
- package/src/bridge/identifiers.ts +2 -0
- package/src/bridge/kernel.ts +56 -98
- package/src/bridge/protocol.ts +3 -142
- package/src/browser.ts +90 -6
- package/src/context-key.ts +4 -7
- package/src/error.ts +1 -1
- package/src/errors.ts +7 -0
- package/src/guest.ts +327 -0
- package/src/host.ts +128 -23
- package/src/http/bytes.ts +87 -0
- package/src/http/events.ts +34 -0
- package/src/http.ts +272 -0
- package/src/index.ts +3 -0
- package/src/infrastructure/rpc/client.ts +136 -17
- package/src/infrastructure/rpc/resources.ts +123 -0
- package/src/interpreter/abi.ts +69 -0
- package/src/interpreter/acquire.ts +58 -0
- package/src/interpreter/browser-network.ts +170 -0
- package/src/interpreter/browser-port.ts +425 -0
- package/src/interpreter/browser.ts +340 -0
- package/src/interpreter/cli.ts +30 -0
- package/src/interpreter/codec.ts +298 -0
- package/src/interpreter/component/execution.ts +264 -0
- package/src/interpreter/component/host.ts +409 -0
- package/src/interpreter/component/instance.ts +138 -0
- package/src/interpreter/component/kernel.ts +611 -0
- package/src/interpreter/component/names.ts +13 -0
- package/src/interpreter/component/port.ts +598 -0
- package/src/interpreter/component/prepared.ts +194 -0
- package/src/interpreter/component/resources.ts +345 -0
- package/src/interpreter/component/revision.ts +702 -0
- package/src/interpreter/component/scope.ts +447 -0
- package/src/interpreter/component/streams.ts +180 -0
- package/src/interpreter/component/values.ts +254 -0
- package/src/interpreter/component/wasi-filesystem.ts +472 -0
- package/src/interpreter/component/wasi-host.ts +197 -0
- package/src/interpreter/component/wasi-http.ts +939 -0
- package/src/interpreter/component/wasi-sockets.ts +958 -0
- package/src/interpreter/component/wasi.ts +238 -0
- package/src/interpreter/core.ts +386 -0
- package/src/interpreter/fetch-http-provider.ts +98 -0
- package/src/interpreter/filesystem/contract.ts +138 -0
- package/src/interpreter/filesystem/memory.ts +180 -0
- package/src/interpreter/filesystem/opfs.ts +294 -0
- package/src/interpreter/filesystem/scope.ts +390 -0
- package/src/interpreter/filesystem.ts +20 -0
- package/src/interpreter/gate.ts +55 -0
- package/src/interpreter/host-protocol.ts +242 -0
- package/src/interpreter/http-ingress-fetch.ts +133 -0
- package/src/interpreter/http-ingress.ts +203 -0
- package/src/interpreter/http-provider.ts +105 -0
- package/src/interpreter/io.ts +66 -0
- package/src/interpreter/mobile.ts +385 -0
- package/src/interpreter/native-ingress.ts +550 -0
- package/src/interpreter/node-port.ts +218 -0
- package/src/interpreter/node.ts +114 -0
- package/src/interpreter/revision.ts +450 -0
- package/src/interpreter/scope.ts +453 -0
- package/src/interpreter/socket-addresses.ts +246 -0
- package/src/interpreter/socket-provider.ts +126 -0
- package/src/interpreter/standard-cli.ts +184 -0
- package/src/interpreter/standard-codec.ts +403 -0
- package/src/interpreter/standard-filesystem.ts +545 -0
- package/src/interpreter/standard-host.ts +840 -0
- package/src/interpreter/standard-http-values.ts +624 -0
- package/src/interpreter/standard-http.ts +622 -0
- package/src/interpreter/standard-ingress.ts +344 -0
- package/src/interpreter/standard-sockets.ts +847 -0
- package/src/interpreter/standard-streams.ts +710 -0
- package/src/interpreter/standard-system.ts +182 -0
- package/src/interpreter/standard-utf8.ts +72 -0
- package/src/interpreter/standard.ts +283 -0
- package/src/interpreter/types.ts +163 -0
- package/src/interpreter/wit-shape.ts +175 -0
- package/src/node.ts +43 -14
- package/src/runtime/activities.ts +6 -6
- package/src/runtime/adapters.ts +314 -0
- package/src/runtime/calls.ts +218 -56
- package/src/runtime/context.ts +7 -7
- package/src/runtime/lifecycle.ts +36 -17
- package/src/runtime/orbs.ts +81 -39
- package/src/runtime/programs.ts +16 -8
- package/src/runtime/references.ts +128 -11
- package/src/runtime/reload.ts +71 -30
- package/src/runtime/resources.ts +2 -2
- package/src/runtime/scopes.ts +17 -17
- package/src/runtime/session.ts +3 -1
- package/src/runtime/signals.ts +31 -0
- package/src/runtime/wit-client.ts +228 -0
- package/src/tooling/build.ts +152 -54
- package/src/tooling/client-resources.ts +74 -0
- package/src/tooling/client.ts +531 -0
- package/src/tooling/component-glue.ts +288 -0
- package/src/tooling/component.ts +225 -0
- package/src/tooling/index.ts +3 -7
- package/src/tooling/resolver.ts +42 -25
- package/src/tooling/typecheck.ts +59 -4
- package/src/tooling/types.ts +27 -12
- package/src/tooling/wit.ts +188 -0
- package/dist/embedded.d.ts +0 -1
- package/dist/embedded.js +0 -1
- package/src/embedded.ts +0 -293
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket addresses for the browser `wasi:sockets` host, with the same meaning as the native
|
|
3
|
+
* host:
|
|
4
|
+
* - equality and grant matching use Rust `SocketAddr` identity (IP, port, IPv6 flow
|
|
5
|
+
* information and scope id), never textual spelling;
|
|
6
|
+
* - validity predicates mirror pinned `wasmtime-wasi` 51.0.0-rc.1 `sockets/mod.rs`;
|
|
7
|
+
* - grant strings parse as Rust `SocketAddr::from_str`;
|
|
8
|
+
* - name lookup input parses as `url::Host::parse`.
|
|
9
|
+
*/
|
|
10
|
+
import type { IpAddress, IpAddressFamily, IpSocketAddress } from "../wasi/wasi-sockets-types.js";
|
|
11
|
+
/** One socket address with exact numeric fields; IPv4 has four octets, IPv6 eight segments. */
|
|
12
|
+
export interface Address {
|
|
13
|
+
readonly family: IpAddressFamily;
|
|
14
|
+
readonly ip: readonly number[];
|
|
15
|
+
readonly port: number;
|
|
16
|
+
readonly flowInfo: number;
|
|
17
|
+
readonly scopeId: number;
|
|
18
|
+
}
|
|
19
|
+
/** Read a WIT `ip-socket-address`, validating every field; `undefined` when malformed. */
|
|
20
|
+
export declare function fromWit(value: unknown): Address | undefined;
|
|
21
|
+
/** A fresh WIT value; never shares arrays with host state. */
|
|
22
|
+
export declare function toWit(address: Address): IpSocketAddress;
|
|
23
|
+
/** Rust `SocketAddr` identity: equal keys are equal addresses. */
|
|
24
|
+
export declare const key: (address: Address) => string;
|
|
25
|
+
export declare const unspecified: (family: IpAddressFamily) => Address;
|
|
26
|
+
/** Upstream `is_valid_unicast_address`. */
|
|
27
|
+
export declare function isUnicast(address: Address): boolean;
|
|
28
|
+
/** Upstream `is_valid_remote_address`. */
|
|
29
|
+
export declare const isRemote: (address: Address) => boolean;
|
|
30
|
+
/** Upstream `is_valid_address_family`, including IPv4-compatible and mapped IPv6 refusal. */
|
|
31
|
+
export declare function hasFamily(address: Address, family: IpAddressFamily): boolean;
|
|
32
|
+
/** An implicit bind by the OS uses the wildcard address and an ephemeral port. */
|
|
33
|
+
export declare const isImplicit: (address: Address) => boolean;
|
|
34
|
+
/** Strict dotted quad, as Rust `Ipv4Addr::from_str` (no leading zeros, no shorthand). */
|
|
35
|
+
export declare function parseIpv4(text: string): number[] | undefined;
|
|
36
|
+
/** Rust `Ipv6Addr::from_str`: 1–4 hex digits per group, one `::` for at least one group. */
|
|
37
|
+
export declare function parseIpv6(text: string): number[] | undefined;
|
|
38
|
+
/** A grant string as Rust `SocketAddr::from_str`: `a.b.c.d:port` or `[v6(%scope)]:port`. */
|
|
39
|
+
export declare function parseSocketAddress(text: string): Address | undefined;
|
|
40
|
+
/** Validate and canonicalize one provider lookup result; mapped IPv6 becomes IPv4. */
|
|
41
|
+
export declare function checkedIpAddress(value: unknown): IpAddress | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Parse a `resolve-addresses` name as `url::Host::parse` with the bare IPv6 fallback upstream
|
|
44
|
+
* adds: an IP literal is answered directly; a domain is IDNA-processed to ASCII.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseHostName(name: string): {
|
|
47
|
+
readonly ip: IpAddress;
|
|
48
|
+
} | {
|
|
49
|
+
readonly domain: string;
|
|
50
|
+
} | undefined;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The injectable host transport behind standard `wasi:sockets` and `wasi:sockets/ip-name-lookup`
|
|
3
|
+
* in the browser. Browsers have no raw sockets: an embedder supplies a provider, and every
|
|
4
|
+
* member is optional, so a provider may support only a subset. A missing member is a standard
|
|
5
|
+
* `not-supported` (`permanent-resolver-failure` for name lookup); it is never emulated.
|
|
6
|
+
*
|
|
7
|
+
* The standard host owns permissions, references and physical accounting. It checks the exact
|
|
8
|
+
* grant before calling a provider, and validates and copies everything a provider returns.
|
|
9
|
+
* Every promise below is physical work. The host tracks it until it settles, even after the
|
|
10
|
+
* guest's call was cancelled, so a provider must settle it once the work has really stopped,
|
|
11
|
+
* including releasing anything it produced late.
|
|
12
|
+
*/
|
|
13
|
+
import type { Duration, ErrorCode as SocketErrorCode, IpAddress, IpAddressFamily, IpSocketAddress } from "../wasi/wasi-sockets-types.js";
|
|
14
|
+
import type { ErrorCode as NameLookupErrorCode } from "../wasi/wasi-sockets-ip-name-lookup.js";
|
|
15
|
+
/** One named network provider, selected by the Orb's `wasi:sockets` import binding. */
|
|
16
|
+
export interface SocketProvider {
|
|
17
|
+
/** Synchronous: `tcp-socket.create`. Throw `SocketProviderError` for an unsupported family. */
|
|
18
|
+
readonly tcp?: {
|
|
19
|
+
create(family: IpAddressFamily): TcpBackend;
|
|
20
|
+
};
|
|
21
|
+
/** Synchronous: `udp-socket.create`. */
|
|
22
|
+
readonly udp?: {
|
|
23
|
+
create(family: IpAddressFamily): UdpBackend;
|
|
24
|
+
};
|
|
25
|
+
/** `resolve-addresses` for an ASCII (IDNA) domain name; IP literals never reach it. */
|
|
26
|
+
resolve?(name: string, signal: AbortSignal): Promise<readonly IpAddress[]>;
|
|
27
|
+
}
|
|
28
|
+
/** TCP socket options, by their standard getter and setter names. */
|
|
29
|
+
export interface TcpOptions {
|
|
30
|
+
keepAliveEnabled: boolean;
|
|
31
|
+
keepAliveIdleTime: Duration;
|
|
32
|
+
keepAliveInterval: Duration;
|
|
33
|
+
keepAliveCount: number;
|
|
34
|
+
hopLimit: number;
|
|
35
|
+
receiveBufferSize: bigint;
|
|
36
|
+
sendBufferSize: bigint;
|
|
37
|
+
/** Only after `listen`; before it, the host keeps the backlog as upstream Wasmtime does. */
|
|
38
|
+
listenBacklogSize: bigint;
|
|
39
|
+
}
|
|
40
|
+
/** UDP socket options, by their standard getter and setter names. */
|
|
41
|
+
export interface UdpOptions {
|
|
42
|
+
unicastHopLimit: number;
|
|
43
|
+
receiveBufferSize: bigint;
|
|
44
|
+
sendBufferSize: bigint;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Real option access. Getting and setting are supported independently; an absent method, or a
|
|
48
|
+
* thrown `not-supported`, is reported as `not-supported`. Setters receive values the host has
|
|
49
|
+
* already validated as WASI requires (for example, never 0 where 0 is invalid).
|
|
50
|
+
*/
|
|
51
|
+
export interface SocketOptions<O> {
|
|
52
|
+
getOption?<K extends keyof O>(name: K): O[K];
|
|
53
|
+
setOption?<K extends keyof O>(name: K, value: O[K]): void;
|
|
54
|
+
}
|
|
55
|
+
/** A provider-owned TCP socket. The host closes it once its last reference is released. */
|
|
56
|
+
export interface TcpBackend extends SocketOptions<TcpOptions> {
|
|
57
|
+
/** The actual bound local address, or `undefined` before any explicit or implicit bind. */
|
|
58
|
+
readonly local: IpSocketAddress | undefined;
|
|
59
|
+
/** Synchronous explicit bind; returns only once bound. Absent means `not-supported`. */
|
|
60
|
+
bind?(local: IpSocketAddress): void;
|
|
61
|
+
/** Synchronous; binds implicitly when unbound. Absent means `not-supported`. */
|
|
62
|
+
listen?(backlog: number): TcpListener;
|
|
63
|
+
/** Binds implicitly when unbound. */
|
|
64
|
+
connect(remote: IpSocketAddress, signal: AbortSignal): Promise<TcpConnection>;
|
|
65
|
+
/** The last reference was released; the promise is the physical acknowledgement. */
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/** The accept side of a listening `TcpBackend`; listening ends when that backend closes. */
|
|
69
|
+
export interface TcpListener {
|
|
70
|
+
/**
|
|
71
|
+
* Accept one connection. The host keeps at most one call pending and aborts `signal` when
|
|
72
|
+
* nobody will take its result; a connection delivered anyway is closed by the host.
|
|
73
|
+
*/
|
|
74
|
+
accept(signal: AbortSignal): Promise<{
|
|
75
|
+
socket: TcpBackend;
|
|
76
|
+
connection: TcpConnection;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
79
|
+
/** The byte directions of a connected socket. Each promise is a physical acknowledgement. */
|
|
80
|
+
export interface TcpConnection {
|
|
81
|
+
readonly remote: IpSocketAddress;
|
|
82
|
+
/** Read as the guest reads. `cancel()` is a read shutdown; empty chunks are allowed. */
|
|
83
|
+
readonly readable: ReadableStream<Uint8Array>;
|
|
84
|
+
/** `close()` is a write shutdown after the last write; `abort()` stops a failed send. */
|
|
85
|
+
readonly writable: WritableStream<Uint8Array>;
|
|
86
|
+
}
|
|
87
|
+
/** A provider-owned UDP socket. */
|
|
88
|
+
export interface UdpBackend extends SocketOptions<UdpOptions> {
|
|
89
|
+
readonly local: IpSocketAddress | undefined;
|
|
90
|
+
/** Synchronous explicit bind, also used for the implicit bind of `connect`. */
|
|
91
|
+
bind?(local: IpSocketAddress): void;
|
|
92
|
+
/** Binds implicitly when unbound; resolves once the datagram was handed to the network. */
|
|
93
|
+
send(data: Uint8Array, remote: IpSocketAddress, signal: AbortSignal): Promise<void>;
|
|
94
|
+
/** The next datagram from any peer; the host filters peers by grant and connection. */
|
|
95
|
+
receive(signal: AbortSignal): Promise<{
|
|
96
|
+
data: Uint8Array;
|
|
97
|
+
remote: IpSocketAddress;
|
|
98
|
+
}>;
|
|
99
|
+
close(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
/** A provider failure carrying a standard socket `error-code`. */
|
|
102
|
+
export declare class SocketProviderError extends Error {
|
|
103
|
+
readonly code: SocketErrorCode;
|
|
104
|
+
constructor(code: SocketErrorCode, message?: string);
|
|
105
|
+
}
|
|
106
|
+
/** A provider failure carrying a standard name lookup `error-code`. */
|
|
107
|
+
export declare class NameLookupError extends Error {
|
|
108
|
+
readonly code: NameLookupErrorCode;
|
|
109
|
+
constructor(code: NameLookupErrorCode, message?: string);
|
|
110
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Standard CLI over host-owned byte providers, with no inherited process environment. */
|
|
2
|
+
import type { CliOptions } from "../authoring/types.ts";
|
|
3
|
+
import { type Implementation, type StandardServices } from "./standard-streams.ts";
|
|
4
|
+
/** The promise owns the actual read until it returns, including after signal cancellation. */
|
|
5
|
+
export interface StdioInput {
|
|
6
|
+
read(maxBytes: number, signal: AbortSignal): Promise<Uint8Array | undefined>;
|
|
7
|
+
close?(): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/** The promise settles only after the physical write has returned. Calls are serialized. */
|
|
10
|
+
export interface StdioOutput {
|
|
11
|
+
write(bytes: Uint8Array, signal: AbortSignal): Promise<void>;
|
|
12
|
+
close?(): void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/** A fresh set per revision; an output provider can be shared by stdout and stderr. */
|
|
15
|
+
export interface StdioStreams {
|
|
16
|
+
readonly stdin?: StdioInput;
|
|
17
|
+
readonly stdout?: StdioOutput;
|
|
18
|
+
readonly stderr?: StdioOutput;
|
|
19
|
+
}
|
|
20
|
+
/** The embedding chooses adapters; Tembra owns their operation promises and final close. */
|
|
21
|
+
export type StdioProvider = (orb: string, configuration: Readonly<CliOptions>) => StdioStreams;
|
|
22
|
+
/** Reuse the revision's existing resource table and physical-work accounting for CLI streams. */
|
|
23
|
+
export declare class StandardCli {
|
|
24
|
+
#private;
|
|
25
|
+
readonly methods: Record<string, Implementation>;
|
|
26
|
+
constructor(configuration?: Readonly<CliOptions>, streams?: StdioStreams);
|
|
27
|
+
private exit;
|
|
28
|
+
private read;
|
|
29
|
+
private write;
|
|
30
|
+
/** Request cancellation first; physical promises remain accounted for until they return. */
|
|
31
|
+
retire(): void;
|
|
32
|
+
/** Close providers only after their physical operations have returned. */
|
|
33
|
+
close(host: StandardServices): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { utf8Decode, utf8Encode } from "./standard-utf8.ts";
|
|
2
|
+
export { utf8Decode, utf8Encode };
|
|
3
|
+
/** First packet byte, then the operation byte. */
|
|
4
|
+
export declare const STANDARD_PACKET = 0;
|
|
5
|
+
export declare const CALL = 0;
|
|
6
|
+
export declare const STREAM_READ = 1;
|
|
7
|
+
export declare const FUTURE_READ = 2;
|
|
8
|
+
export declare const DROP = 3;
|
|
9
|
+
/** Create a guest-writable input stream of a `TYPES` index; replies with its u64 identity. */
|
|
10
|
+
export declare const STREAM_NEW = 4;
|
|
11
|
+
/**
|
|
12
|
+
* Write one chunk into a guest-writable input stream; completes once the host accepted it. The
|
|
13
|
+
* reply is one status byte, `WRITE_ACCEPTED` or `WRITE_CLOSED`; every rejection is a failure.
|
|
14
|
+
*/
|
|
15
|
+
export declare const STREAM_WRITE = 5;
|
|
16
|
+
/** `STREAM_WRITE` status: the chunk was accepted. */
|
|
17
|
+
export declare const WRITE_ACCEPTED = 0;
|
|
18
|
+
/** `STREAM_WRITE` status: the reader closed the stream, an ordinary end of production. */
|
|
19
|
+
export declare const WRITE_CLOSED = 1;
|
|
20
|
+
/** Create a guest-writable future of a generated writable `TYPES` index. */
|
|
21
|
+
export declare const FUTURE_NEW = 6;
|
|
22
|
+
/** Resolve a guest-writable future with one typed payload. */
|
|
23
|
+
export declare const FUTURE_WRITE = 7;
|
|
24
|
+
/**
|
|
25
|
+
* Asynchronous, incoming HTTP callbacks only: publish the handler's
|
|
26
|
+
* `result<own<response>, error-code>` once. The host publishes the head at once and completes the
|
|
27
|
+
* operation only when the response delivery reached its end, so the callback stays alive while
|
|
28
|
+
* the response streams. The reply is empty.
|
|
29
|
+
*/
|
|
30
|
+
export declare const INGRESS_HEAD = 8;
|
|
31
|
+
/**
|
|
32
|
+
* Asynchronous, only in a callback whose export returns a whole `stream<u8>`: publish the guest
|
|
33
|
+
* writer `handle` as that result once. The caller receives the stream at once; the operation
|
|
34
|
+
* completes when the written bytes were delivered or the caller closed the stream, so the
|
|
35
|
+
* callback stays alive while it streams. The reply is empty.
|
|
36
|
+
*/
|
|
37
|
+
export declare const STREAM_RESULT = 9;
|
|
38
|
+
/**
|
|
39
|
+
* Asynchronous, native Rust facade only: call an Orb import whose whole result is a `stream<u8>`.
|
|
40
|
+
* The packet carries the length-prefixed UTF-8 JSON `reference.call` request; the host checks the
|
|
41
|
+
* import's signature before calling it. The reply is the `u64` handle of the readable stream,
|
|
42
|
+
* issued once the producer delivered its head.
|
|
43
|
+
*/
|
|
44
|
+
export declare const STREAM_IMPORT = 10;
|
|
45
|
+
/** Largest byte chunk either side moves through one stream read or write. */
|
|
46
|
+
export declare const STREAM_CHUNK: number;
|
|
47
|
+
/** The resource class name jco exposes for a canonical `interface#resource-name`. */
|
|
48
|
+
export declare function resourceClassName(name: string): string;
|
|
49
|
+
/** Handle conversion supplied by the side that owns handle identities. */
|
|
50
|
+
export interface HandleCodec {
|
|
51
|
+
/** Return the handle number for an outgoing value of `kind`. */
|
|
52
|
+
handle(kind: string, detail: unknown, value: unknown): number;
|
|
53
|
+
/** Return the language value for an incoming handle of `kind`. */
|
|
54
|
+
value(kind: string, detail: unknown, handle: number): unknown;
|
|
55
|
+
}
|
|
56
|
+
/** Growable little-endian writer. */
|
|
57
|
+
export declare class Writer {
|
|
58
|
+
#private;
|
|
59
|
+
u8(value: number): void;
|
|
60
|
+
u16(value: number): void;
|
|
61
|
+
u32(value: number): void;
|
|
62
|
+
u64(value: bigint): void;
|
|
63
|
+
/** Encode a host-issued identity exactly without a process-wide 32-bit ceiling. */
|
|
64
|
+
handle(value: number): void;
|
|
65
|
+
s64(value: bigint): void;
|
|
66
|
+
raw(bytes: Uint8Array): void;
|
|
67
|
+
bytes(bytes: Uint8Array): void;
|
|
68
|
+
/** Return the written bytes as one exact Uint8Array. */
|
|
69
|
+
finish(): Uint8Array;
|
|
70
|
+
}
|
|
71
|
+
/** Bounds-checked little-endian reader. */
|
|
72
|
+
export declare class Reader {
|
|
73
|
+
#private;
|
|
74
|
+
readonly source: Uint8Array;
|
|
75
|
+
constructor(source: Uint8Array);
|
|
76
|
+
u8(): number;
|
|
77
|
+
u16(): number;
|
|
78
|
+
u32(): number;
|
|
79
|
+
u64(): bigint;
|
|
80
|
+
/** Decode a u64 host identity only when JavaScript can represent it exactly. */
|
|
81
|
+
handle(): number;
|
|
82
|
+
s64(): bigint;
|
|
83
|
+
/** Copy one u32-prefixed byte list. */
|
|
84
|
+
bytes(): Uint8Array;
|
|
85
|
+
/** Copy exactly `length` bytes. */
|
|
86
|
+
raw(length: number): Uint8Array;
|
|
87
|
+
string(): string;
|
|
88
|
+
/** Bytes not yet read. */
|
|
89
|
+
get remaining(): number;
|
|
90
|
+
/** Refuse trailing bytes so one packet has exactly one meaning. */
|
|
91
|
+
end(): void;
|
|
92
|
+
}
|
|
93
|
+
/** Encode one value of generated type `index`. */
|
|
94
|
+
export declare function encode(w: Writer, index: number, value: any, handles: HandleCodec): void;
|
|
95
|
+
/** Decode one value of generated type `index`. */
|
|
96
|
+
export declare function decode(r: Reader, index: number, handles: HandleCodec): any;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser implementations of the generated `wasi:filesystem` methods over provider descriptors
|
|
3
|
+
* (`filesystem.ts`). Tembra checks descriptor kind, rights and lexical confinement before any
|
|
4
|
+
* provider call, then providers enforce their own scope as well. Error codes follow upstream
|
|
5
|
+
* Wasmtime: a wrong descriptor kind or a missing file right is `bad-descriptor` (`not-directory`
|
|
6
|
+
* for directory methods), and a directory mutation without `mutate-directory` is
|
|
7
|
+
* `not-permitted`.
|
|
8
|
+
*
|
|
9
|
+
* Browser providers have no settable timestamps, hard links or symbolic links: those methods
|
|
10
|
+
* report `unsupported` after their authority checks. `advise` is an advisory no-op, and
|
|
11
|
+
* `set-times`/`set-times-at` with `no-change` for both timestamps succeed without effect.
|
|
12
|
+
*/
|
|
13
|
+
import { type Descriptor as ProviderDescriptor, type DirectoryDescriptor, type FileDescriptor, type MountedFilesystem } from "./filesystem.ts";
|
|
14
|
+
import { type Implementation, type StandardResource, type StandardServices } from "./standard-streams.ts";
|
|
15
|
+
/** A mount granted to this revision. */
|
|
16
|
+
export interface StandardMount {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly writable: boolean;
|
|
19
|
+
readonly filesystem: MountedFilesystem;
|
|
20
|
+
}
|
|
21
|
+
/** jco `descriptor-flags`. */
|
|
22
|
+
interface DescriptorFlags {
|
|
23
|
+
read: boolean;
|
|
24
|
+
write: boolean;
|
|
25
|
+
fileIntegritySync: boolean;
|
|
26
|
+
dataIntegritySync: boolean;
|
|
27
|
+
requestedWriteSync: boolean;
|
|
28
|
+
mutateDirectory: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** A provider descriptor behind one host handle; streams and borrows retain it independently. */
|
|
31
|
+
export declare class HostDescriptor implements StandardResource {
|
|
32
|
+
#private;
|
|
33
|
+
readonly host: StandardServices;
|
|
34
|
+
readonly provider: ProviderDescriptor;
|
|
35
|
+
readonly flags: Readonly<DescriptorFlags>;
|
|
36
|
+
borrows: number;
|
|
37
|
+
constructor(host: StandardServices, provider: ProviderDescriptor, flags: Readonly<DescriptorFlags>);
|
|
38
|
+
get file(): FileDescriptor | undefined;
|
|
39
|
+
get directory(): DirectoryDescriptor | undefined;
|
|
40
|
+
/** `mutate-directory` for a directory. */
|
|
41
|
+
get mutable(): boolean;
|
|
42
|
+
retain(): void;
|
|
43
|
+
release(): void;
|
|
44
|
+
}
|
|
45
|
+
/** Build the filesystem implementations over this revision's granted mounts. */
|
|
46
|
+
export declare function filesystemMethods(mounts: () => readonly StandardMount[]): Readonly<Record<string, Implementation>>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type StandardMount } from "./standard-filesystem.ts";
|
|
2
|
+
import { type StdioStreams } from "./standard-cli.ts";
|
|
3
|
+
import { type HttpClient } from "./standard-http.ts";
|
|
4
|
+
import type { IngressExchange } from "./http-ingress.ts";
|
|
5
|
+
import { type SocketBindings } from "./standard-sockets.ts";
|
|
6
|
+
import type { CliOptions } from "../authoring/types.ts";
|
|
7
|
+
import { type StandardServices } from "./standard-streams.ts";
|
|
8
|
+
import { type ClockProvider, type RandomProvider, type SystemProviders } from "./standard-system.ts";
|
|
9
|
+
export type { StandardMount } from "./standard-filesystem.ts";
|
|
10
|
+
/** Encoded result and the handles it publishes only when resumed into the guest. */
|
|
11
|
+
export interface StandardDelivery {
|
|
12
|
+
readonly bytes: Uint8Array;
|
|
13
|
+
readonly issued: readonly number[];
|
|
14
|
+
/** Streams advanced by this reply; an unpublished read poisons its stream. */
|
|
15
|
+
readonly reads?: readonly number[] | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** Per-revision standard WASI host for the browser. */
|
|
18
|
+
export declare class StandardHost implements StandardServices {
|
|
19
|
+
#private;
|
|
20
|
+
readonly mounts: readonly StandardMount[];
|
|
21
|
+
readonly packetBytes: number;
|
|
22
|
+
readonly clocks: ClockProvider;
|
|
23
|
+
readonly random: RandomProvider;
|
|
24
|
+
/**
|
|
25
|
+
* @param allowed interfaces imported by this revision's checked contract
|
|
26
|
+
* @param mounts filesystem grants opened for this revision, in grant order
|
|
27
|
+
*/
|
|
28
|
+
constructor(allowed: ReadonlySet<string>, mounts: readonly StandardMount[], packetBytes: number, providers?: SystemProviders & {
|
|
29
|
+
cli?: CliOptions | undefined;
|
|
30
|
+
stdio?: StdioStreams | undefined;
|
|
31
|
+
/** Granted outgoing HTTP; absent means every `wasi:http/client#send` is denied. */
|
|
32
|
+
http?: HttpClient | undefined;
|
|
33
|
+
/** Providers and grants bound to this revision's `wasi:sockets` imports. */
|
|
34
|
+
sockets?: SocketBindings | undefined;
|
|
35
|
+
});
|
|
36
|
+
/** Whether the revision is retired; late physical results are then released, not issued. */
|
|
37
|
+
get closed(): boolean;
|
|
38
|
+
/** Live handles; used by acceptance to observe retirement. */
|
|
39
|
+
get size(): number;
|
|
40
|
+
/** Accepted, unconsumed guest input bytes; bounded by `INPUT_BUDGET`. */
|
|
41
|
+
get inputBytes(): number;
|
|
42
|
+
/** Physical operations and destructors still running; zero once retirement settled. */
|
|
43
|
+
get pending(): number;
|
|
44
|
+
/** Wait for actual provider work and destructors before releasing a callback or revision. */
|
|
45
|
+
settled(): Promise<void>;
|
|
46
|
+
physical<T>(signal: AbortSignal | undefined, operation: () => Promise<T>): Promise<T>;
|
|
47
|
+
cleanup(operation: () => unknown): void;
|
|
48
|
+
/** Serve one WIT-synchronous packet while the guest stack waits. */
|
|
49
|
+
sync(packet: Uint8Array): Uint8Array;
|
|
50
|
+
/** Serve one asynchronous packet owned by the callback whose `signal` is supplied. */
|
|
51
|
+
async(packet: Uint8Array, signal?: AbortSignal): Promise<StandardDelivery>;
|
|
52
|
+
/** Release resources from a reply that was never resumed into the guest. */
|
|
53
|
+
discard(delivery: Pick<StandardDelivery, "issued" | "reads">): void;
|
|
54
|
+
/**
|
|
55
|
+
* End of the current callback: every input writer it created and did not drop ends, so its
|
|
56
|
+
* consumer reaches end of stream (streams) or the abandoned error (futures) instead of
|
|
57
|
+
* waiting for a producer that is gone.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Begin serving one incoming request in the next callback: issue its `own<request>` handle.
|
|
61
|
+
* Invalid input is refused before anything is issued.
|
|
62
|
+
*/
|
|
63
|
+
beginIngress(exchange: IngressExchange): number;
|
|
64
|
+
/** The serving callback ended: whatever its delivery had not finished ends with `reason`. */
|
|
65
|
+
endIngress(reason: unknown): void;
|
|
66
|
+
endCallback(): void;
|
|
67
|
+
/** Retire the revision: drop every handle after physical provider work has settled. */
|
|
68
|
+
dispose(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/** Whether an interpreter packet is a binary standard packet rather than UTF-8 JSON. */
|
|
71
|
+
export declare function isStandardPacket(packet: Uint8Array): boolean;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous value semantics of outgoing standard `wasi:http@0.3.0` in the browser: the
|
|
3
|
+
* `fields`, `request-options`, `request` and `response` resources and request-target
|
|
4
|
+
* validation. Nothing here performs I/O or uses host services; bodies and transport lifetime
|
|
5
|
+
* live in the source or compiled transport adapter.
|
|
6
|
+
*
|
|
7
|
+
* Semantics follow pinned upstream `wasmtime-wasi-http` 51.0.0-rc.1 (`p3/host/types.rs`,
|
|
8
|
+
* `field_map.rs`, `p3/request.rs`): raw byte field values, explicit duplicates, the
|
|
9
|
+
* forbidden-field filter and the 128 KiB field budget, immutable headers/options views, and the
|
|
10
|
+
* same request target defaults and errors. Target hosts follow the native host's
|
|
11
|
+
* `Target::parse` rules.
|
|
12
|
+
*/
|
|
13
|
+
import type { ErrorCode, HeaderError, Method, RequestOptionsError, Result, Scheme } from "../wasi/wasi-http-types.js";
|
|
14
|
+
import { type HttpField, type HttpTimeouts } from "./http-provider.ts";
|
|
15
|
+
import type { HostFuture, OutputStream, StandardResource, StandardServices, FutureReader } from "./standard-streams.ts";
|
|
16
|
+
export type Outcome = Result<void, ErrorCode>;
|
|
17
|
+
export type Trailers = Result<HttpFields | undefined, ErrorCode>;
|
|
18
|
+
export declare const ok: <T>(val: T) => {
|
|
19
|
+
tag: "ok";
|
|
20
|
+
val: T;
|
|
21
|
+
};
|
|
22
|
+
export declare const err: <E>(val: E) => {
|
|
23
|
+
tag: "err";
|
|
24
|
+
val: E;
|
|
25
|
+
};
|
|
26
|
+
export declare const internal: (message: string) => ErrorCode;
|
|
27
|
+
export declare const done: Outcome;
|
|
28
|
+
/** ASCII digits of a validated `Content-Length` value. */
|
|
29
|
+
export declare const digits: (bytes: Uint8Array) => string;
|
|
30
|
+
/** Reference counting for resources a handle, a call or a value may hold independently. */
|
|
31
|
+
export declare abstract class HttpResource implements StandardResource {
|
|
32
|
+
#private;
|
|
33
|
+
borrows: number;
|
|
34
|
+
retain(): void;
|
|
35
|
+
release(): void;
|
|
36
|
+
/** The last user went away. */
|
|
37
|
+
protected close(): void;
|
|
38
|
+
}
|
|
39
|
+
/** `wasi:http/types#fields`: names in canonical lowercase, values as raw bytes in order. */
|
|
40
|
+
export declare class HttpFields extends HttpResource {
|
|
41
|
+
#private;
|
|
42
|
+
/** Standard `fields` constructor creates empty mutable fields. */
|
|
43
|
+
constructor(entries?: Map<string, readonly Uint8Array[]>, size?: number, mutable?: boolean);
|
|
44
|
+
/** `constructor`: empty and mutable. */
|
|
45
|
+
static create(): HttpFields;
|
|
46
|
+
/** `[static] from-list`: mutable; the first refused entry refuses the whole list. */
|
|
47
|
+
static fromList(entries: [string, Uint8Array][]): Result<HttpFields, HeaderError>;
|
|
48
|
+
/**
|
|
49
|
+
* Immutable fields received from a provider. Forbidden fields are stripped before they can
|
|
50
|
+
* reach the guest, as upstream does; a malformed name or value is the provider's error.
|
|
51
|
+
*/
|
|
52
|
+
static received(pairs: readonly HttpField[]): HttpFields;
|
|
53
|
+
/** Whether any field is present. */
|
|
54
|
+
get empty(): boolean;
|
|
55
|
+
/** An immutable snapshot, as upstream marks fields moved into a request or response. */
|
|
56
|
+
frozen(): HttpFields;
|
|
57
|
+
/** Every name/value pair in serialization order. */
|
|
58
|
+
/** Every name/value pair in serialization order; values are copies the caller owns. */
|
|
59
|
+
pairs(): [string, Uint8Array][];
|
|
60
|
+
get(name: string): Uint8Array[];
|
|
61
|
+
has(name: string): boolean;
|
|
62
|
+
set(name: string, values: Uint8Array[]): Result<void, HeaderError>;
|
|
63
|
+
delete(name: string): Result<void, HeaderError>;
|
|
64
|
+
getAndDelete(name: string): Result<Uint8Array[], HeaderError>;
|
|
65
|
+
append(name: string, value: Uint8Array): Result<void, HeaderError>;
|
|
66
|
+
copyAll(): [string, Uint8Array][];
|
|
67
|
+
/** A deep, mutable copy. */
|
|
68
|
+
clone(): HttpFields;
|
|
69
|
+
}
|
|
70
|
+
type OptionsResult = Result<void, RequestOptionsError>;
|
|
71
|
+
/** `wasi:http/types#request-options`; views obtained from a request are immutable. */
|
|
72
|
+
export declare class HttpRequestOptions extends HttpResource {
|
|
73
|
+
#private;
|
|
74
|
+
readonly mutable: boolean;
|
|
75
|
+
constructor(timeouts?: HttpTimeouts, mutable?: boolean);
|
|
76
|
+
/** The current timeouts, as a request keeps them once the options moved into it. */
|
|
77
|
+
get timeouts(): HttpTimeouts;
|
|
78
|
+
getConnectTimeout(): bigint | undefined;
|
|
79
|
+
/** Kept for the provider, which honors or refuses it at send. */
|
|
80
|
+
setConnectTimeout(duration: bigint | undefined): OptionsResult;
|
|
81
|
+
getFirstByteTimeout(): bigint | undefined;
|
|
82
|
+
setFirstByteTimeout(duration: bigint | undefined): OptionsResult;
|
|
83
|
+
getBetweenBytesTimeout(): bigint | undefined;
|
|
84
|
+
setBetweenBytesTimeout(duration: bigint | undefined): OptionsResult;
|
|
85
|
+
clone(): HttpRequestOptions;
|
|
86
|
+
}
|
|
87
|
+
/** Minimum lifetime contract shared by both transports. */
|
|
88
|
+
export interface HttpBody {
|
|
89
|
+
close(): void;
|
|
90
|
+
}
|
|
91
|
+
/** Source transport contents and trailers, consumed or dropped once. */
|
|
92
|
+
export interface Body extends HttpBody {
|
|
93
|
+
/** `consume-body`: the contents stream and trailers future; `res` reports the consumer. */
|
|
94
|
+
consume(host: StandardServices, res: FutureReader<Outcome>): [OutputStream, HostFuture];
|
|
95
|
+
/** Dropped unconsumed. */
|
|
96
|
+
close(): void;
|
|
97
|
+
}
|
|
98
|
+
/** State shared by requests and responses: immutable headers and a body that moves once. */
|
|
99
|
+
export declare abstract class Message<B extends HttpBody = Body> extends HttpResource {
|
|
100
|
+
#private;
|
|
101
|
+
readonly headers: HttpFields;
|
|
102
|
+
constructor(headers: HttpFields, body: B);
|
|
103
|
+
/** Move the body out; afterwards the message holds only its metadata. */
|
|
104
|
+
take(): B;
|
|
105
|
+
/** An immutable view; each call issues a new resource. */
|
|
106
|
+
getHeaders(): HttpFields;
|
|
107
|
+
protected close(): void;
|
|
108
|
+
}
|
|
109
|
+
/** A checked request target. */
|
|
110
|
+
export interface Target {
|
|
111
|
+
/** Canonical origin plus the WHATWG-normalized path, for grants and URL-based transports. */
|
|
112
|
+
readonly url: URL;
|
|
113
|
+
/** The validated raw origin-form path and query, as the guest set it. */
|
|
114
|
+
readonly pathWithQuery: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The native host's `Target::parse` host rules, applied to an authority that already passed
|
|
118
|
+
* `authority`: an IP literal (strict dotted quad, or any valid bracketed IPv6 spelling in its
|
|
119
|
+
* canonical form) or a lowercase LDH DNS name whose last label is not numeric (so URL parsers
|
|
120
|
+
* cannot read it as an IPv4 shorthand), plus a u16 port (leading zeros allowed, 0 refused).
|
|
121
|
+
*/
|
|
122
|
+
export declare function canonicalHost(authority: string, secure: boolean): {
|
|
123
|
+
name: string;
|
|
124
|
+
port: number;
|
|
125
|
+
} | undefined;
|
|
126
|
+
/** `wasi:http/types#request` built by the guest. */
|
|
127
|
+
export declare class HttpRequest<B extends HttpBody = Body> extends Message<B> {
|
|
128
|
+
#private;
|
|
129
|
+
readonly options: HttpTimeouts | undefined;
|
|
130
|
+
constructor(headers: HttpFields, options: HttpTimeouts | undefined, body: B);
|
|
131
|
+
getMethod(): Method;
|
|
132
|
+
/** Standard names normalize to their cases, as upstream's `http::Method` does. */
|
|
133
|
+
setMethod(method: Method): Result<void, void>;
|
|
134
|
+
getPathWithQuery(): string | undefined;
|
|
135
|
+
setPathWithQuery(path: string | undefined): Result<void, void>;
|
|
136
|
+
getScheme(): Scheme | undefined;
|
|
137
|
+
setScheme(scheme: Scheme | undefined): Result<void, void>;
|
|
138
|
+
getAuthority(): string | undefined;
|
|
139
|
+
setAuthority(value: string | undefined): Result<void, void>;
|
|
140
|
+
getOptions(): HttpRequestOptions | undefined;
|
|
141
|
+
/** The method as sent on the wire: a standard name in uppercase, or the extension token. */
|
|
142
|
+
get methodName(): string;
|
|
143
|
+
/**
|
|
144
|
+
* The checked target, with upstream's defaults and errors: no scheme means HTTPS, only
|
|
145
|
+
* HTTP(S) is supported, and authority and path are required. The host must pass the native
|
|
146
|
+
* host's `Target::parse` rules (see `canonicalHost`), otherwise the request is denied. `url`
|
|
147
|
+
* names the canonical origin the grant is checked against; `pathWithQuery` stays exactly as
|
|
148
|
+
* the guest validated it, independent of URL normalization.
|
|
149
|
+
*/
|
|
150
|
+
target(): Result<Target, ErrorCode>;
|
|
151
|
+
}
|
|
152
|
+
/** `wasi:http/types#response`: received from a provider, or built by the guest. */
|
|
153
|
+
export declare class HttpResponse<B extends HttpBody = Body> extends Message<B> {
|
|
154
|
+
#private;
|
|
155
|
+
constructor(headers: HttpFields, body: B, status?: number);
|
|
156
|
+
getStatusCode(): number;
|
|
157
|
+
setStatusCode(status: number): Result<void, void>;
|
|
158
|
+
}
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type HttpProvider } from "./http-provider.ts";
|
|
2
|
+
import { type Implementation } from "./standard-streams.ts";
|
|
3
|
+
/** Grant-checked selection of the host transport. */
|
|
4
|
+
export interface HttpClient {
|
|
5
|
+
/** The provider granted for exactly this URL's origin, or `undefined` to deny. */
|
|
6
|
+
provider(url: URL): HttpProvider | undefined;
|
|
7
|
+
}
|
|
8
|
+
/** Every generated `wasi:http` function, keyed for the standard host. */
|
|
9
|
+
export declare function httpMethods(client: HttpClient | undefined): Record<string, Implementation>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incoming standard `wasi:http@0.3.0` in the browser `StandardHost`: the request handed to an
|
|
3
|
+
* Orb's `wasi:http/handler#handle` and the delivery of the response it publishes.
|
|
4
|
+
*
|
|
5
|
+
* Ownership and ends:
|
|
6
|
+
* - The request is an `own` resource issued to the callback. Its body pulls the application's
|
|
7
|
+
* `AsyncIterable` only as the handler reads; the host calls the iterator's `return()` when the
|
|
8
|
+
* body is dropped early, when the client disconnects, and when the call ends.
|
|
9
|
+
* - The published response moves to the host. Its body is read only as the application reads.
|
|
10
|
+
* The delivery ends exactly once:
|
|
11
|
+
* - `eof`: the body and its trailers were read; the transmission result is `ok`, or the
|
|
12
|
+
* trailers' own error;
|
|
13
|
+
* - `disconnect`: the application stopped reading (`return()`); the handler sees
|
|
14
|
+
* `connection-terminated` on the transmission result, its request body is closed and its
|
|
15
|
+
* next write fails;
|
|
16
|
+
* - `abort`: the call was cancelled, timed out or the revision retired; same signals, and a
|
|
17
|
+
* pending or later read rejects with the reason.
|
|
18
|
+
* The handler's callback stays open until that end (see `INGRESS_HEAD`).
|
|
19
|
+
*/
|
|
20
|
+
import type { ErrorCode } from "../wasi/wasi-http-types.js";
|
|
21
|
+
import { type HttpField } from "./http-provider.ts";
|
|
22
|
+
import { type IngressExchange } from "./http-ingress.ts";
|
|
23
|
+
import { type Body, HttpRequest, HttpResponse, type Outcome } from "./standard-http-values.ts";
|
|
24
|
+
import { type FutureReader, HostFuture, OutputStream, type StandardServices } from "./standard-streams.ts";
|
|
25
|
+
/** The request contents, pulled from the application's iterable as the handler reads. */
|
|
26
|
+
declare class IncomingBody implements Body {
|
|
27
|
+
#private;
|
|
28
|
+
readonly cleanup: (operation: () => unknown) => void;
|
|
29
|
+
readonly source: AsyncIterable<Uint8Array> | null;
|
|
30
|
+
readonly trailers: PromiseLike<readonly HttpField[] | undefined> | undefined;
|
|
31
|
+
constructor(cleanup: (operation: () => unknown) => void, source: AsyncIterable<Uint8Array> | null, trailers: PromiseLike<readonly HttpField[] | undefined> | undefined);
|
|
32
|
+
consume(_host: StandardServices, res: FutureReader<Outcome>): [OutputStream, HostFuture];
|
|
33
|
+
/** The exchange ended: a pending or later read fails with `code`. */
|
|
34
|
+
terminate(code: ErrorCode): void;
|
|
35
|
+
/** Dropped unconsumed. */
|
|
36
|
+
close(): void;
|
|
37
|
+
}
|
|
38
|
+
/** One incoming request served by one handler callback. */
|
|
39
|
+
export declare class IngressCall {
|
|
40
|
+
#private;
|
|
41
|
+
readonly exchange: IngressExchange;
|
|
42
|
+
readonly body: IncomingBody;
|
|
43
|
+
constructor(exchange: IngressExchange, cleanup: (operation: () => unknown) => void);
|
|
44
|
+
/**
|
|
45
|
+
* The `own<request>` resource handed to the handler; invalid input is refused here, and the
|
|
46
|
+
* body this call already owns is closed with it.
|
|
47
|
+
*/
|
|
48
|
+
resource(): HttpRequest;
|
|
49
|
+
/**
|
|
50
|
+
* Publish the handler's result. A response's head is released at once; the returned promise
|
|
51
|
+
* resolves when its delivery ended. An error code is reported when the call settles.
|
|
52
|
+
*/
|
|
53
|
+
respond(host: StandardServices, result: {
|
|
54
|
+
tag: "ok";
|
|
55
|
+
val: HttpResponse;
|
|
56
|
+
} | {
|
|
57
|
+
tag: "err";
|
|
58
|
+
val: ErrorCode;
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
/** The callback ended or was cancelled: end the delivery and close the request body. */
|
|
61
|
+
end(reason: unknown): void;
|
|
62
|
+
}
|
|
63
|
+
export {};
|