@solidrt/flux-types 0.0.6 → 0.0.7

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 (2) hide show
  1. package/index.d.ts +54 -19
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,16 +1,17 @@
1
1
  declare global {
2
- type FluxDirEntry = {
3
- name: string
4
- type: "file" | "directory" | "symlink" | "other"
2
+ let Flux: {
3
+ on(event: string, callback: (data: any) => void): () => void
4
+ once(event: string, callback: (data: any) => void): () => void
5
5
  }
6
+ }
6
7
 
7
- type FluxDir = {
8
- path: string
9
- entries(): Promise<FluxDirEntry[]>
10
- exists(): Promise<boolean>
8
+ declare module "flux:fs" {
9
+ type DirEntry = {
10
+ name: string
11
+ type: "file" | "directory" | "symlink" | "other"
11
12
  }
12
13
 
13
- type FluxFileStat = {
14
+ type FileStat = {
14
15
  size: number
15
16
  type: string
16
17
  mtime?: number
@@ -22,21 +23,55 @@ declare global {
22
23
  bytes(): Promise<Uint8Array>
23
24
  json(): Promise<any>
24
25
  exists(): Promise<boolean>
25
- stat(): Promise<FluxFileStat>
26
+ stat(): Promise<FileStat>
27
+ write(data: string | Uint8Array): Promise<void>
28
+ }
29
+
30
+ type FluxDir = {
31
+ path: string
32
+ entries(): Promise<DirEntry[]>
33
+ exists(): Promise<boolean>
26
34
  }
27
35
 
28
- type FluxServeOptions = {
29
- port: number
30
- fetch?: (req: Request) => Response | string | Promise<Response | string>
36
+ export function file(path: string): FluxFile
37
+ export function dir(path: string): FluxDir
38
+ }
39
+
40
+ declare module "flux:sqlite" {
41
+ // Values accepted as bound parameters. booleans bind as 0/1.
42
+ type SqlParam = null | boolean | number | string | Uint8Array
43
+ // Values returned in result rows. BLOB comes back as Uint8Array.
44
+ type SqlValue = null | number | string | Uint8Array
45
+ type Row = Record<string, SqlValue>
46
+
47
+ // The outcome of a write.
48
+ type RunResult = { changes: number; lastInsertRowid: number }
49
+
50
+ // A reusable prepared statement. Created with db.query(sql); its executions
51
+ // reuse the compiled statement (cached on the connection).
52
+ export class Statement {
53
+ all(params?: SqlParam[]): Promise<Row[]>
54
+ get(params?: SqlParam[]): Promise<Row | undefined>
55
+ run(params?: SqlParam[]): Promise<RunResult>
31
56
  }
32
57
 
33
- let Flux: {
34
- on(event: string, callback: (data: any) => void): () => void
35
- once(event: string, callback: (data: any) => void): () => void
36
- dir(path: string): FluxDir
37
- file(path: string): FluxFile
38
- write(path: string, data: string | Uint8Array): Promise<void>
39
- serve(options: FluxServeOptions): void
58
+ // Open mode: "ro" (default, read-only, must exist), "rw" (read-write, must
59
+ // exist), "rw+" (read-write, create if missing).
60
+ type OpenMode = "ro" | "rw" | "rw+"
61
+
62
+ export class Database {
63
+ static connect(path: string, mode?: OpenMode): Promise<Database>
64
+ // Create a reusable prepared statement (synchronous; compiles on first run).
65
+ query(sql: string): Statement
66
+ // One-shot write; uses plain prepare (no caching).
67
+ run(sql: string, params?: SqlParam[]): Promise<RunResult>
68
+ // Run a multi-statement script (no params), e.g. schema setup / migrations.
69
+ 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.
73
+ transaction(statements: [string, SqlParam[]?][]): Promise<RunResult[]>
74
+ close(): Promise<void>
40
75
  }
41
76
  }
42
77
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",