@polyengine/runtime 0.1.0-pre.g633468a
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/LICENSE +202 -0
- package/README.md +23 -0
- package/esm/cabi/async_values.js +162 -0
- package/esm/cabi/bulk_lists.js +198 -0
- package/esm/cabi/context.js +42 -0
- package/esm/cabi/flatten.js +145 -0
- package/esm/cabi/float.js +67 -0
- package/esm/cabi/handles.js +253 -0
- package/esm/cabi/layout.js +149 -0
- package/esm/cabi/lift.js +196 -0
- package/esm/cabi/load.js +146 -0
- package/esm/cabi/lower.js +141 -0
- package/esm/cabi/memory.js +182 -0
- package/esm/cabi/mod.js +22 -0
- package/esm/cabi/store.js +186 -0
- package/esm/cabi/strings.js +336 -0
- package/esm/cabi/trap.js +38 -0
- package/esm/cabi/types.js +264 -0
- package/esm/cabi/values.js +64 -0
- package/esm/cache/core.js +156 -0
- package/esm/cache/dir.js +170 -0
- package/esm/cache/mod.js +4 -0
- package/esm/cache/web.js +136 -0
- package/esm/digest/digest.js +332 -0
- package/esm/digest/mod.js +3 -0
- package/esm/digest/verify.js +129 -0
- package/esm/embedder/casing.js +56 -0
- package/esm/embedder/copy.js +42 -0
- package/esm/embedder/errors.js +26 -0
- package/esm/embedder/imports.js +63 -0
- package/esm/embedder/instantiate.js +978 -0
- package/esm/embedder/mod.js +40 -0
- package/esm/embedder/resources.js +406 -0
- package/esm/embedder/streams.js +770 -0
- package/esm/embedder/values.js +450 -0
- package/esm/embedder/version.js +273 -0
- package/esm/exec/boundary.js +1902 -0
- package/esm/exec/executor.js +1004 -0
- package/esm/exec/host_streams.js +818 -0
- package/esm/exec/mod.js +4 -0
- package/esm/intrinsics/async_builtins.js +510 -0
- package/esm/intrinsics/context.js +90 -0
- package/esm/intrinsics/errors.js +13 -0
- package/esm/intrinsics/fact_calls.js +865 -0
- package/esm/intrinsics/mod.js +564 -0
- package/esm/intrinsics/stream_builtins.js +578 -0
- package/esm/intrinsics/transcode.js +443 -0
- package/esm/jspi/bridge.js +579 -0
- package/esm/jspi/mechanics.js +89 -0
- package/esm/jspi/mod.js +5 -0
- package/esm/jspi/suspending.js +15 -0
- package/esm/jspi/types.js +29 -0
- package/esm/package.json +3 -0
- package/esm/plan/format.js +5 -0
- package/esm/plan/loader.js +657 -0
- package/esm/plan/mod.js +3 -0
- package/esm/shim/mod.js +2 -0
- package/esm/shim/translator.js +94 -0
- package/esm/task/mod.js +483 -0
- package/esm/task/scheduler.js +1028 -0
- package/esm/task/streams.js +786 -0
- package/esm/task/subtask.js +135 -0
- package/esm/task/thread.js +255 -0
- package/esm/task/waitable.js +144 -0
- package/package.json +91 -0
- package/types/cabi/async_values.d.ts +35 -0
- package/types/cabi/bulk_lists.d.ts +18 -0
- package/types/cabi/context.d.ts +59 -0
- package/types/cabi/flatten.d.ts +14 -0
- package/types/cabi/float.d.ts +14 -0
- package/types/cabi/handles.d.ts +70 -0
- package/types/cabi/layout.d.ts +13 -0
- package/types/cabi/lift.d.ts +25 -0
- package/types/cabi/load.d.ts +14 -0
- package/types/cabi/lower.d.ts +10 -0
- package/types/cabi/memory.d.ts +58 -0
- package/types/cabi/mod.d.ts +15 -0
- package/types/cabi/store.d.ts +12 -0
- package/types/cabi/strings.d.ts +23 -0
- package/types/cabi/trap.d.ts +11 -0
- package/types/cabi/types.d.ts +206 -0
- package/types/cabi/values.d.ts +5 -0
- package/types/cache/core.d.ts +97 -0
- package/types/cache/dir.d.ts +6 -0
- package/types/cache/mod.d.ts +3 -0
- package/types/cache/web.d.ts +10 -0
- package/types/digest/digest.d.ts +17 -0
- package/types/digest/mod.d.ts +2 -0
- package/types/digest/verify.d.ts +48 -0
- package/types/embedder/casing.d.ts +40 -0
- package/types/embedder/copy.d.ts +24 -0
- package/types/embedder/errors.d.ts +11 -0
- package/types/embedder/imports.d.ts +47 -0
- package/types/embedder/instantiate.d.ts +88 -0
- package/types/embedder/mod.d.ts +11 -0
- package/types/embedder/resources.d.ts +158 -0
- package/types/embedder/streams.d.ts +202 -0
- package/types/embedder/values.d.ts +70 -0
- package/types/embedder/version.d.ts +85 -0
- package/types/exec/boundary.d.ts +360 -0
- package/types/exec/executor.d.ts +125 -0
- package/types/exec/host_streams.d.ts +165 -0
- package/types/exec/mod.d.ts +3 -0
- package/types/intrinsics/async_builtins.d.ts +69 -0
- package/types/intrinsics/context.d.ts +28 -0
- package/types/intrinsics/errors.d.ts +5 -0
- package/types/intrinsics/fact_calls.d.ts +120 -0
- package/types/intrinsics/mod.d.ts +187 -0
- package/types/intrinsics/stream_builtins.d.ts +113 -0
- package/types/intrinsics/transcode.d.ts +21 -0
- package/types/jspi/bridge.d.ts +227 -0
- package/types/jspi/mechanics.d.ts +50 -0
- package/types/jspi/mod.d.ts +3 -0
- package/types/jspi/suspending.d.ts +1 -0
- package/types/jspi/types.d.ts +26 -0
- package/types/plan/format.d.ts +369 -0
- package/types/plan/loader.d.ts +113 -0
- package/types/plan/mod.d.ts +2 -0
- package/types/shim/mod.d.ts +1 -0
- package/types/shim/translator.d.ts +55 -0
- package/types/task/mod.d.ts +257 -0
- package/types/task/scheduler.d.ts +421 -0
- package/types/task/streams.d.ts +370 -0
- package/types/task/subtask.d.ts +96 -0
- package/types/task/thread.d.ts +73 -0
- package/types/task/waitable.d.ts +67 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { ValType } from "../cabi/types.js";
|
|
2
|
+
import type { ComponentValue } from "../cabi/types.js";
|
|
3
|
+
import { type HostFuture, type HostStream } from "../exec/host_streams.js";
|
|
4
|
+
import { ErrorContext as InternalErrorContext } from "../task/mod.js";
|
|
5
|
+
/** `Chunk<u8>` is a `Uint8Array`; every other element type chunks as `T[]`. */
|
|
6
|
+
export type Chunk<T> = T extends number ? Uint8Array | T[] : T[];
|
|
7
|
+
/** Per-element adaptation, supplied by the value adapter. */
|
|
8
|
+
export interface ElemCodec<T> {
|
|
9
|
+
readonly element: ValType | null;
|
|
10
|
+
/** internal component value -> conventions value */
|
|
11
|
+
toHost(v: ComponentValue): T;
|
|
12
|
+
/** conventions value -> internal component value */
|
|
13
|
+
fromHost(v: T): ComponentValue;
|
|
14
|
+
/**
|
|
15
|
+
* Destroy a LOWERED element the reader will never take (amendment A13);
|
|
16
|
+
* present only for element types that hold resources (`own<R>`), where
|
|
17
|
+
* abandonment without destruction is a leak.
|
|
18
|
+
*/
|
|
19
|
+
readonly release?: (lowered: ComponentValue) => void;
|
|
20
|
+
/** Optional site name (`import 'x'.f`, `export 'i#f'`) for diagnostics. */
|
|
21
|
+
readonly where?: string;
|
|
22
|
+
}
|
|
23
|
+
export { StreamProducerError } from "@polyengine/protocol";
|
|
24
|
+
/** True for `stream<u8>` / `future<u8>`, whose chunks are `Uint8Array`. */
|
|
25
|
+
export declare function isU8Element(element: ValType | null): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* A stream handle.
|
|
28
|
+
*
|
|
29
|
+
* `read` returning an empty chunk is end-of-stream, exactly as the contract
|
|
30
|
+
* spells it; `readable()` and the async iterator are built on it.
|
|
31
|
+
*/
|
|
32
|
+
export declare class Stream<T> {
|
|
33
|
+
#private;
|
|
34
|
+
private constructor();
|
|
35
|
+
/** Wrap a stream value that was lifted out of a guest. */
|
|
36
|
+
static fromLifted<T>(value: ComponentValue, codec: ElemCodec<T>): Stream<T>;
|
|
37
|
+
/** Wrap a freshly created host-owned stream of a known element type. */
|
|
38
|
+
static fromHostStream<T>(host: HostStream<T>, codec: ElemCodec<T>): Stream<T>;
|
|
39
|
+
/**
|
|
40
|
+
* `Stream.create<T>(): { stream, writer }` — the writer-side host end the
|
|
41
|
+
* contract names.
|
|
42
|
+
*
|
|
43
|
+
* The element type is deliberately NOT a parameter: the embedder does not
|
|
44
|
+
* have one (a `ValType` is a runtime-internal shape) and the *lowering site*
|
|
45
|
+
* always does. So the shared object is created lazily, at the moment the
|
|
46
|
+
* stream is passed to a guest, and writer operations issued before that park
|
|
47
|
+
* until then. A stream created and written but never passed anywhere simply
|
|
48
|
+
* never completes — the same honest hang the low-level layer documents.
|
|
49
|
+
*/
|
|
50
|
+
static create<T>(): {
|
|
51
|
+
stream: Stream<T>;
|
|
52
|
+
writer: StreamWriter<T>;
|
|
53
|
+
};
|
|
54
|
+
/** @internal — bind a lazily created stream to the lowering site's type. */
|
|
55
|
+
bindElement(codec: ElemCodec<T>): void;
|
|
56
|
+
/** @internal — resolve once this handle has a shared object. */
|
|
57
|
+
whenBound(): Promise<void>;
|
|
58
|
+
/** @internal */
|
|
59
|
+
get bound(): boolean;
|
|
60
|
+
/** @internal — the shared value to hand to a lowering site. */
|
|
61
|
+
takeValue(codec: ElemCodec<T>): ComponentValue;
|
|
62
|
+
/** @internal */
|
|
63
|
+
get codec(): ElemCodec<T> | null;
|
|
64
|
+
/** Low-level read: up to `max` elements; an empty chunk means end-of-stream. */
|
|
65
|
+
read(max: number): Promise<Chunk<T>>;
|
|
66
|
+
/**
|
|
67
|
+
* Cancel an in-flight `read` (R-fix review advisory 1).
|
|
68
|
+
*
|
|
69
|
+
* #97, DELIBERATE AND PINNED: the cancelled `read` resolves with whatever
|
|
70
|
+
* had already arrived — typically the empty chunk, which this layer also
|
|
71
|
+
* uses as end-of-stream (`read`'s contract, and hence `readable()` and the
|
|
72
|
+
* async iterator, which close on it). **A cancelled read is therefore
|
|
73
|
+
* indistinguishable from EOS at this layer.** Kept as-is rather than given
|
|
74
|
+
* a distinct signal: the caller of `cancelRead()` is the same code that
|
|
75
|
+
* observes the read's result, so it already knows which happened, and only
|
|
76
|
+
* that caller can reach the state. See exec/host_streams.ts
|
|
77
|
+
* `HostReadableEnd.cancelRead` for the mechanism.
|
|
78
|
+
*/
|
|
79
|
+
cancelRead(): void;
|
|
80
|
+
drop(): void;
|
|
81
|
+
/**
|
|
82
|
+
* @internal — teardown after a trapping import abandoned this handle
|
|
83
|
+
* (#66, instantiate.ts `releaseAsyncArgs`). Unlike `drop()`, this goes
|
|
84
|
+
* through `dropSharedForTeardown`, whose parked-side discipline never
|
|
85
|
+
* wakes the about-to-be-poisoned caller (review B2: a plain drop queued a
|
|
86
|
+
* DROPPED event into the trapping instance's waitables, and a later
|
|
87
|
+
* driving loop asserted on the corpse).
|
|
88
|
+
*
|
|
89
|
+
* The arm is released on this path too (#162, amendment A15): the wrapper's
|
|
90
|
+
* `HostActivity` now closes through the shared object's drop observers,
|
|
91
|
+
* which `dropSharedForTeardown` fires unconditionally — so a teardown with
|
|
92
|
+
* nothing parked no longer leaves the arm outliving the stream. (This
|
|
93
|
+
* paragraph previously recorded that asymmetry as a known, non-blocking
|
|
94
|
+
* review advisory.)
|
|
95
|
+
*/
|
|
96
|
+
dropForTeardown(): void;
|
|
97
|
+
[Symbol.dispose](): void;
|
|
98
|
+
/** Web-native view: `ReadableStream<Chunk<T>>`. */
|
|
99
|
+
readable(): ReadableStream<Chunk<T>>;
|
|
100
|
+
[Symbol.asyncIterator](): AsyncIterator<Chunk<T>>;
|
|
101
|
+
}
|
|
102
|
+
/** Writer half of `Stream.create()`. */
|
|
103
|
+
export declare class StreamWriter<T> {
|
|
104
|
+
#private;
|
|
105
|
+
constructor(stream: Stream<T>);
|
|
106
|
+
/**
|
|
107
|
+
* Offer values; resolves with how many the reader took.
|
|
108
|
+
*
|
|
109
|
+
* `Chunk<T>` mirrors the read side: a u8 stream accepts a `Uint8Array`
|
|
110
|
+
* (taken as already-lowered bytes), and a plain array of any element type
|
|
111
|
+
* is lowered per element. u8 chunks travel as `Uint8Array` all the way to
|
|
112
|
+
* the CABI store's bulk path (issue #54) — which makes a `Uint8Array`
|
|
113
|
+
* chunk a BORROW until the returned promise settles; mutating it in that
|
|
114
|
+
* window is misuse. Plain-array chunks are lowered (copied) up front.
|
|
115
|
+
*/
|
|
116
|
+
write(values: Chunk<T>): Promise<number>;
|
|
117
|
+
/** Offer values until all are taken or the reader goes away. */
|
|
118
|
+
writeAll(values: Chunk<T>): Promise<number>;
|
|
119
|
+
cancelWrite(): void;
|
|
120
|
+
/** End-of-stream. */
|
|
121
|
+
close(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
/** @internal — publish the host end for `StreamWriter` (see `hostOf`). */
|
|
124
|
+
export declare function publishHostStream<T>(s: Stream<T>, h: HostStream<T>): void;
|
|
125
|
+
/**
|
|
126
|
+
* A future handle. `await`able directly (`PromiseLike`), and droppable.
|
|
127
|
+
*
|
|
128
|
+
* A future whose write end dropped without ever writing rejects with
|
|
129
|
+
* `DroppedError` — not `undefined`, which `future<void>` legitimately yields.
|
|
130
|
+
*/
|
|
131
|
+
export declare class Future<T> implements PromiseLike<T> {
|
|
132
|
+
#private;
|
|
133
|
+
private constructor();
|
|
134
|
+
static fromLifted<T>(value: ComponentValue, codec: ElemCodec<T>): Future<T>;
|
|
135
|
+
static fromHostFuture<T>(host: HostFuture<T>, codec: ElemCodec<T>): Future<T>;
|
|
136
|
+
/**
|
|
137
|
+
* A future that is still in flight: the guest call that produces it has not
|
|
138
|
+
* resolved yet.
|
|
139
|
+
*
|
|
140
|
+
* CONTRACT (contracts/embedder-api.md): §"Functions and async" makes every
|
|
141
|
+
* export Promise-shaped, and §"Streams and futures" makes `Future<T>` a
|
|
142
|
+
* `PromiseLike<T>`. For an export whose *result* is a `future<T>` those two
|
|
143
|
+
* collide irreducibly: JS promise resolution unconditionally adopts a
|
|
144
|
+
* thenable, so `await someExport()` can never hand back a thenable handle —
|
|
145
|
+
* it hands back the value the handle would have yielded. Conservative
|
|
146
|
+
* reading, implemented here: the export returns the handle **eagerly** (it
|
|
147
|
+
* is itself PromiseLike, so `await` still works and still yields `T`), which
|
|
148
|
+
* keeps `drop()`/`cancel()` reachable for a caller that does not await. The
|
|
149
|
+
* alternative — resolving a Promise *to* the handle — is not expressible.
|
|
150
|
+
* Flagged in the C2 report.
|
|
151
|
+
*/
|
|
152
|
+
static deferred<T>(pending: Promise<ComponentValue>, codec: ElemCodec<T>): Future<T>;
|
|
153
|
+
/** @internal */
|
|
154
|
+
adopt(h: HostFuture<T>): void;
|
|
155
|
+
/** @internal */
|
|
156
|
+
takeValue(): ComponentValue;
|
|
157
|
+
then<R1 = T, R2 = never>(onfulfilled?: ((v: T) => R1 | PromiseLike<R1>) | null, onrejected?: ((e: unknown) => R2 | PromiseLike<R2>) | null): PromiseLike<R1 | R2>;
|
|
158
|
+
cancel(): void;
|
|
159
|
+
/**
|
|
160
|
+
* Release this future handle. Total and idempotent (#90): it never throws,
|
|
161
|
+
* and calling it twice — or after `Symbol.dispose` — is a no-op.
|
|
162
|
+
*
|
|
163
|
+
* Dropping a future the host never wrote to, once the guest already holds
|
|
164
|
+
* its readable end, is **abandonment**: the guest's reader can never be
|
|
165
|
+
* satisfied, so it is armed with a trap at its rendezvous point rather than
|
|
166
|
+
* being handed a value-less completion (exec/host_streams.ts
|
|
167
|
+
* `HostFuture.drop`, task/streams.ts `abandonSharedFuture`; the spec keeps
|
|
168
|
+
* that state unreachable by trapping the early writable drop,
|
|
169
|
+
* definitions.py:1183-1184). Write-then-drop is the normal path and is
|
|
170
|
+
* unaffected; a future no guest ever saw is plain cleanup.
|
|
171
|
+
*/
|
|
172
|
+
drop(): void;
|
|
173
|
+
/** @internal — see `Stream.dropForTeardown` (#66). */
|
|
174
|
+
dropForTeardown(): void;
|
|
175
|
+
[Symbol.dispose](): void;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* `error-context` as the contract spells it: `{ readonly message: string }`.
|
|
179
|
+
* The internal value is `task/streams.ts`'s `ErrorContext` (debug message
|
|
180
|
+
* only, per definitions.py).
|
|
181
|
+
*/
|
|
182
|
+
export declare class ErrorContext {
|
|
183
|
+
readonly message: string;
|
|
184
|
+
/** @internal — the internal value, preserved so it can be lowered back. */
|
|
185
|
+
readonly internal: InternalErrorContext;
|
|
186
|
+
constructor(internal: InternalErrorContext);
|
|
187
|
+
}
|
|
188
|
+
/** Anything the layer accepts where a guest expects `stream<T>`. */
|
|
189
|
+
export type StreamSource<T> = Stream<T> | ReadableStream<T[] | Uint8Array | T> | AsyncIterable<T[] | Uint8Array | T> | Iterable<T>;
|
|
190
|
+
/** Anything the layer accepts where a guest expects `future<T>`. */
|
|
191
|
+
export type FutureSource<T> = Future<T> | PromiseLike<T> | T;
|
|
192
|
+
/**
|
|
193
|
+
* Adapt a producer to a lowered `stream<T>` value, and own the pumping.
|
|
194
|
+
*
|
|
195
|
+
* The driving arm auto-closes on end (the pump drops the write end when the
|
|
196
|
+
* producer is exhausted) and on `DROPPED` (host_streams settles the activity
|
|
197
|
+
* arm) — R-fix review advisory 2, the deadlock-masking activity-lifetime
|
|
198
|
+
* footgun.
|
|
199
|
+
*/
|
|
200
|
+
export declare function lowerStreamSource<T>(src: StreamSource<T>, codec: ElemCodec<T>): ComponentValue;
|
|
201
|
+
/** Adapt a `Promise`/`Future`/plain value to a lowered `future<T>` value. */
|
|
202
|
+
export declare function lowerFutureSource<T>(src: FutureSource<T>, codec: ElemCodec<T>): ComponentValue;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ComponentValue, ValType } from "../cabi/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The parts of adaptation that need instance state: resources (identity
|
|
4
|
+
* mapping, ownership) and the borrow scope of the call in flight.
|
|
5
|
+
*/
|
|
6
|
+
export interface ValueBridge {
|
|
7
|
+
/** A guest handed the host an `own<R>`; the host now owns it. */
|
|
8
|
+
liftOwn(rep: number, t: ValType & {
|
|
9
|
+
kind: "own";
|
|
10
|
+
}): unknown;
|
|
11
|
+
/** A guest handed the host a `borrow<R>`, valid only for this call. */
|
|
12
|
+
liftBorrow(rep: number, t: ValType & {
|
|
13
|
+
kind: "borrow";
|
|
14
|
+
}, scope: BorrowScope): unknown;
|
|
15
|
+
/** The host is passing an `own<R>` (transfer). */
|
|
16
|
+
lowerOwn(v: unknown, t: ValType & {
|
|
17
|
+
kind: "own";
|
|
18
|
+
}): number;
|
|
19
|
+
/** The host is passing a `borrow<R>` (no transfer). */
|
|
20
|
+
lowerBorrow(v: unknown, t: ValType & {
|
|
21
|
+
kind: "borrow";
|
|
22
|
+
}): number;
|
|
23
|
+
/**
|
|
24
|
+
* Destroy a LOWERED `own<R>` the guest will never receive (amendment
|
|
25
|
+
* A13: a stream element the producer lowered but the reader never took).
|
|
26
|
+
* Runs the resource's destructor — for a host-implemented R the
|
|
27
|
+
* instance's `[Symbol.dispose]`, for a guest-implemented R the guest
|
|
28
|
+
* dtor — exactly as if the guest had taken the handle and dropped it.
|
|
29
|
+
*/
|
|
30
|
+
dropOwn(rep: number, t: ValType & {
|
|
31
|
+
kind: "own";
|
|
32
|
+
}): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wrappers materialized for `borrow<R>` arguments of one call. The contract:
|
|
36
|
+
* "instance valid **only during the call** (retention throws)", so the scope
|
|
37
|
+
* invalidates them when the call returns.
|
|
38
|
+
*/
|
|
39
|
+
export declare class BorrowScope {
|
|
40
|
+
#private;
|
|
41
|
+
add(f: () => void): void;
|
|
42
|
+
end(): void;
|
|
43
|
+
}
|
|
44
|
+
/** A no-op scope for positions where no borrow can appear. */
|
|
45
|
+
export declare const NO_BORROWS: BorrowScope;
|
|
46
|
+
/**
|
|
47
|
+
* Refuse two labels in one scope that camelCase to the same JS name.
|
|
48
|
+
*
|
|
49
|
+
* `read-only` and `readOnly` are distinct WIT labels but one JS property, so
|
|
50
|
+
* one would silently shadow the other at the boundary — values corrupted with
|
|
51
|
+
* no diagnostic anywhere. Contract principle 2: footguns are design defects.
|
|
52
|
+
*/
|
|
53
|
+
export declare function checkNoCollisions(key: object, labels: string[], what: string): void;
|
|
54
|
+
export interface AdapterOptions {
|
|
55
|
+
bridge: ValueBridge;
|
|
56
|
+
/** Names the site in error messages (`import 'wasi:x/y'.f`, param 2). */
|
|
57
|
+
where: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Adapt one lifted value to its conventions shape.
|
|
61
|
+
*
|
|
62
|
+
* `inOption` implements the contract's option rule: the *outermost* option in
|
|
63
|
+
* a chain maps to `T | undefined`; an option nested **directly inside another
|
|
64
|
+
* option** boxes as `{ kind: "some", value } | { kind: "none" }`. Only option maps
|
|
65
|
+
* to `undefined`, so this is the only ambiguity, and the flag is set only when
|
|
66
|
+
* descending through an option's payload — every other constructor resets it.
|
|
67
|
+
*/
|
|
68
|
+
export declare function toHost(v: ComponentValue, t: ValType, o: AdapterOptions, scope?: BorrowScope, inOption?: boolean): unknown;
|
|
69
|
+
export declare function fromHost(v: unknown, t: ValType, o: AdapterOptions, inOption?: boolean): ComponentValue;
|
|
70
|
+
export declare function describe(v: unknown): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Fault in how the embedder registered its imports. */
|
|
2
|
+
export declare class ImportRegistrationError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
/** Fault resolving a component's import against the registered providers. */
|
|
6
|
+
export declare class ImportResolutionError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
/** A parsed `name@version` interface id. `version` is null when unversioned. */
|
|
10
|
+
export interface ParsedId {
|
|
11
|
+
/** The id with the version suffix removed (`wasi:clocks/monotonic-clock`). */
|
|
12
|
+
base: string;
|
|
13
|
+
/** The raw version text, or null. */
|
|
14
|
+
version: string | null;
|
|
15
|
+
/** Parsed semver, or null when unversioned / unparseable. */
|
|
16
|
+
semver: Semver | null;
|
|
17
|
+
}
|
|
18
|
+
export interface Semver {
|
|
19
|
+
major: number;
|
|
20
|
+
minor: number;
|
|
21
|
+
patch: number;
|
|
22
|
+
/** Dot-separated prerelease identifiers; empty when there is none. */
|
|
23
|
+
prerelease: string[];
|
|
24
|
+
build: string | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Split an interface id at its LAST `@`.
|
|
28
|
+
*
|
|
29
|
+
* Last, not first: a package name may not contain `@`, but being explicit
|
|
30
|
+
* costs nothing and matches how wasmtime splits (`name.rfind('@')`).
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseInterfaceId(id: string): ParsedId;
|
|
33
|
+
export declare function parseSemver(v: string): Semver | null;
|
|
34
|
+
/**
|
|
35
|
+
* The compatibility-track key of an interface id, or null when the id belongs
|
|
36
|
+
* to no track (unversioned, unparseable, prerelease, or `0.0.z`).
|
|
37
|
+
*
|
|
38
|
+
* Mirrors wasmtime `alternate_lookup_key`:
|
|
39
|
+
* - `major > 0` -> `base@{major}` (`1.2.3` -> `@1`)
|
|
40
|
+
* - `major == 0, minor > 0`-> `base@0.{minor}` (`0.2.6` -> `@0.2`)
|
|
41
|
+
* - `0.0.z` -> none (patch-only versions are compatible with
|
|
42
|
+
* nothing)
|
|
43
|
+
* - any prerelease -> none (wasmtime treats prereleases as
|
|
44
|
+
* exact-only; the historic WASI `0.2.0-rc`
|
|
45
|
+
* snapshots are exactly the phenomenon this
|
|
46
|
+
* exclusion protects — same track on paper,
|
|
47
|
+
* divergent function sets in fact)
|
|
48
|
+
*
|
|
49
|
+
* Build metadata is ignored for track purposes (`2.1.2+abc` -> `@2`), as
|
|
50
|
+
* semver requires.
|
|
51
|
+
*/
|
|
52
|
+
export declare function trackKey(id: string): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Is `id` itself spelled as a *track key* (`ns:pkg/iface@0.2`, `…@1`)?
|
|
55
|
+
*
|
|
56
|
+
* Note `semver::Version::parse("0.2")` fails — which is exactly why the two
|
|
57
|
+
* mechanisms compose: a track key can never be mistaken for a full version,
|
|
58
|
+
* and a full version never generates a track key equal to itself.
|
|
59
|
+
*/
|
|
60
|
+
export declare function asTrackKeySpelling(id: string): string | null;
|
|
61
|
+
/**
|
|
62
|
+
* Registration table over the embedder's imports record.
|
|
63
|
+
*
|
|
64
|
+
* Only the *interface-id* keys participate: world-level bare imports live at
|
|
65
|
+
* the record's top level under camelCase names and are matched by exact
|
|
66
|
+
* string equality, never by version machinery.
|
|
67
|
+
*/
|
|
68
|
+
export declare class ImportResolver {
|
|
69
|
+
#private;
|
|
70
|
+
constructor(record: Record<string, unknown>);
|
|
71
|
+
/** Every registered key, in registration order. */
|
|
72
|
+
keys(): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Resolve one component import name. Returns `undefined` when nothing is
|
|
75
|
+
* registered for it; throws when a registration *nearly* matches in a way
|
|
76
|
+
* the contract bans (unversioned folding), because silently reporting
|
|
77
|
+
* "not provided" would hide the real mistake.
|
|
78
|
+
*/
|
|
79
|
+
resolve(id: string): {
|
|
80
|
+
key: string;
|
|
81
|
+
value: unknown;
|
|
82
|
+
} | undefined;
|
|
83
|
+
}
|
|
84
|
+
/** Semver precedence, prerelease-aware (semver.org §11). */
|
|
85
|
+
export declare function compareSemver(a: Semver, b: Semver): number;
|