@solidrt/flux-types 0.0.26 → 0.0.28
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 +7 -0
- package/modules/wasm.d.ts +87 -0
- package/package.json +1 -1
- package/standards/fetch.d.ts +27 -1
- package/standards/time.d.ts +4 -4
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
|
@@ -16,6 +16,8 @@ declare module "flux:fs" {
|
|
|
16
16
|
text(): Promise<string>
|
|
17
17
|
/** Read the whole file as raw bytes. */
|
|
18
18
|
bytes(): Promise<Uint8Array>
|
|
19
|
+
/** Read the whole file as an ArrayBuffer. */
|
|
20
|
+
arrayBuffer(): Promise<ArrayBuffer>
|
|
19
21
|
/** Read and parse the file as JSON. */
|
|
20
22
|
json(): Promise<any>
|
|
21
23
|
/** Resolve to whether the file exists. */
|
|
@@ -40,6 +42,11 @@ declare module "flux:fs" {
|
|
|
40
42
|
entries(): Promise<DirEntry[]>
|
|
41
43
|
/** Resolve to whether the directory exists. */
|
|
42
44
|
exists(): Promise<boolean>
|
|
45
|
+
/**
|
|
46
|
+
* Create the directory, including any missing parents. Succeeds if it
|
|
47
|
+
* already exists.
|
|
48
|
+
*/
|
|
49
|
+
create(): Promise<void>
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
/**
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The Fetch API cluster (Headers, Request, Response, fetch). A deliberate subset
|
|
2
2
|
// of the WHATWG Fetch standard: flux provides exactly these members and no more
|
|
3
|
-
// (no Blob, FormData, ReadableStream,
|
|
3
|
+
// (no Blob, FormData, ReadableStream, clone(), AbortSignal, ...).
|
|
4
4
|
// Grouped in one file because the four share BodyInit/HeadersInit and reference
|
|
5
5
|
// each other.
|
|
6
6
|
|
|
@@ -44,6 +44,28 @@ interface RequestInit {
|
|
|
44
44
|
body?: BodyInit | null
|
|
45
45
|
/** Request headers. */
|
|
46
46
|
headers?: HeadersInit
|
|
47
|
+
/**
|
|
48
|
+
* Disk-cache policy, explicit and per call. flux never caches by default
|
|
49
|
+
* (like Node/Bun/Deno), and server cache headers (`cache-control`,
|
|
50
|
+
* `expires`, `etag`) are ignored entirely: the caller decides.
|
|
51
|
+
*
|
|
52
|
+
* - `"force-cache"`: serve from disk if stored, otherwise fetch and store.
|
|
53
|
+
* No freshness, no TTL: the entry lives until evicted by the size cap or
|
|
54
|
+
* overwritten by `"reload"`. Use for assets (images, audio, fonts);
|
|
55
|
+
* versioned URLs are the normal way to handle updatable assets.
|
|
56
|
+
* - `"reload"`: fetch fresh and overwrite the stored entry.
|
|
57
|
+
* - `"default"`, `"no-store"`, `"no-cache"`: accepted, plain network
|
|
58
|
+
* request (all equivalent to omitting the option here; there is no
|
|
59
|
+
* freshness model to modulate).
|
|
60
|
+
*
|
|
61
|
+
* Only GET requests with 2xx responses are cached, keyed by URL; on other
|
|
62
|
+
* methods the option is ignored. Unknown values throw.
|
|
63
|
+
*
|
|
64
|
+
* Cached fetches queue on a small per-host concurrency limit so asset
|
|
65
|
+
* floods stay polite; disk hits and plain (uncached) fetches are never
|
|
66
|
+
* throttled.
|
|
67
|
+
*/
|
|
68
|
+
cache?: "force-cache" | "reload" | "default" | "no-store" | "no-cache"
|
|
47
69
|
}
|
|
48
70
|
|
|
49
71
|
/**
|
|
@@ -62,6 +84,8 @@ interface Request {
|
|
|
62
84
|
text(): Promise<string>
|
|
63
85
|
/** Read the whole body as raw bytes. */
|
|
64
86
|
bytes(): Promise<Uint8Array>
|
|
87
|
+
/** Read the whole body as an ArrayBuffer. */
|
|
88
|
+
arrayBuffer(): Promise<ArrayBuffer>
|
|
65
89
|
/** Read and parse the whole body as JSON. */
|
|
66
90
|
json(): Promise<any>
|
|
67
91
|
}
|
|
@@ -93,6 +117,8 @@ interface Response {
|
|
|
93
117
|
text(): Promise<string>
|
|
94
118
|
/** Read the whole body as raw bytes. */
|
|
95
119
|
bytes(): Promise<Uint8Array>
|
|
120
|
+
/** Read the whole body as an ArrayBuffer. */
|
|
121
|
+
arrayBuffer(): Promise<ArrayBuffer>
|
|
96
122
|
/** Read and parse the whole body as JSON. */
|
|
97
123
|
json(): Promise<any>
|
|
98
124
|
}
|
package/standards/time.d.ts
CHANGED
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
* {@link clearTimeout}.
|
|
8
8
|
*/
|
|
9
9
|
declare function setTimeout(callback: () => void, ms: number): number
|
|
10
|
-
/** Cancel a pending timeout.
|
|
11
|
-
declare function clearTimeout(id
|
|
10
|
+
/** Cancel a pending timeout. Unknown or missing ids are ignored. */
|
|
11
|
+
declare function clearTimeout(id?: number): void
|
|
12
12
|
/**
|
|
13
13
|
* Run `callback` every `ms` milliseconds. Returns a timer id for
|
|
14
14
|
* {@link clearInterval}.
|
|
15
15
|
*/
|
|
16
16
|
declare function setInterval(callback: () => void, ms: number): number
|
|
17
|
-
/** Cancel a running interval.
|
|
18
|
-
declare function clearInterval(id
|
|
17
|
+
/** Cancel a running interval. Unknown or missing ids are ignored. */
|
|
18
|
+
declare function clearInterval(id?: number): void
|
|
19
19
|
/**
|
|
20
20
|
* Queue `callback` to run as a microtask: after the current job finishes, before
|
|
21
21
|
* any timer fires.
|