@solidrt/flux-types 0.0.11 → 0.0.13
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 +38 -17
- package/gui/camera.d.ts +67 -0
- package/gui/gpu.d.ts +39 -0
- package/gui/microphone.d.ts +39 -0
- package/gui/raf.d.ts +14 -0
- package/gui/rendertree.d.ts +47 -0
- package/index.d.ts +32 -207
- package/modules/fs.d.ts +50 -0
- package/modules/http.d.ts +197 -0
- package/modules/p2p.d.ts +85 -0
- package/modules/path.d.ts +26 -0
- package/modules/process.d.ts +36 -0
- package/modules/sqlite.d.ts +53 -0
- package/modules/subprocess.d.ts +89 -0
- package/package.json +4 -1
- package/standards/console.d.ts +10 -0
- package/standards/fetch.d.ts +104 -0
- package/standards/text.d.ts +47 -0
- package/standards/time.d.ts +31 -0
- package/standards/websocket.d.ts +62 -0
package/README.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# @solidrt/flux-types
|
|
2
2
|
|
|
3
|
-
TypeScript type definitions for the
|
|
3
|
+
TypeScript type definitions for the [SolidRT](https://github.com/wellawaretech/solidrt)
|
|
4
|
+
`flux` runtime: the `Flux` global, the `flux:*` capability modules, the
|
|
5
|
+
web-standard globals flux provides, and the GUI globals.
|
|
6
|
+
|
|
7
|
+
The runtime is QuickJS, not a browser or Node, so it ships neither `lib.dom` nor
|
|
8
|
+
the Bun/Node libraries. This package is the single source of truth for everything
|
|
9
|
+
the flux runtime exposes, including web standards like `fetch`, `Response`,
|
|
10
|
+
`WebSocket`, `console`, and timers.
|
|
4
11
|
|
|
5
12
|
## Installation
|
|
6
13
|
|
|
@@ -8,31 +15,45 @@ TypeScript type definitions for the `Flux` runtime global in [SolidRT](https://g
|
|
|
8
15
|
bun add -d @solidrt/flux-types
|
|
9
16
|
```
|
|
10
17
|
|
|
11
|
-
Then
|
|
12
|
-
|
|
13
|
-
visible to TypeScript when the package is listed in `types`. Without this you
|
|
14
|
-
will get `Cannot find module 'flux:fs'` (and the same for `flux:http`,
|
|
15
|
-
`flux:process`, etc.).
|
|
18
|
+
Then configure `tsconfig.json` so TypeScript uses these types and does **not**
|
|
19
|
+
pull in browser or Bun/Node globals that the runtime does not have:
|
|
16
20
|
|
|
17
21
|
```json
|
|
18
22
|
{
|
|
19
23
|
"compilerOptions": {
|
|
24
|
+
"lib": ["ESNext"],
|
|
20
25
|
"types": ["@solidrt/flux-types"]
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
```
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
- `lib: ["ESNext"]` keeps the genuine ECMAScript types (Promise, Array, Map,
|
|
31
|
+
TypedArrays, `Symbol.asyncIterator`) while dropping the DOM. Including `"dom"`
|
|
32
|
+
would advertise `document`, `window`, `localStorage`, and other APIs that do
|
|
33
|
+
not exist in flux.
|
|
34
|
+
- `types: ["@solidrt/flux-types"]` makes the `flux:*` modules (ambient module
|
|
35
|
+
declarations) and the runtime globals visible.
|
|
36
|
+
|
|
37
|
+
Do **not** also add `@types/bun` or `@types/node`: they declare `Bun.*`,
|
|
38
|
+
`bun:*`/`node:*` modules, `process`, `Buffer`, and other APIs the runtime does
|
|
39
|
+
not provide, and they collide with the web-standard globals declared here.
|
|
40
|
+
|
|
41
|
+
If you already maintain a `types` array, add to it rather than replacing it:
|
|
42
|
+
listing `types` disables TypeScript's automatic inclusion, so every package you
|
|
43
|
+
rely on must be named.
|
|
44
|
+
|
|
45
|
+
## What's covered
|
|
46
|
+
|
|
47
|
+
- `Flux` global (`version`, `capabilities`).
|
|
48
|
+
- `flux:*` modules: `flux:http`, `flux:fs`, `flux:sqlite`, `flux:subprocess`,
|
|
49
|
+
`flux:p2p`, `flux:process`, `flux:path`, and (on a gui-enabled runtime)
|
|
50
|
+
`flux:camera`, `flux:microphone`, `flux:gpu`.
|
|
51
|
+
- Web-standard globals: `console`, `fetch` + `Headers`/`Request`/`Response`,
|
|
52
|
+
`setTimeout`/`setInterval`/`queueMicrotask`, `performance`, `WebSocket`,
|
|
53
|
+
`TextEncoder`/`TextDecoder`. These are deliberate subsets matching exactly what
|
|
54
|
+
the runtime implements.
|
|
55
|
+
- GUI globals (gui-enabled runtime only): `requestAnimationFrame` /
|
|
56
|
+
`cancelAnimationFrame` (web-standard names, so kept global).
|
|
36
57
|
|
|
37
58
|
## License
|
|
38
59
|
|
package/gui/camera.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Camera capture (gui-enabled runtime only). The imperative primitive;
|
|
2
|
+
// @solidrt/core's createCamera wraps it with SolidJS reactivity. `open` resolves
|
|
3
|
+
// to a bound session object, so the raw handle never leaves the runtime.
|
|
4
|
+
|
|
5
|
+
declare module "flux:camera" {
|
|
6
|
+
/** A camera device from {@link listCameras}. */
|
|
7
|
+
type CameraDevice = {
|
|
8
|
+
/** Device id to pass as `open({ camera })`. */
|
|
9
|
+
id: number
|
|
10
|
+
/** Human-readable device name. */
|
|
11
|
+
name: string
|
|
12
|
+
/** Which way the camera faces. */
|
|
13
|
+
facing: "front" | "back" | "unknown"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Options for {@link open}. */
|
|
17
|
+
type CameraOpenOptions = {
|
|
18
|
+
/** Device id from {@link CameraDevice}. Omit to let the runtime choose. */
|
|
19
|
+
camera?: number
|
|
20
|
+
/** Prefer a front- or back-facing camera. */
|
|
21
|
+
facing?: "front" | "back"
|
|
22
|
+
/** Requested capture width in pixels. */
|
|
23
|
+
width?: number
|
|
24
|
+
/** Requested capture height in pixels. */
|
|
25
|
+
height?: number
|
|
26
|
+
/** Barcode formats to scan each frame for. Only "qr" is supported. */
|
|
27
|
+
scan?: "qr"[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A decoded barcode. */
|
|
31
|
+
type Barcode = {
|
|
32
|
+
/** The decoded payload. */
|
|
33
|
+
data: string
|
|
34
|
+
/** The barcode format (currently always "qr"). */
|
|
35
|
+
format: "qr"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** An opened camera session: the frame texture plus controls bound to it. */
|
|
39
|
+
type CameraSession = {
|
|
40
|
+
/** GPU texture id the latest frame is uploaded into (use as a texture source). */
|
|
41
|
+
texture: number
|
|
42
|
+
/** Frame width in pixels. */
|
|
43
|
+
width: number
|
|
44
|
+
/** Frame height in pixels. */
|
|
45
|
+
height: number
|
|
46
|
+
/**
|
|
47
|
+
* Register (or replace) the callback that receives decoded barcodes (only
|
|
48
|
+
* fires when the session was opened with a `scan` option).
|
|
49
|
+
*/
|
|
50
|
+
onBarcode(callback: (barcode: Barcode) => void): void
|
|
51
|
+
/** Release the device. */
|
|
52
|
+
close(): void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** List the available camera devices. */
|
|
56
|
+
export function listCameras(): CameraDevice[]
|
|
57
|
+
/**
|
|
58
|
+
* Open a camera. Opening is also the permission request: the promise rejects
|
|
59
|
+
* if permission is denied, and resolves once the first frame is ready.
|
|
60
|
+
*/
|
|
61
|
+
export function open(options?: CameraOpenOptions): Promise<CameraSession>
|
|
62
|
+
/**
|
|
63
|
+
* One-shot scan of an RGBA8 pixel buffer (exactly width*height*4 bytes).
|
|
64
|
+
* Returns every decoded barcode.
|
|
65
|
+
*/
|
|
66
|
+
export function scanImage(data: Uint8Array, width: number, height: number): Barcode[]
|
|
67
|
+
}
|
package/gui/gpu.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Low-level GPU textures and fragment shaders (gui-enabled runtime only). The
|
|
2
|
+
// imperative primitive; @solidrt/core's gpu helpers add reactive auto-cleanup on
|
|
3
|
+
// top. Texture ids are the public token (used as `<texture src>` and shader
|
|
4
|
+
// sampler inputs), so there is no handle to hide here.
|
|
5
|
+
|
|
6
|
+
declare module "flux:gpu" {
|
|
7
|
+
/**
|
|
8
|
+
* Create an immutable texture from an RGBA8 pixel buffer (exactly
|
|
9
|
+
* width*height*4 bytes). Returns the texture id.
|
|
10
|
+
*/
|
|
11
|
+
export function createTexture(data: Uint8Array, width: number, height: number): number
|
|
12
|
+
/**
|
|
13
|
+
* Create a texture intended to be updated later via {@link uploadTexture}. The
|
|
14
|
+
* seed buffer must hold at least one frame (width*height*4 bytes) and may hold
|
|
15
|
+
* more (uploadTexture selects a frame by offset).
|
|
16
|
+
*/
|
|
17
|
+
export function createMutableTexture(data: Uint8Array, width: number, height: number): number
|
|
18
|
+
/**
|
|
19
|
+
* Replace a mutable texture's pixels. `data` may hold several frames; `offset`
|
|
20
|
+
* (default 0) selects which frame to upload.
|
|
21
|
+
*/
|
|
22
|
+
export function uploadTexture(id: number, data: Uint8Array, offset?: number): void
|
|
23
|
+
/** Destroy a texture (immutable, mutable, or shader). */
|
|
24
|
+
export function destroyTexture(id: number): void
|
|
25
|
+
/**
|
|
26
|
+
* Compile a GLSL ES fragment shader into an offscreen texture of the given
|
|
27
|
+
* size. `params` sets float uniforms by name; `textures` binds sampler2D
|
|
28
|
+
* uniforms to texture ids. Returns the resulting texture id.
|
|
29
|
+
*/
|
|
30
|
+
export function createShader(
|
|
31
|
+
fragmentSrc: string,
|
|
32
|
+
width: number,
|
|
33
|
+
height: number,
|
|
34
|
+
params?: Record<string, number>,
|
|
35
|
+
textures?: Record<string, number>,
|
|
36
|
+
): number
|
|
37
|
+
/** Update a shader texture's float uniforms by name and re-render it. */
|
|
38
|
+
export function setShaderParams(id: number, params: Record<string, number>): void
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Microphone capture (gui-enabled runtime only). The imperative primitive;
|
|
2
|
+
// @solidrt/core's createMicrophone wraps it with SolidJS reactivity. `open`
|
|
3
|
+
// returns a bound session object, so the raw handle never leaves the runtime.
|
|
4
|
+
|
|
5
|
+
declare module "flux:microphone" {
|
|
6
|
+
/** A microphone device from {@link listMicrophones}. */
|
|
7
|
+
type MicrophoneDevice = {
|
|
8
|
+
/** Device id to pass as `open({ microphone })`. */
|
|
9
|
+
id: number
|
|
10
|
+
/** Human-readable device name. */
|
|
11
|
+
name: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Options for {@link open}. */
|
|
15
|
+
type MicrophoneOpenOptions = {
|
|
16
|
+
/** Device id from {@link MicrophoneDevice}. Omit to use the default. */
|
|
17
|
+
microphone?: number
|
|
18
|
+
/** Capture sample rate in Hz. Defaults to 16000. */
|
|
19
|
+
sampleRate?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** An opened microphone session with controls bound to it. */
|
|
23
|
+
type MicrophoneSession = {
|
|
24
|
+
/** The actual capture sample rate in Hz. */
|
|
25
|
+
sampleRate: number
|
|
26
|
+
/** Drain the mono float samples captured since the last read. */
|
|
27
|
+
read(): Float32Array
|
|
28
|
+
/** Release the device. */
|
|
29
|
+
close(): void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** List the available microphone devices. */
|
|
33
|
+
export function listMicrophones(): MicrophoneDevice[]
|
|
34
|
+
/**
|
|
35
|
+
* Open a microphone. Synchronous: current platforms expose no audio permission
|
|
36
|
+
* prompt.
|
|
37
|
+
*/
|
|
38
|
+
export function open(options?: MicrophoneOpenOptions): MicrophoneSession
|
|
39
|
+
}
|
package/gui/raf.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Animation-frame scheduling globals (gui-enabled runtime only).
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
/**
|
|
5
|
+
* Request that `callback` run before the next rendered frame, receiving the
|
|
6
|
+
* frame timestamp in milliseconds. Returns an id for
|
|
7
|
+
* {@link cancelAnimationFrame}. Available only on a gui-enabled runtime.
|
|
8
|
+
*/
|
|
9
|
+
function requestAnimationFrame(callback: (timestamp: number) => void): number
|
|
10
|
+
/** Cancel a frame callback scheduled with {@link requestAnimationFrame}. */
|
|
11
|
+
function cancelAnimationFrame(id: number): void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// The render-tree bridge (gui-enabled runtime only): the low-level surface the
|
|
2
|
+
// renderer drives to build and mutate the native tree - create/insert/delete
|
|
3
|
+
// nodes, write properties, query layout, measure text. Displaying the built
|
|
4
|
+
// tree is the runner's concern ("srt:render" in lattice), not part of this
|
|
5
|
+
// module; requestFrame here only schedules a future frame.
|
|
6
|
+
|
|
7
|
+
declare module "flux:rendertree" {
|
|
8
|
+
/** Font options for {@link measureText}. */
|
|
9
|
+
export interface MeasureTextOptions {
|
|
10
|
+
fontFamily?: "sans" | "mono" | (string & {})
|
|
11
|
+
fontSize?: number
|
|
12
|
+
fontStyle?: "normal" | "italic"
|
|
13
|
+
fontWeight?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
|
14
|
+
maxLines?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Create the window root node with the given id. */
|
|
18
|
+
export function createRoot(id: number): void
|
|
19
|
+
/** Create a node of `kind` (the primitive element name) with the given id. */
|
|
20
|
+
export function createNode(id: number, kind: string): void
|
|
21
|
+
/** Insert `nodeId` under `parentId`, before `anchorId` if given (else appended). */
|
|
22
|
+
export function insertNode(parentId: number, nodeId: number, anchorId?: number): void
|
|
23
|
+
/** Detach and destroy `nodeId` from under `parentId`. */
|
|
24
|
+
export function deleteNode(parentId: number, nodeId: number): void
|
|
25
|
+
/** Write a single property on a node; `value` is marshalled per property. */
|
|
26
|
+
export function setProperty(nodeId: number, name: string, value: unknown): void
|
|
27
|
+
/** Enable or disable text-input capture / the on-screen keyboard. */
|
|
28
|
+
export function setTextInputActive(active: boolean): void
|
|
29
|
+
/** Request that a frame be rendered soon (coalesced by the demand-driven loop). */
|
|
30
|
+
export function requestFrame(): void
|
|
31
|
+
/**
|
|
32
|
+
* Lay out, paint and submit the whole tree to the screen now (one frame). The
|
|
33
|
+
* direct draw path for a flux + alloy app; requestFrame only schedules a
|
|
34
|
+
* future frame and leaves the actual draw to the runner.
|
|
35
|
+
*/
|
|
36
|
+
export function render(): void
|
|
37
|
+
/**
|
|
38
|
+
* Measure the rendered size of `text` under the given font options, without
|
|
39
|
+
* adding it to the tree.
|
|
40
|
+
*/
|
|
41
|
+
export function measureText(text: string, options?: MeasureTextOptions): { width: number, height: number }
|
|
42
|
+
/**
|
|
43
|
+
* The node's window-relative bounding box from the most recent layout, or
|
|
44
|
+
* `null` if it has no layout or has not been laid out yet.
|
|
45
|
+
*/
|
|
46
|
+
export function getBoundingBox(id: number): { x: number, y: number, width: number, height: number } | null
|
|
47
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,212 +1,37 @@
|
|
|
1
|
+
/// <reference path="./modules/process.d.ts" />
|
|
2
|
+
/// <reference path="./modules/path.d.ts" />
|
|
3
|
+
/// <reference path="./modules/http.d.ts" />
|
|
4
|
+
/// <reference path="./modules/fs.d.ts" />
|
|
5
|
+
/// <reference path="./modules/sqlite.d.ts" />
|
|
6
|
+
/// <reference path="./modules/subprocess.d.ts" />
|
|
7
|
+
/// <reference path="./modules/p2p.d.ts" />
|
|
8
|
+
|
|
9
|
+
// Web-standard globals. The runtime is QuickJS, not a browser or Node, so it
|
|
10
|
+
// ships no lib.dom / @types/bun: these declarations are the sole source for
|
|
11
|
+
// console, fetch, the Fetch types, timers, WebSocket, and the encoders.
|
|
12
|
+
/// <reference path="./standards/console.d.ts" />
|
|
13
|
+
/// <reference path="./standards/time.d.ts" />
|
|
14
|
+
/// <reference path="./standards/text.d.ts" />
|
|
15
|
+
/// <reference path="./standards/fetch.d.ts" />
|
|
16
|
+
/// <reference path="./standards/websocket.d.ts" />
|
|
17
|
+
|
|
18
|
+
// GUI capabilities (present only on a gui-enabled runtime). rendertree/camera/
|
|
19
|
+
// microphone/gpu are flux:* modules like the rest; requestAnimationFrame stays a
|
|
20
|
+
// global (web-standard name). flux:rendertree is the render-tree bridge the
|
|
21
|
+
// renderer drives; displaying the built tree (renderFrame) is the runner's
|
|
22
|
+
// concern (srt:render in lattice), not part of flux.
|
|
23
|
+
/// <reference path="./gui/rendertree.d.ts" />
|
|
24
|
+
/// <reference path="./gui/camera.d.ts" />
|
|
25
|
+
/// <reference path="./gui/microphone.d.ts" />
|
|
26
|
+
/// <reference path="./gui/gpu.d.ts" />
|
|
27
|
+
/// <reference path="./gui/raf.d.ts" />
|
|
28
|
+
|
|
1
29
|
declare let Flux: {
|
|
30
|
+
/** The flux runtime version. */
|
|
2
31
|
version: string
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
declare module "flux:process" {
|
|
6
|
-
/**
|
|
7
|
-
* The program's command-line arguments. `argv[0]` is the script path;
|
|
8
|
-
* `argv[1]` onward are the user-supplied arguments.
|
|
9
|
-
*/
|
|
10
|
-
export let argv: string[]
|
|
11
|
-
/** The host OS: "darwin", "win32", "linux", "android", ... */
|
|
12
|
-
export let platform: string
|
|
13
|
-
/** The CPU architecture: "x64", "arm64", ... */
|
|
14
|
-
export let arch: string
|
|
15
|
-
/**
|
|
16
|
-
* Current-process memory usage. `rss` is the resident set size in bytes.
|
|
17
|
-
* (Node also reports heapTotal/heapUsed/external/arrayBuffers; only rss is
|
|
18
|
-
* provided for now.)
|
|
19
|
-
*/
|
|
20
|
-
export function memoryUsage(): { rss: number }
|
|
21
|
-
/**
|
|
22
|
-
* Listen for an OS signal. The callback receives the signal name. Returns an
|
|
23
|
-
* unsubscribe function. Unix only; a no-op elsewhere.
|
|
24
|
-
*
|
|
25
|
-
* @param signal One of "SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT", "SIGUSR1",
|
|
26
|
-
* "SIGUSR2".
|
|
27
|
-
* @param callback Invoked on each delivery with the signal name.
|
|
28
|
-
* @returns An unsubscribe function.
|
|
29
|
-
*/
|
|
30
|
-
export function on(signal: string, callback: (signal: string) => void): () => void
|
|
31
|
-
/**
|
|
32
|
-
* Like {@link on}, but the listener fires at most once and then unsubscribes.
|
|
33
|
-
*
|
|
34
|
-
* @param signal One of "SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT", "SIGUSR1",
|
|
35
|
-
* "SIGUSR2".
|
|
36
|
-
* @param callback Invoked once with the signal name.
|
|
37
|
-
* @returns An unsubscribe function.
|
|
38
|
-
*/
|
|
39
|
-
export function once(signal: string, callback: (signal: string) => void): () => void
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
declare module "flux:path" {
|
|
43
|
-
/**
|
|
44
|
-
* Resolves `path` against the trusted base directory `base`, returning the
|
|
45
|
-
* absolute result only if it stays inside `base`; otherwise `null`. Fusing
|
|
46
|
-
* normalization and containment means a `..`-laden or absolute `path` that
|
|
47
|
-
* would escape `base` is rejected rather than silently resolved.
|
|
48
|
-
*
|
|
49
|
-
* Purely lexical: it does not resolve symlinks, so a symlink inside `base`
|
|
50
|
-
* pointing out of it is not caught.
|
|
51
|
-
*
|
|
52
|
-
* @param base Trusted root directory. Relative values resolve against cwd.
|
|
53
|
-
* @param path Untrusted path to place within `base`.
|
|
54
|
-
* @returns The contained absolute path, or `null` if it would escape `base`.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* let target = resolveWithin(".", req.params.page)
|
|
58
|
-
* if (!target) return new Response("Not found", { status: 404 })
|
|
59
|
-
*/
|
|
60
|
-
export function resolveWithin(base: string, path: string): string | null
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Joins and normalizes path `segments`. Lexical only, with no containment
|
|
64
|
-
* guarantee; use `resolveWithin` when a segment is untrusted.
|
|
65
|
-
*/
|
|
66
|
-
export function join(...segments: string[]): string
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
declare module "flux:http" {
|
|
70
|
-
/** Path parameters captured from a route pattern (e.g. ":page"). */
|
|
71
|
-
type RouteParams = Record<string, string>
|
|
72
|
-
|
|
73
|
-
/** The request passed to a route handler, with captured route params. */
|
|
74
|
-
type FluxRequest = Request & {
|
|
75
|
-
params: RouteParams
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Handles a matched route, returning a `Response` (or a promise of one). */
|
|
79
|
-
type RouteHandler = (req: FluxRequest) => Response | Promise<Response>
|
|
80
|
-
|
|
81
|
-
type ServeOptions = {
|
|
82
|
-
/** Port to listen on. */
|
|
83
|
-
port?: number
|
|
84
|
-
/** Hostname/interface to bind. Defaults to all interfaces. */
|
|
85
|
-
hostname?: string
|
|
86
|
-
/**
|
|
87
|
-
* Route table keyed by path pattern. Patterns may contain `:name`
|
|
88
|
-
* segments, exposed on `req.params`.
|
|
89
|
-
*/
|
|
90
|
-
routes: Record<string, RouteHandler>
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
type Server = {
|
|
94
|
-
port: number
|
|
95
|
-
hostname: string
|
|
96
|
-
/** Stop accepting connections and shut the server down. */
|
|
97
|
-
stop(): void
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Start an HTTP server with the given route table.
|
|
102
|
-
*
|
|
103
|
-
* @param options Port, hostname, and routes.
|
|
104
|
-
* @returns The running {@link Server}.
|
|
105
|
-
*/
|
|
106
|
-
export function serve(options: ServeOptions): Server
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare module "flux:fs" {
|
|
110
|
-
type DirEntry = {
|
|
111
|
-
name: string
|
|
112
|
-
type: "file" | "directory" | "symlink" | "other"
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
type FileStat = {
|
|
116
|
-
size: number
|
|
117
|
-
type: string
|
|
118
|
-
mtime?: number
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
type FluxFile = {
|
|
122
|
-
path: string
|
|
123
|
-
/** Read the whole file as UTF-8 text. */
|
|
124
|
-
text(): Promise<string>
|
|
125
|
-
/** Read the whole file as raw bytes. */
|
|
126
|
-
bytes(): Promise<Uint8Array>
|
|
127
|
-
/** Read and parse the file as JSON. */
|
|
128
|
-
json(): Promise<any>
|
|
129
|
-
/** Resolve to whether the file exists. */
|
|
130
|
-
exists(): Promise<boolean>
|
|
131
|
-
/** Resolve to the file's metadata (size, type, mtime). */
|
|
132
|
-
stat(): Promise<FileStat>
|
|
133
|
-
/** Write `data`, replacing any existing contents. */
|
|
134
|
-
write(data: string | Uint8Array): Promise<void>
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
type FluxDir = {
|
|
138
|
-
path: string
|
|
139
|
-
/** List the directory's immediate entries (non-recursive). */
|
|
140
|
-
entries(): Promise<DirEntry[]>
|
|
141
|
-
/** Resolve to whether the directory exists. */
|
|
142
|
-
exists(): Promise<boolean>
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Reference a file by path. Lazy: no I/O happens until a method is called.
|
|
147
|
-
*
|
|
148
|
-
* @param path Path to the file.
|
|
149
|
-
*/
|
|
150
|
-
export function file(path: string): FluxFile
|
|
151
|
-
/**
|
|
152
|
-
* Reference a directory by path. Lazy: no I/O happens until a method is
|
|
153
|
-
* called.
|
|
154
|
-
*
|
|
155
|
-
* @param path Path to the directory.
|
|
156
|
-
*/
|
|
157
|
-
export function dir(path: string): FluxDir
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
declare module "flux:sqlite" {
|
|
161
|
-
/** Values accepted as bound parameters. booleans bind as 0/1. */
|
|
162
|
-
type SqlParam = null | boolean | number | string | Uint8Array
|
|
163
|
-
/** Values returned in result rows. BLOB comes back as Uint8Array. */
|
|
164
|
-
type SqlValue = null | number | string | Uint8Array
|
|
165
|
-
type Row = Record<string, SqlValue>
|
|
166
|
-
|
|
167
|
-
/** The outcome of a write. */
|
|
168
|
-
type RunResult = { changes: number; lastInsertRowid: number }
|
|
169
|
-
|
|
170
32
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
33
|
+
* Feature names this build/runtime provides. Branch on availability rather
|
|
34
|
+
* than the OS, e.g. `Flux.capabilities.includes("subprocess")`.
|
|
173
35
|
*/
|
|
174
|
-
|
|
175
|
-
/** Run the statement and resolve to all matching rows. */
|
|
176
|
-
all(params?: SqlParam[]): Promise<Row[]>
|
|
177
|
-
/** Run the statement and resolve to the first row, or `undefined`. */
|
|
178
|
-
get(params?: SqlParam[]): Promise<Row | undefined>
|
|
179
|
-
/** Run the statement as a write and resolve to its {@link RunResult}. */
|
|
180
|
-
run(params?: SqlParam[]): Promise<RunResult>
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Open mode: "ro" (default, read-only, must exist), "rw" (read-write, must
|
|
185
|
-
* exist), "rw+" (read-write, create if missing).
|
|
186
|
-
*/
|
|
187
|
-
type OpenMode = "ro" | "rw" | "rw+"
|
|
188
|
-
|
|
189
|
-
export class Database {
|
|
190
|
-
/**
|
|
191
|
-
* Open a connection to the database at `path`.
|
|
192
|
-
*
|
|
193
|
-
* @param path Database file path.
|
|
194
|
-
* @param mode Open mode; defaults to "ro".
|
|
195
|
-
*/
|
|
196
|
-
static connect(path: string, mode?: OpenMode): Promise<Database>
|
|
197
|
-
/** Create a reusable prepared statement (synchronous; compiles on first run). */
|
|
198
|
-
query(sql: string): Statement
|
|
199
|
-
/** One-shot write; uses plain prepare (no caching). */
|
|
200
|
-
run(sql: string, params?: SqlParam[]): Promise<RunResult>
|
|
201
|
-
/** Run a multi-statement script (no params), e.g. schema setup / migrations. */
|
|
202
|
-
exec(sql: string): Promise<void>
|
|
203
|
-
/**
|
|
204
|
-
* Run a batch of [sql, params] statements in one transaction (BEGIN/COMMIT,
|
|
205
|
-
* ROLLBACK on any error). Resolves to one result per statement. Statements
|
|
206
|
-
* must be writes/DDL. Cannot branch on intermediate results.
|
|
207
|
-
*/
|
|
208
|
-
transaction(statements: [string, SqlParam[]?][]): Promise<RunResult[]>
|
|
209
|
-
/** Close the connection. */
|
|
210
|
-
close(): Promise<void>
|
|
211
|
-
}
|
|
36
|
+
capabilities: string[]
|
|
212
37
|
}
|
package/modules/fs.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
declare module "flux:fs" {
|
|
2
|
+
type DirEntry = {
|
|
3
|
+
name: string
|
|
4
|
+
type: "file" | "directory" | "symlink" | "other"
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type FileStat = {
|
|
8
|
+
size: number
|
|
9
|
+
type: string
|
|
10
|
+
mtime?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type FluxFile = {
|
|
14
|
+
path: string
|
|
15
|
+
/** Read the whole file as UTF-8 text. */
|
|
16
|
+
text(): Promise<string>
|
|
17
|
+
/** Read the whole file as raw bytes. */
|
|
18
|
+
bytes(): Promise<Uint8Array>
|
|
19
|
+
/** Read and parse the file as JSON. */
|
|
20
|
+
json(): Promise<any>
|
|
21
|
+
/** Resolve to whether the file exists. */
|
|
22
|
+
exists(): Promise<boolean>
|
|
23
|
+
/** Resolve to the file's metadata (size, type, mtime). */
|
|
24
|
+
stat(): Promise<FileStat>
|
|
25
|
+
/** Write `data`, replacing any existing contents. */
|
|
26
|
+
write(data: string | Uint8Array): Promise<void>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type FluxDir = {
|
|
30
|
+
path: string
|
|
31
|
+
/** List the directory's immediate entries (non-recursive). */
|
|
32
|
+
entries(): Promise<DirEntry[]>
|
|
33
|
+
/** Resolve to whether the directory exists. */
|
|
34
|
+
exists(): Promise<boolean>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Reference a file by path. Lazy: no I/O happens until a method is called.
|
|
39
|
+
*
|
|
40
|
+
* @param path Path to the file.
|
|
41
|
+
*/
|
|
42
|
+
export function file(path: string): FluxFile
|
|
43
|
+
/**
|
|
44
|
+
* Reference a directory by path. Lazy: no I/O happens until a method is
|
|
45
|
+
* called.
|
|
46
|
+
*
|
|
47
|
+
* @param path Path to the directory.
|
|
48
|
+
*/
|
|
49
|
+
export function dir(path: string): FluxDir
|
|
50
|
+
}
|