@solidrt/flux-types 0.0.7 → 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.
Files changed (3) hide show
  1. package/README.md +17 -1
  2. package/index.d.ts +144 -20
  3. 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 reference it in your `tsconfig.json`:
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,8 +1,99 @@
1
- declare global {
2
- let Flux: {
3
- on(event: string, callback: (data: any) => void): () => void
4
- once(event: string, callback: (data: any) => void): () => void
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
  }
67
+
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
88
+ }
89
+
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
6
97
  }
7
98
 
8
99
  declare module "flux:fs" {
@@ -19,60 +110,93 @@ declare module "flux:fs" {
19
110
 
20
111
  type FluxFile = {
21
112
  path: string
113
+ /** Read the whole file as UTF-8 text. */
22
114
  text(): Promise<string>
115
+ /** Read the whole file as raw bytes. */
23
116
  bytes(): Promise<Uint8Array>
117
+ /** Read and parse the file as JSON. */
24
118
  json(): Promise<any>
119
+ /** Resolve to whether the file exists. */
25
120
  exists(): Promise<boolean>
121
+ /** Resolve to the file's metadata (size, type, mtime). */
26
122
  stat(): Promise<FileStat>
123
+ /** Write `data`, replacing any existing contents. */
27
124
  write(data: string | Uint8Array): Promise<void>
28
125
  }
29
126
 
30
127
  type FluxDir = {
31
128
  path: string
129
+ /** List the directory's immediate entries (non-recursive). */
32
130
  entries(): Promise<DirEntry[]>
131
+ /** Resolve to whether the directory exists. */
33
132
  exists(): Promise<boolean>
34
133
  }
35
134
 
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
+ */
36
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
+ */
37
147
  export function dir(path: string): FluxDir
38
148
  }
39
149
 
40
150
  declare module "flux:sqlite" {
41
- // Values accepted as bound parameters. booleans bind as 0/1.
151
+ /** Values accepted as bound parameters. booleans bind as 0/1. */
42
152
  type SqlParam = null | boolean | number | string | Uint8Array
43
- // Values returned in result rows. BLOB comes back as Uint8Array.
153
+ /** Values returned in result rows. BLOB comes back as Uint8Array. */
44
154
  type SqlValue = null | number | string | Uint8Array
45
155
  type Row = Record<string, SqlValue>
46
156
 
47
- // The outcome of a write.
157
+ /** The outcome of a write. */
48
158
  type RunResult = { changes: number; lastInsertRowid: number }
49
159
 
50
- // A reusable prepared statement. Created with db.query(sql); its executions
51
- // reuse the compiled statement (cached on the connection).
160
+ /**
161
+ * A reusable prepared statement. Created with {@link Database.query}; its
162
+ * executions reuse the compiled statement (cached on the connection).
163
+ */
52
164
  export class Statement {
165
+ /** Run the statement and resolve to all matching rows. */
53
166
  all(params?: SqlParam[]): Promise<Row[]>
167
+ /** Run the statement and resolve to the first row, or `undefined`. */
54
168
  get(params?: SqlParam[]): Promise<Row | undefined>
169
+ /** Run the statement as a write and resolve to its {@link RunResult}. */
55
170
  run(params?: SqlParam[]): Promise<RunResult>
56
171
  }
57
172
 
58
- // Open mode: "ro" (default, read-only, must exist), "rw" (read-write, must
59
- // exist), "rw+" (read-write, create if missing).
173
+ /**
174
+ * Open mode: "ro" (default, read-only, must exist), "rw" (read-write, must
175
+ * exist), "rw+" (read-write, create if missing).
176
+ */
60
177
  type OpenMode = "ro" | "rw" | "rw+"
61
178
 
62
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
+ */
63
186
  static connect(path: string, mode?: OpenMode): Promise<Database>
64
- // Create a reusable prepared statement (synchronous; compiles on first run).
187
+ /** Create a reusable prepared statement (synchronous; compiles on first run). */
65
188
  query(sql: string): Statement
66
- // One-shot write; uses plain prepare (no caching).
189
+ /** One-shot write; uses plain prepare (no caching). */
67
190
  run(sql: string, params?: SqlParam[]): Promise<RunResult>
68
- // Run a multi-statement script (no params), e.g. schema setup / migrations.
191
+ /** Run a multi-statement script (no params), e.g. schema setup / migrations. */
69
192
  exec(sql: string): Promise<void>
70
- // Run a batch of [sql, params] statements in one transaction (BEGIN/COMMIT,
71
- // ROLLBACK on any error). Resolves to one result per statement. Statements
72
- // must be writes/DDL. Cannot branch on intermediate results.
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
+ */
73
198
  transaction(statements: [string, SqlParam[]?][]): Promise<RunResult[]>
199
+ /** Close the connection. */
74
200
  close(): Promise<void>
75
201
  }
76
- }
77
-
78
- export {}
202
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",