@solidrt/flux-types 0.0.6 → 0.0.8
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 +17 -1
- package/index.d.ts +181 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,11 @@ TypeScript type definitions for the `Flux` runtime global in [SolidRT](https://g
|
|
|
8
8
|
bun add -d @solidrt/flux-types
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Then
|
|
11
|
+
Then **you must add it to the `types` array** in your `tsconfig.json`. This is
|
|
12
|
+
required: the `flux:*` modules are ambient declarations, so they are only
|
|
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.).
|
|
12
16
|
|
|
13
17
|
```json
|
|
14
18
|
{
|
|
@@ -18,6 +22,18 @@ Then reference it in your `tsconfig.json`:
|
|
|
18
22
|
}
|
|
19
23
|
```
|
|
20
24
|
|
|
25
|
+
If you already have a `types` array (for example with `@types/bun`), **add to
|
|
26
|
+
it** rather than replacing it — listing `types` disables TypeScript's automatic
|
|
27
|
+
type inclusion, so every package you rely on must be named:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"compilerOptions": {
|
|
32
|
+
"types": ["bun", "@solidrt/flux-types"]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
21
37
|
## License
|
|
22
38
|
|
|
23
39
|
MIT. Copyright (c) 2026 Antoine van Wel.
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,108 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
declare let Flux: {
|
|
2
|
+
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
|
+
/**
|
|
12
|
+
* Listen for an OS signal. The callback receives the signal name. Returns an
|
|
13
|
+
* unsubscribe function. Unix only; a no-op elsewhere.
|
|
14
|
+
*
|
|
15
|
+
* @param signal One of "SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT", "SIGUSR1",
|
|
16
|
+
* "SIGUSR2".
|
|
17
|
+
* @param callback Invoked on each delivery with the signal name.
|
|
18
|
+
* @returns An unsubscribe function.
|
|
19
|
+
*/
|
|
20
|
+
export function on(signal: string, callback: (signal: string) => void): () => void
|
|
21
|
+
/**
|
|
22
|
+
* Like {@link on}, but the listener fires at most once and then unsubscribes.
|
|
23
|
+
*
|
|
24
|
+
* @param signal One of "SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT", "SIGUSR1",
|
|
25
|
+
* "SIGUSR2".
|
|
26
|
+
* @param callback Invoked once with the signal name.
|
|
27
|
+
* @returns An unsubscribe function.
|
|
28
|
+
*/
|
|
29
|
+
export function once(signal: string, callback: (signal: string) => void): () => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare module "flux:path" {
|
|
33
|
+
/**
|
|
34
|
+
* Resolves `path` against the trusted base directory `base`, returning the
|
|
35
|
+
* absolute result only if it stays inside `base`; otherwise `null`. Fusing
|
|
36
|
+
* normalization and containment means a `..`-laden or absolute `path` that
|
|
37
|
+
* would escape `base` is rejected rather than silently resolved.
|
|
38
|
+
*
|
|
39
|
+
* Purely lexical: it does not resolve symlinks, so a symlink inside `base`
|
|
40
|
+
* pointing out of it is not caught.
|
|
41
|
+
*
|
|
42
|
+
* @param base Trusted root directory. Relative values resolve against cwd.
|
|
43
|
+
* @param path Untrusted path to place within `base`.
|
|
44
|
+
* @returns The contained absolute path, or `null` if it would escape `base`.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* let target = resolveWithin(".", req.params.page)
|
|
48
|
+
* if (!target) return new Response("Not found", { status: 404 })
|
|
49
|
+
*/
|
|
50
|
+
export function resolveWithin(base: string, path: string): string | null
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Joins and normalizes path `segments`. Lexical only, with no containment
|
|
54
|
+
* guarantee; use `resolveWithin` when a segment is untrusted.
|
|
55
|
+
*/
|
|
56
|
+
export function join(...segments: string[]): string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare module "flux:http" {
|
|
60
|
+
/** Path parameters captured from a route pattern (e.g. ":page"). */
|
|
61
|
+
type RouteParams = Record<string, string>
|
|
62
|
+
|
|
63
|
+
/** The request passed to a route handler, with captured route params. */
|
|
64
|
+
type FluxRequest = Request & {
|
|
65
|
+
params: RouteParams
|
|
5
66
|
}
|
|
6
67
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
68
|
+
/** Handles a matched route, returning a `Response` (or a promise of one). */
|
|
69
|
+
type RouteHandler = (req: FluxRequest) => Response | Promise<Response>
|
|
70
|
+
|
|
71
|
+
type ServeOptions = {
|
|
72
|
+
/** Port to listen on. */
|
|
73
|
+
port?: number
|
|
74
|
+
/** Hostname/interface to bind. Defaults to all interfaces. */
|
|
75
|
+
hostname?: string
|
|
76
|
+
/**
|
|
77
|
+
* Route table keyed by path pattern. Patterns may contain `:name`
|
|
78
|
+
* segments, exposed on `req.params`.
|
|
79
|
+
*/
|
|
80
|
+
routes: Record<string, RouteHandler>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type Server = {
|
|
84
|
+
port: number
|
|
85
|
+
hostname: string
|
|
86
|
+
/** Stop accepting connections and shut the server down. */
|
|
87
|
+
stop(): void
|
|
11
88
|
}
|
|
12
89
|
|
|
13
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Start an HTTP server with the given route table.
|
|
92
|
+
*
|
|
93
|
+
* @param options Port, hostname, and routes.
|
|
94
|
+
* @returns The running {@link Server}.
|
|
95
|
+
*/
|
|
96
|
+
export function serve(options: ServeOptions): Server
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare module "flux:fs" {
|
|
100
|
+
type DirEntry = {
|
|
101
|
+
name: string
|
|
102
|
+
type: "file" | "directory" | "symlink" | "other"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type FileStat = {
|
|
14
106
|
size: number
|
|
15
107
|
type: string
|
|
16
108
|
mtime?: number
|
|
@@ -18,26 +110,93 @@ declare global {
|
|
|
18
110
|
|
|
19
111
|
type FluxFile = {
|
|
20
112
|
path: string
|
|
113
|
+
/** Read the whole file as UTF-8 text. */
|
|
21
114
|
text(): Promise<string>
|
|
115
|
+
/** Read the whole file as raw bytes. */
|
|
22
116
|
bytes(): Promise<Uint8Array>
|
|
117
|
+
/** Read and parse the file as JSON. */
|
|
23
118
|
json(): Promise<any>
|
|
119
|
+
/** Resolve to whether the file exists. */
|
|
24
120
|
exists(): Promise<boolean>
|
|
25
|
-
|
|
121
|
+
/** Resolve to the file's metadata (size, type, mtime). */
|
|
122
|
+
stat(): Promise<FileStat>
|
|
123
|
+
/** Write `data`, replacing any existing contents. */
|
|
124
|
+
write(data: string | Uint8Array): Promise<void>
|
|
26
125
|
}
|
|
27
126
|
|
|
28
|
-
type
|
|
29
|
-
|
|
30
|
-
|
|
127
|
+
type FluxDir = {
|
|
128
|
+
path: string
|
|
129
|
+
/** List the directory's immediate entries (non-recursive). */
|
|
130
|
+
entries(): Promise<DirEntry[]>
|
|
131
|
+
/** Resolve to whether the directory exists. */
|
|
132
|
+
exists(): Promise<boolean>
|
|
31
133
|
}
|
|
32
134
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Reference a file by path. Lazy: no I/O happens until a method is called.
|
|
137
|
+
*
|
|
138
|
+
* @param path Path to the file.
|
|
139
|
+
*/
|
|
140
|
+
export function file(path: string): FluxFile
|
|
141
|
+
/**
|
|
142
|
+
* Reference a directory by path. Lazy: no I/O happens until a method is
|
|
143
|
+
* called.
|
|
144
|
+
*
|
|
145
|
+
* @param path Path to the directory.
|
|
146
|
+
*/
|
|
147
|
+
export function dir(path: string): FluxDir
|
|
41
148
|
}
|
|
42
149
|
|
|
43
|
-
|
|
150
|
+
declare module "flux:sqlite" {
|
|
151
|
+
/** Values accepted as bound parameters. booleans bind as 0/1. */
|
|
152
|
+
type SqlParam = null | boolean | number | string | Uint8Array
|
|
153
|
+
/** Values returned in result rows. BLOB comes back as Uint8Array. */
|
|
154
|
+
type SqlValue = null | number | string | Uint8Array
|
|
155
|
+
type Row = Record<string, SqlValue>
|
|
156
|
+
|
|
157
|
+
/** The outcome of a write. */
|
|
158
|
+
type RunResult = { changes: number; lastInsertRowid: number }
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A reusable prepared statement. Created with {@link Database.query}; its
|
|
162
|
+
* executions reuse the compiled statement (cached on the connection).
|
|
163
|
+
*/
|
|
164
|
+
export class Statement {
|
|
165
|
+
/** Run the statement and resolve to all matching rows. */
|
|
166
|
+
all(params?: SqlParam[]): Promise<Row[]>
|
|
167
|
+
/** Run the statement and resolve to the first row, or `undefined`. */
|
|
168
|
+
get(params?: SqlParam[]): Promise<Row | undefined>
|
|
169
|
+
/** Run the statement as a write and resolve to its {@link RunResult}. */
|
|
170
|
+
run(params?: SqlParam[]): Promise<RunResult>
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Open mode: "ro" (default, read-only, must exist), "rw" (read-write, must
|
|
175
|
+
* exist), "rw+" (read-write, create if missing).
|
|
176
|
+
*/
|
|
177
|
+
type OpenMode = "ro" | "rw" | "rw+"
|
|
178
|
+
|
|
179
|
+
export class Database {
|
|
180
|
+
/**
|
|
181
|
+
* Open a connection to the database at `path`.
|
|
182
|
+
*
|
|
183
|
+
* @param path Database file path.
|
|
184
|
+
* @param mode Open mode; defaults to "ro".
|
|
185
|
+
*/
|
|
186
|
+
static connect(path: string, mode?: OpenMode): Promise<Database>
|
|
187
|
+
/** Create a reusable prepared statement (synchronous; compiles on first run). */
|
|
188
|
+
query(sql: string): Statement
|
|
189
|
+
/** One-shot write; uses plain prepare (no caching). */
|
|
190
|
+
run(sql: string, params?: SqlParam[]): Promise<RunResult>
|
|
191
|
+
/** Run a multi-statement script (no params), e.g. schema setup / migrations. */
|
|
192
|
+
exec(sql: string): Promise<void>
|
|
193
|
+
/**
|
|
194
|
+
* Run a batch of [sql, params] statements in one transaction (BEGIN/COMMIT,
|
|
195
|
+
* ROLLBACK on any error). Resolves to one result per statement. Statements
|
|
196
|
+
* must be writes/DDL. Cannot branch on intermediate results.
|
|
197
|
+
*/
|
|
198
|
+
transaction(statements: [string, SqlParam[]?][]): Promise<RunResult[]>
|
|
199
|
+
/** Close the connection. */
|
|
200
|
+
close(): Promise<void>
|
|
201
|
+
}
|
|
202
|
+
}
|