@solidrt/flux-types 0.0.24 → 0.0.26

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/gui/audio.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  // Sound playback (gui-enabled runtime only). The imperative primitive; `play`
2
- // decodes an encoded clip (Ogg/Vorbis or WAV) and returns a handle whose
3
- // `stop()` halts just that sound, so the raw track id never leaves the runtime.
2
+ // decodes and starts a clip in one call, while `load` decodes once so a clip can
3
+ // be replayed cheaply. Handles carry a `stop()` bound to just that voice, so the
4
+ // raw track id never leaves the runtime.
4
5
 
5
6
  declare module "flux:audio" {
6
- /** Options for {@link play}. */
7
+ /** Options for {@link play} and {@link LoadedSound.play}. */
7
8
  type PlayOptions = {
8
9
  /** Repeat the clip until stopped. Defaults to false. */
9
10
  loop?: boolean
@@ -11,17 +12,39 @@ declare module "flux:audio" {
11
12
  gain?: number
12
13
  }
13
14
 
14
- /** A playing sound with controls bound to it. */
15
+ /** A playing voice with controls bound to it. */
15
16
  type SoundHandle = {
16
- /** Stop this sound. A no-op if it already finished. */
17
+ /** Stop this voice. A no-op if it already finished. */
17
18
  stop(): void
18
19
  }
19
20
 
21
+ /** A decoded clip that can be replayed without re-decoding. */
22
+ type LoadedSound = {
23
+ /** Start a fresh overlapping voice for this clip. */
24
+ play(options?: PlayOptions): SoundHandle
25
+ /** Release the decoded clip. Voices already playing keep going. */
26
+ unload(): void
27
+ }
28
+
20
29
  /**
21
30
  * Decode and start an encoded audio clip (Ogg/Vorbis or WAV). Returns
22
- * immediately; the sound plays on the mixer's own thread.
31
+ * immediately; the sound plays on the mixer's own thread. Use {@link load} to
32
+ * replay a clip repeatedly without decoding it each time.
23
33
  */
24
34
  export function play(bytes: Uint8Array, options?: PlayOptions): SoundHandle
35
+ /**
36
+ * Decode an encoded clip (Ogg/Vorbis or WAV) once and keep it in memory so it
37
+ * can be replayed cheaply. Call `unload()` on the result when done.
38
+ */
39
+ export function load(bytes: Uint8Array): LoadedSound
40
+ /**
41
+ * Open a clip for streaming: it is decoded on demand instead of loaded fully
42
+ * into memory, so a large track needs little RAM. Takes a `file()` from
43
+ * `flux:fs` (not a path), so the source rides the `file()` proxy override - a
44
+ * dev-server-proxied file streams from the server. Play the result as a single
45
+ * voice; do not overlap a stream with itself. Call `unload()` when done.
46
+ */
47
+ export function stream(source: ReturnType<typeof import("flux:fs").file>): LoadedSound
25
48
  /** Stop every playing sound. */
26
- export function stopAll(): void
49
+ export function stop(): void
27
50
  }
package/gui/gpu.d.ts CHANGED
@@ -36,4 +36,21 @@ 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
+ * Capture a render-tree node's subtree into a new GPU texture, resolving once
41
+ * it has been rendered on the next paint pass. The node must be attached to
42
+ * the live tree (a detached node is never painted, so its capture rejects).
43
+ * Rendered at the current display scale, so `width`/`height` are the texture's
44
+ * actual pixel dimensions (ceil(logicalSize * displayScale)), not logical
45
+ * points. Each call returns an independent id you must {@link destroyTexture}
46
+ * when done. Use the returned id anywhere a texture id is accepted
47
+ * (`<texture src>`, a shader sampler input, {@link readTexture}).
48
+ */
49
+ export function captureSnapshot(nodeId: number): Promise<{ id: number; width: number; height: number }>
50
+ /**
51
+ * Read back a registered texture's current pixels as RGBA8 (tightly packed,
52
+ * top-to-bottom rows), for any texture id whatever created it (createTexture,
53
+ * createShader, captureSnapshot). Synchronous. Throws if the id is unknown.
54
+ */
55
+ export function readTexture(id: number): { width: number; height: number; data: Uint8Array }
39
56
  }
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}. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",
@@ -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: {