@solidrt/flux-types 0.0.25 → 0.0.27
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 +2 -1
- package/gui/gpu.d.ts +59 -0
- package/index.d.ts +2 -0
- package/modules/ffi.d.ts +63 -0
- package/modules/fs.d.ts +8 -0
- package/modules/http.d.ts +39 -0
- package/modules/p2p.d.ts +14 -1
- package/modules/wasm.d.ts +87 -0
- package/package.json +1 -1
- package/standards/fetch.d.ts +6 -0
package/README.md
CHANGED
|
@@ -46,7 +46,8 @@ rely on must be named.
|
|
|
46
46
|
|
|
47
47
|
- `Flux` global (`version`, `capabilities`).
|
|
48
48
|
- `flux:*` modules: `flux:http`, `flux:fs`, `flux:sqlite`, `flux:subprocess`,
|
|
49
|
-
`flux:p2p`, `flux:process`, `flux:path`,
|
|
49
|
+
`flux:p2p`, `flux:net`, `flux:mdns`, `flux:process`, `flux:path`, `flux:wasm`, `flux:ffi`,
|
|
50
|
+
and (on a gui-enabled runtime)
|
|
50
51
|
`flux:camera`, `flux:microphone`, `flux:audio`, `flux:gpu`.
|
|
51
52
|
- Web-standard globals: `console`, `fetch` + `Headers`/`Request`/`Response`,
|
|
52
53
|
`setTimeout`/`setInterval`/`queueMicrotask`, `performance`, `WebSocket`,
|
package/gui/gpu.d.ts
CHANGED
|
@@ -36,6 +36,65 @@ declare module "flux:gpu" {
|
|
|
36
36
|
): number
|
|
37
37
|
/** Update a shader texture's float uniforms by name and re-render it. */
|
|
38
38
|
export function setShaderParams(id: number, params: Record<string, number>): void
|
|
39
|
+
|
|
40
|
+
export type Topology = "points" | "lines" | "line-strip" | "triangles" | "triangle-strip"
|
|
41
|
+
/**
|
|
42
|
+
* One float attribute of an interleaved vertex. The attribute list's order
|
|
43
|
+
* defines the byte layout; locations are resolved by name against the
|
|
44
|
+
* vertex shader's `in` declarations.
|
|
45
|
+
*/
|
|
46
|
+
export type VertexAttribute = { name: string; format: "f32" | "vec2" | "vec3" | "vec4" }
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Compile a GLSL ES vertex+fragment pipeline into an offscreen texture of
|
|
50
|
+
* the given size and render it once. Sources without a `#version` line get
|
|
51
|
+
* a 300 es preamble declaring `iResolution`/`iTime` (no vUV: varyings are
|
|
52
|
+
* the pipeline's own). `attributes` describes one interleaved vertex in
|
|
53
|
+
* `buffer` (a {@link createBuffer} id); omit both for attributeless
|
|
54
|
+
* rendering via gl_VertexID. `vertexCount` defaults to the whole buffer
|
|
55
|
+
* (buffer size / vertex stride). With `depth: true` the pipeline gets a
|
|
56
|
+
* private depth buffer, cleared and tested on every render. The target is
|
|
57
|
+
* cleared to `clearColor` (default transparent black) before each draw.
|
|
58
|
+
* Returns a texture id: display it with `<texture src>`, drive uniforms via
|
|
59
|
+
* the `params` prop or {@link setShaderParams}, destroy with
|
|
60
|
+
* {@link destroyTexture}.
|
|
61
|
+
*/
|
|
62
|
+
export function createPipeline(
|
|
63
|
+
vertexSrc: string,
|
|
64
|
+
fragmentSrc: string,
|
|
65
|
+
width: number,
|
|
66
|
+
height: number,
|
|
67
|
+
opts?: {
|
|
68
|
+
params?: Record<string, number>
|
|
69
|
+
textures?: Record<string, number>
|
|
70
|
+
attributes?: VertexAttribute[]
|
|
71
|
+
buffer?: number
|
|
72
|
+
topology?: Topology
|
|
73
|
+
vertexCount?: number
|
|
74
|
+
depth?: boolean
|
|
75
|
+
clearColor?: [number, number, number, number]
|
|
76
|
+
},
|
|
77
|
+
): number
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create a vertex buffer from raw bytes (interleave attribute data to match
|
|
81
|
+
* the pipeline's attribute list). Buffer ids are their own space, separate
|
|
82
|
+
* from texture ids.
|
|
83
|
+
*/
|
|
84
|
+
export function createBuffer(data: Uint8Array): number
|
|
85
|
+
/**
|
|
86
|
+
* Overwrite part of a vertex buffer at `byteOffset` (default 0), within the
|
|
87
|
+
* size it was created with. Pipelines drawing from the buffer re-render
|
|
88
|
+
* with their last-applied params.
|
|
89
|
+
*/
|
|
90
|
+
export function writeBuffer(id: number, data: Uint8Array, byteOffset?: number): void
|
|
91
|
+
/** Destroy a vertex buffer. Destroy pipelines drawing from it first. */
|
|
92
|
+
export function destroyBuffer(id: number): void
|
|
93
|
+
/**
|
|
94
|
+
* Set how many vertices a pipeline texture draws and re-render it, e.g.
|
|
95
|
+
* after writing a variable amount of dynamic geometry into its buffer.
|
|
96
|
+
*/
|
|
97
|
+
export function setDrawCount(id: number, count: number): void
|
|
39
98
|
/**
|
|
40
99
|
* Capture a render-tree node's subtree into a new GPU texture, resolving once
|
|
41
100
|
* it has been rendered on the next paint pass. The node must be attached to
|
package/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
/// <reference path="./modules/p2p.d.ts" />
|
|
8
8
|
/// <reference path="./modules/net.d.ts" />
|
|
9
9
|
/// <reference path="./modules/mdns.d.ts" />
|
|
10
|
+
/// <reference path="./modules/wasm.d.ts" />
|
|
11
|
+
/// <reference path="./modules/ffi.d.ts" />
|
|
10
12
|
|
|
11
13
|
// Web-standard globals. The runtime is QuickJS, not a browser or Node, so it
|
|
12
14
|
// ships no lib.dom / @types/bun: these declarations are the sole source for
|
package/modules/ffi.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
declare module "flux:ffi" {
|
|
2
|
+
/**
|
|
3
|
+
* A scalar ffi value. i32/f32/f64 marshal as number; i64 and ptr marshal as
|
|
4
|
+
* BigInt (an address or i64 does not fit a JS number without precision
|
|
5
|
+
* loss). A number is also accepted where an i64 or ptr is expected.
|
|
6
|
+
*/
|
|
7
|
+
type FfiValue = number | bigint
|
|
8
|
+
type FfiTypeName = "i32" | "i64" | "f32" | "f64" | "ptr"
|
|
9
|
+
|
|
10
|
+
/** One symbol declaration. `returns` defaults to "void". */
|
|
11
|
+
type SymbolDecl = {
|
|
12
|
+
args: FfiTypeName[]
|
|
13
|
+
returns?: FfiTypeName | "void"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The symbols to resolve at load time, keyed by exported name. */
|
|
17
|
+
type Symbols = Record<string, SymbolDecl>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A JS function backing a minted C function pointer. Called synchronously
|
|
21
|
+
* while a `symbols.*` call is on the stack; its return value is coerced to
|
|
22
|
+
* the callback's declared result type ("void" ignores it). A throw cannot
|
|
23
|
+
* abort the native frame: the callback returns zeroes, the native call runs
|
|
24
|
+
* to completion, and the exception is rethrown after it returns.
|
|
25
|
+
*/
|
|
26
|
+
type CallbackFunction = (...args: FfiValue[]) => FfiValue | void
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A native shared library. The native counterpart of `flux:wasm`'s Module:
|
|
30
|
+
* declare what you need up front, every declared symbol must resolve.
|
|
31
|
+
*
|
|
32
|
+
* There is NO sandbox: the library runs with full process rights, loading
|
|
33
|
+
* runs its constructors, and a declared signature that does not match the
|
|
34
|
+
* real ABI is undefined behavior. Only load trusted code.
|
|
35
|
+
*/
|
|
36
|
+
export class Library {
|
|
37
|
+
/**
|
|
38
|
+
* Load a shared library from bytes (e.g. a bundled binary import; written
|
|
39
|
+
* to a temp file behind the scenes) or a filesystem path, and resolve
|
|
40
|
+
* every declared symbol. A missing symbol throws.
|
|
41
|
+
*/
|
|
42
|
+
constructor(source: Uint8Array | ArrayBuffer | string, symbols: Symbols)
|
|
43
|
+
/**
|
|
44
|
+
* The declared symbols as bound JS functions, keyed by name. Destructure
|
|
45
|
+
* once and reuse: the object is rebuilt on each access.
|
|
46
|
+
*/
|
|
47
|
+
readonly symbols: Record<string, (...args: FfiValue[]) => FfiValue | undefined>
|
|
48
|
+
/**
|
|
49
|
+
* Mint a C function pointer (returned as a BigInt address) that invokes
|
|
50
|
+
* `func` when the library calls it during a `symbols.*` call. Callbacks
|
|
51
|
+
* may only fire while such a call is on the stack, on the same thread;
|
|
52
|
+
* the pointer stays valid for the lifetime of the library.
|
|
53
|
+
*/
|
|
54
|
+
callback(func: CallbackFunction, decl: SymbolDecl): bigint
|
|
55
|
+
/**
|
|
56
|
+
* Copy `len` bytes out of process memory at `ptr`. No bounds checking is
|
|
57
|
+
* possible: a bad pointer is undefined behavior.
|
|
58
|
+
*/
|
|
59
|
+
readMemory(ptr: FfiValue, len: number): Uint8Array
|
|
60
|
+
/** Copy `bytes` into process memory at `ptr`. Same caveat as readMemory. */
|
|
61
|
+
writeMemory(ptr: FfiValue, bytes: Uint8Array | ArrayBuffer): void
|
|
62
|
+
}
|
|
63
|
+
}
|
package/modules/fs.d.ts
CHANGED
|
@@ -22,8 +22,16 @@ declare module "flux:fs" {
|
|
|
22
22
|
exists(): Promise<boolean>
|
|
23
23
|
/** Resolve to the file's metadata (size, type, mtime). */
|
|
24
24
|
stat(): Promise<FileStat>
|
|
25
|
+
/**
|
|
26
|
+
* Read exactly `length` bytes starting at byte `offset`. A range extending
|
|
27
|
+
* past end-of-file rejects rather than short-reading; clamp against
|
|
28
|
+
* `stat()` size first.
|
|
29
|
+
*/
|
|
30
|
+
read(offset: number, length: number): Promise<Uint8Array>
|
|
25
31
|
/** Write `data`, replacing any existing contents. */
|
|
26
32
|
write(data: string | Uint8Array): Promise<void>
|
|
33
|
+
/** Append `data` to the end of the file, creating it if missing. */
|
|
34
|
+
append(data: string | Uint8Array): Promise<void>
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
type FluxDir = {
|
package/modules/http.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
declare module "flux:http" {
|
|
2
|
+
import type { Endpoint } from "flux:p2p"
|
|
3
|
+
|
|
2
4
|
/** Path parameters captured from a route pattern (e.g. ":page"). */
|
|
3
5
|
type RouteParams = Record<string, string>
|
|
4
6
|
|
|
@@ -93,6 +95,11 @@ declare module "flux:http" {
|
|
|
93
95
|
close(code?: number, reason?: string): void
|
|
94
96
|
/** Connection state: CONNECTING 0, OPEN 1, CLOSING 2, CLOSED 3. */
|
|
95
97
|
readonly readyState: number
|
|
98
|
+
/**
|
|
99
|
+
* The peer's IP address (or, for a connection accepted over the `p2p`
|
|
100
|
+
* option, the peer's endpoint id), or undefined when unknown.
|
|
101
|
+
*/
|
|
102
|
+
readonly remoteAddress: string | undefined
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
/**
|
|
@@ -129,6 +136,18 @@ declare module "flux:http" {
|
|
|
129
136
|
headers?: Record<string, string> | Headers
|
|
130
137
|
}
|
|
131
138
|
|
|
139
|
+
/**
|
|
140
|
+
* A peer address, as returned by {@link Server.requestIP}. A p2p peer has no
|
|
141
|
+
* IP: `address` is its endpoint id, `port` is 0, and `family` is `"p2p"`.
|
|
142
|
+
*/
|
|
143
|
+
type SocketAddress = {
|
|
144
|
+
/** The peer's IP address, or a p2p peer's endpoint id. */
|
|
145
|
+
address: string
|
|
146
|
+
/** The peer's port (0 for a p2p peer). */
|
|
147
|
+
port: number
|
|
148
|
+
family: "IPv4" | "IPv6" | "p2p"
|
|
149
|
+
}
|
|
150
|
+
|
|
132
151
|
type Server = {
|
|
133
152
|
/** The bound port. */
|
|
134
153
|
readonly port: number
|
|
@@ -151,6 +170,11 @@ declare module "flux:http" {
|
|
|
151
170
|
publish(topic: string, data: string | Uint8Array): number
|
|
152
171
|
/** How many sockets are currently subscribed to `topic`. */
|
|
153
172
|
subscriberCount(topic: string): number
|
|
173
|
+
/**
|
|
174
|
+
* The peer address of the connection `req` arrived on, or null when unknown
|
|
175
|
+
* (e.g. a JS-constructed Request).
|
|
176
|
+
*/
|
|
177
|
+
requestIP(req: Request): SocketAddress | null
|
|
154
178
|
/**
|
|
155
179
|
* Stop accepting new connections and gracefully shut down open ones. Safe to
|
|
156
180
|
* call more than once.
|
|
@@ -158,6 +182,14 @@ declare module "flux:http" {
|
|
|
158
182
|
stop(): void
|
|
159
183
|
}
|
|
160
184
|
|
|
185
|
+
/** Options for accepting `flux:p2p` connections alongside the TCP listener. */
|
|
186
|
+
type P2pOptions = {
|
|
187
|
+
/** The `flux:p2p` Endpoint to accept connections on. */
|
|
188
|
+
endpoint: Endpoint
|
|
189
|
+
/** ALPN protocol matched against each incoming connection. */
|
|
190
|
+
protocol: string
|
|
191
|
+
}
|
|
192
|
+
|
|
161
193
|
type ServeOptions = {
|
|
162
194
|
/** Port to listen on. */
|
|
163
195
|
port: number
|
|
@@ -184,6 +216,13 @@ declare module "flux:http" {
|
|
|
184
216
|
* without it `upgrade()` always returns false.
|
|
185
217
|
*/
|
|
186
218
|
websocket?: WebSocketHandlers
|
|
219
|
+
/**
|
|
220
|
+
* Accept connections on a `flux:p2p` Endpoint alongside the TCP listener:
|
|
221
|
+
* each incoming connection whose ALPN matches `protocol` has the HTTP/WS
|
|
222
|
+
* protocol spoken over its first bidirectional stream. `server.stop()`
|
|
223
|
+
* stops accepting; the endpoint itself stays open for its owner.
|
|
224
|
+
*/
|
|
225
|
+
p2p?: P2pOptions
|
|
187
226
|
}
|
|
188
227
|
|
|
189
228
|
/**
|
package/modules/p2p.d.ts
CHANGED
|
@@ -10,6 +10,19 @@ declare module "flux:p2p" {
|
|
|
10
10
|
relayUrl?: string
|
|
11
11
|
/** Protocols this endpoint will {@link Endpoint.accept}. */
|
|
12
12
|
protocols?: string[]
|
|
13
|
+
/**
|
|
14
|
+
* Bind local-only: no relay and no address publishing/lookup, so nothing
|
|
15
|
+
* about the endpoint leaves the machine except the ticket itself, whose
|
|
16
|
+
* direct IPs same-network peers dial. Excludes `relayUrl`; a bare-id
|
|
17
|
+
* `connect` cannot resolve a local endpoint (tickets only).
|
|
18
|
+
*/
|
|
19
|
+
local?: boolean
|
|
20
|
+
/**
|
|
21
|
+
* Pin the UDP bind port (IPv4-only). With a persisted `secretKey` this keeps
|
|
22
|
+
* the whole ticket stable across restarts, so a paired client can re-dial
|
|
23
|
+
* the old ticket. Omit for an ephemeral port.
|
|
24
|
+
*/
|
|
25
|
+
port?: number
|
|
13
26
|
}
|
|
14
27
|
|
|
15
28
|
/** One transport address from {@link Endpoint.connInfo}. */
|
|
@@ -54,7 +67,7 @@ declare module "flux:p2p" {
|
|
|
54
67
|
/**
|
|
55
68
|
* Bind an endpoint.
|
|
56
69
|
*
|
|
57
|
-
* @param opts secretKey, relayUrl, protocols.
|
|
70
|
+
* @param opts secretKey, relayUrl, protocols, local, port.
|
|
58
71
|
*/
|
|
59
72
|
static create(opts?: EndpointOptions): Promise<Endpoint>
|
|
60
73
|
/** This endpoint's dial address: the string peers pass to {@link connect}. */
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
declare module "flux:wasm" {
|
|
2
|
+
/**
|
|
3
|
+
* A scalar wasm value. i32/f32/f64 marshal as number; i64 marshals as BigInt
|
|
4
|
+
* (an i64 does not fit a JS number without precision loss). A number is also
|
|
5
|
+
* accepted where an i64 is expected.
|
|
6
|
+
*/
|
|
7
|
+
type WasmValue = number | bigint
|
|
8
|
+
type WasmTypeName = "i32" | "i64" | "f32" | "f64"
|
|
9
|
+
|
|
10
|
+
/** A function import a module requires, `{ module, name }`-keyed like the standard. */
|
|
11
|
+
type ImportInfo = {
|
|
12
|
+
module: string
|
|
13
|
+
name: string
|
|
14
|
+
params: WasmTypeName[]
|
|
15
|
+
results: WasmTypeName[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* An instance export. `params`/`results` are present only for functions with
|
|
20
|
+
* all-scalar signatures.
|
|
21
|
+
*/
|
|
22
|
+
type ExportInfo =
|
|
23
|
+
| { name: string; kind: "function"; params: WasmTypeName[]; results: WasmTypeName[] }
|
|
24
|
+
| { name: string; kind: "memory" | "other" }
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A host function backing a guest import. Called synchronously during an
|
|
28
|
+
* export call; must return values matching the import's declared results:
|
|
29
|
+
* nothing for zero results, a single value for one, an array for several.
|
|
30
|
+
* A throw aborts the wasm call and propagates. May re-enter the instance
|
|
31
|
+
* (e.g. via {@link Instance.callIndirect}).
|
|
32
|
+
*/
|
|
33
|
+
type HostFunction = (...args: WasmValue[]) => WasmValue | WasmValue[] | void
|
|
34
|
+
|
|
35
|
+
/** Host functions keyed by import module then name, e.g. `{ env: { mul } }`. */
|
|
36
|
+
type Imports = Record<string, Record<string, HostFunction>>
|
|
37
|
+
|
|
38
|
+
export class Module {
|
|
39
|
+
/**
|
|
40
|
+
* Parse and validate a wasm binary (wat text bytes are also accepted).
|
|
41
|
+
* Throws on invalid input or on an unsupported import (non-function, or
|
|
42
|
+
* non-scalar signature).
|
|
43
|
+
*/
|
|
44
|
+
constructor(bytes: Uint8Array | ArrayBuffer)
|
|
45
|
+
/**
|
|
46
|
+
* The function imports this module requires, in the order the host
|
|
47
|
+
* functions are indexed.
|
|
48
|
+
*/
|
|
49
|
+
readonly imports: ImportInfo[]
|
|
50
|
+
/**
|
|
51
|
+
* Instantiate with host functions. Every listed import must resolve to a
|
|
52
|
+
* function; a missing or non-function entry throws.
|
|
53
|
+
*/
|
|
54
|
+
instantiate(imports: Imports): Instance
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** An instantiated module. Created with {@link Module.instantiate}. */
|
|
58
|
+
export class Instance {
|
|
59
|
+
/** The module's exports. */
|
|
60
|
+
readonly exports: ExportInfo[]
|
|
61
|
+
/**
|
|
62
|
+
* Call an exported function. Arguments are coerced to the export's declared
|
|
63
|
+
* parameter types. Returns `undefined` for no results, the single value for
|
|
64
|
+
* one, or an array for several. Host imports hit during the call dispatch
|
|
65
|
+
* to the functions passed to `instantiate`; a throw from one aborts the
|
|
66
|
+
* call.
|
|
67
|
+
*/
|
|
68
|
+
call(name: string, ...args: WasmValue[]): WasmValue | WasmValue[] | undefined
|
|
69
|
+
/**
|
|
70
|
+
* Call a function by its index in the module's exported function table:
|
|
71
|
+
* `table[index](...args)`. This is how a host function invokes a guest
|
|
72
|
+
* function pointer it received as an integer (e.g. a C callback). Same
|
|
73
|
+
* coercion and host-import dispatch rules as {@link call}; safe to use
|
|
74
|
+
* from within a host function (re-entrant).
|
|
75
|
+
*/
|
|
76
|
+
callIndirect(index: number, ...args: WasmValue[]): WasmValue | WasmValue[] | undefined
|
|
77
|
+
/**
|
|
78
|
+
* The exported memory's current size in bytes, or `undefined` if the
|
|
79
|
+
* module exports no memory.
|
|
80
|
+
*/
|
|
81
|
+
readonly memorySize: number | undefined
|
|
82
|
+
/** Copy `len` bytes out of the exported memory at `ptr`. */
|
|
83
|
+
readMemory(ptr: number, len: number): Uint8Array
|
|
84
|
+
/** Copy `bytes` into the exported memory at `ptr`. */
|
|
85
|
+
writeMemory(ptr: number, bytes: Uint8Array | ArrayBuffer): void
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
CHANGED
package/standards/fetch.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ interface Headers {
|
|
|
25
25
|
delete(name: string): void
|
|
26
26
|
/** Add a value for `name` without replacing existing ones. */
|
|
27
27
|
append(name: string, value: string): void
|
|
28
|
+
/**
|
|
29
|
+
* Call `callback(value, name, headers)` for each entry. Iterates entries as
|
|
30
|
+
* stored (insertion order, duplicates separate); WHATWG iterates sorted with
|
|
31
|
+
* duplicate names combined.
|
|
32
|
+
*/
|
|
33
|
+
forEach(callback: (value: string, name: string, headers: Headers) => void, thisArg?: any): void
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
declare let Headers: {
|