@crvouga/mockingbird-service-sqlite 1.2.1 → 2.0.0
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/CHANGELOG.md +25 -1
- package/DISCOVERY.md +48 -0
- package/README.md +49 -6
- package/dist/admin.d.ts +13 -0
- package/dist/admin.js +19604 -0
- package/dist/admin.js.map +7 -0
- package/dist/api/database.d.ts +37 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +270 -13
- package/dist/index.js.map +3 -3
- package/dist/runtime/options.d.ts +5 -0
- package/dist/socket/cli.d.ts +2 -0
- package/dist/socket/cli.js +16467 -0
- package/dist/socket/cli.js.map +7 -0
- package/dist/socket/index.d.ts +58 -0
- package/dist/socket/index.js +16486 -0
- package/dist/socket/index.js.map +7 -0
- package/dist/unstable.js.map +2 -2
- package/package.json +39 -4
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small TCP server in front of the in-memory SQLite engine.
|
|
3
|
+
*
|
|
4
|
+
* SQLite has no client/server wire protocol, so the stock `sqlite3` CLI cannot
|
|
5
|
+
* attach. This entry speaks a length-prefixed JSON frame (`uint32` big-endian
|
|
6
|
+
* length, then UTF-8 JSON, at most 8 MiB) and ships an in-package `connect(uri)`
|
|
7
|
+
* client. URIs look like `sqlite://127.0.0.1:5432/app`. It needs `node:net`, so
|
|
8
|
+
* it stays out of the browser build. Portable queries go through `POST /sql/query`
|
|
9
|
+
* on the admin API.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { connect, serve } from "@crvouga/mockingbird-service-sqlite/socket";
|
|
14
|
+
*
|
|
15
|
+
* const server = await serve("sqlite://127.0.0.1:0/app");
|
|
16
|
+
* const db = await connect(server.url);
|
|
17
|
+
* await db.exec("CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT)");
|
|
18
|
+
* await db.close();
|
|
19
|
+
* await server.close();
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import { type Server } from "node:net";
|
|
25
|
+
import { Database, type DatabaseOptions } from "../api/database.js";
|
|
26
|
+
export type SocketServeOptions = {
|
|
27
|
+
/** TCP port. `0` (the default) picks a free one. */
|
|
28
|
+
port?: number;
|
|
29
|
+
/** Interface to bind. Default `127.0.0.1`. */
|
|
30
|
+
host?: string;
|
|
31
|
+
/** Engine to share. Omit for a fresh deterministic database. */
|
|
32
|
+
database?: Database;
|
|
33
|
+
databaseOptions?: DatabaseOptions;
|
|
34
|
+
/** When set, a frame naming another database is rejected. */
|
|
35
|
+
databaseName?: string;
|
|
36
|
+
/** `sqlite://host:port/name`. An omitted port means `0` (ephemeral) for the server. */
|
|
37
|
+
url?: string;
|
|
38
|
+
};
|
|
39
|
+
export type SqliteServer = {
|
|
40
|
+
readonly port: number;
|
|
41
|
+
readonly host: string;
|
|
42
|
+
/** Bound `sqlite://` URI. */
|
|
43
|
+
readonly url: string;
|
|
44
|
+
readonly database: Database;
|
|
45
|
+
readonly server: Server;
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
export type SqliteSocket = {
|
|
49
|
+
query<T = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<T[]>;
|
|
50
|
+
exec(sql: string): Promise<{
|
|
51
|
+
changes: number;
|
|
52
|
+
}>;
|
|
53
|
+
close(): Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
/** Start a server and resolve once it is listening. A string argument is a `sqlite://` URI. */
|
|
56
|
+
export declare const serve: (input?: SocketServeOptions | string) => Promise<SqliteServer>;
|
|
57
|
+
/** Open a client for a `sqlite://host:port/name` URI. The port must already be listening. */
|
|
58
|
+
export declare const connect: (uri: string) => Promise<SqliteSocket>;
|