@plurnk/plurnk-execs-sqlite 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PossumTech Laboratories
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @plurnk/plurnk-execs-sqlite
2
+
3
+ SQLite runtime executor for [plurnk-service](https://github.com/plurnk/plurnk-service)'s `exec` scheme. Runs the `sqlite` runtime tag **in-process** via Node's builtin `node:sqlite` β€” no subprocess.
4
+
5
+ A `@plurnk/plurnk-execs-*` sibling built on the [plurnk-execs](https://github.com/plurnk/plurnk-execs) framework.
6
+
7
+ ## Runtime tag
8
+
9
+ | Tag | Glyph | Engine |
10
+ |---|---|---|
11
+ | `sqlite` | πŸ—ƒ | `node:sqlite` (Node 25 builtin) |
12
+
13
+ ## Database target
14
+
15
+ The EXEC target slot is the database file; with no target it defaults to an ephemeral in-memory db:
16
+
17
+ ```
18
+ <<EXEC[sqlite]:SELECT * FROM users:EXEC β†’ :memory: (fresh per run)
19
+ <<EXEC[sqlite](./app.db):SELECT * FROM users:EXEC β†’ ./app.db (persistent)
20
+ ```
21
+
22
+ `:memory:` is ephemeral β€” state does not persist across EXECs. Pass a file path for persistence.
23
+
24
+ ## Output
25
+
26
+ Writes to the `results` channel as `application/json`, ready for the jsonpath body-matcher (plurnk-mimetypes' JSON handler):
27
+
28
+ - **Row-returning statements** (SELECT, RETURNING, PRAGMA) β†’ an array of row objects.
29
+ - **Mutations** (INSERT/UPDATE/DELETE/DDL) β†’ `{ changes, lastInsertRowid }`.
30
+
31
+ The query/mutation split is decided by the prepared statement's `columns()`, never by parsing the SQL. One statement per EXEC. Errors emit a `TelemetryEvent` (`source: "exec:sqlite"`): `sqlite_open_failed`, `sqlite_error`.
32
+
33
+ ## Availability & proposal gating
34
+
35
+ `probe()` always reports available (`node:sqlite` is a builtin). `effect()` β€” which will mark `:memory:` as `pure` (auto-run) and a file-backed db as `host` (propose) β€” is pending the contract addition in plurnk-service#182 and lands when that does.
36
+
37
+ ## Tests
38
+
39
+ `test:lint`, `test:unit`.
@@ -0,0 +1,8 @@
1
+ import { BaseExecutor } from "@plurnk/plurnk-execs";
2
+ import type { ChannelDecl, ExecArgs, ExecResult, RuntimeAvailability } from "@plurnk/plurnk-execs";
3
+ export default class Sqlite extends BaseExecutor {
4
+ get channels(): Readonly<Record<string, ChannelDecl>>;
5
+ probe(): Promise<RuntimeAvailability>;
6
+ run({ command, cwd, write, setState, emit }: ExecArgs): Promise<ExecResult>;
7
+ }
8
+ //# sourceMappingURL=Sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sqlite.d.ts","sourceRoot":"","sources":["../src/Sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAuBnG,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,YAAY;IAC5C,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAEpD;IAGc,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAI9C,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CA4BpF"}
package/dist/Sqlite.js ADDED
@@ -0,0 +1,60 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import { BaseExecutor } from "@plurnk/plurnk-execs";
3
+ const MEMORY = ":memory:";
4
+ // node:sqlite can return bigint for large integers; stringify them so the
5
+ // JSON output is always serializable.
6
+ const jsonReplacer = (_key, value) => (typeof value === "bigint" ? value.toString() : value);
7
+ // In-process SQLite executor (a logical runtime, not subprocess). Runs one SQL
8
+ // statement via node:sqlite against the EXEC target db β€” defaulting to an
9
+ // ephemeral `:memory:` when no target is given β€” and writes the result to the
10
+ // `results` channel as application/json, ready for the jsonpath body-matcher.
11
+ //
12
+ // <<EXEC[sqlite]:SELECT * FROM users:EXEC β†’ :memory: (ephemeral)
13
+ // <<EXEC[sqlite](./app.db):SELECT * FROM users:EXEC β†’ ./app.db (persistent)
14
+ //
15
+ // Row-returning statements (SELECT, RETURNING, PRAGMA) write an array of row
16
+ // objects; mutations write `{ changes, lastInsertRowid }`. The query/mutation
17
+ // split is decided by `columns()` β€” never by parsing the SQL.
18
+ //
19
+ // NOTE: `effect()` (per-runtime proposal gating; :memory:→pure, file→host) is
20
+ // pending the contract addition in plurnk-service#182 and lands when that does.
21
+ export default class Sqlite extends BaseExecutor {
22
+ get channels() {
23
+ return { results: { mimetype: "application/json" } };
24
+ }
25
+ // Always available β€” node:sqlite is a Node 25 builtin, in-process.
26
+ async probe() {
27
+ return { available: true, detail: "node:sqlite" };
28
+ }
29
+ async run({ command, cwd, write, setState, emit }) {
30
+ const path = cwd && cwd.length > 0 ? cwd : MEMORY;
31
+ const sql = command.trim();
32
+ const fail = (kind, message) => {
33
+ emit({ source: "exec:sqlite", kind, message });
34
+ setState("results", "errored");
35
+ return { status: 500 };
36
+ };
37
+ let db;
38
+ try {
39
+ db = new DatabaseSync(path);
40
+ }
41
+ catch (err) {
42
+ return fail("sqlite_open_failed", `cannot open database '${path}': ${err.message}`);
43
+ }
44
+ try {
45
+ const stmt = db.prepare(sql);
46
+ // Non-empty columns β‡’ a row-returning statement; empty β‡’ a mutation.
47
+ const output = stmt.columns().length > 0 ? stmt.all() : stmt.run();
48
+ write("results", JSON.stringify(output, jsonReplacer));
49
+ setState("results", "closed");
50
+ return { status: 200 };
51
+ }
52
+ catch (err) {
53
+ return fail("sqlite_error", `${err.message}; db='${path}'`);
54
+ }
55
+ finally {
56
+ db.close();
57
+ }
58
+ }
59
+ }
60
+ //# sourceMappingURL=Sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sqlite.js","sourceRoot":"","sources":["../src/Sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,0EAA0E;AAC1E,sCAAsC;AACtC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAC3D,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAE3D,+EAA+E;AAC/E,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAC9E,EAAE;AACF,4EAA4E;AAC5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,GAAG,CAAC,CAAC;YAC7B,qEAAqE;YACrE,MAAM,MAAM,GAAY,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YAC5E,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;YACvD,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAC9B,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,IAAI,CAAC,cAAc,EAAE,GAAI,GAAa,CAAC,OAAO,SAAS,IAAI,GAAG,CAAC,CAAC;QAC3E,CAAC;gBAAS,CAAC;YACP,EAAE,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ export { default as Sqlite } from "./Sqlite.ts";
2
+ export { default } from "./Sqlite.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default as Sqlite } from "./Sqlite.js";
2
+ export { default } from "./Sqlite.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@plurnk/plurnk-execs-sqlite",
3
+ "version": "0.1.0",
4
+ "description": "SQLite runtime executor for plurnk-service's exec scheme β€” runs the sqlite runtime tag in-process via node:sqlite, results as application/json.",
5
+ "keywords": ["plurnk", "exec", "runtime", "executor", "sqlite", "sql"],
6
+ "homepage": "https://github.com/plurnk/plurnk-execs-sqlite#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/plurnk/plurnk-execs-sqlite/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/plurnk/plurnk-execs-sqlite.git"
13
+ },
14
+ "engines": {
15
+ "node": ">=25"
16
+ },
17
+ "license": "MIT",
18
+ "author": "@wikitopian",
19
+ "type": "module",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "plurnk": {
24
+ "kind": "exec",
25
+ "runtimes": [
26
+ { "name": "sqlite", "glyph": "πŸ—ƒ" }
27
+ ]
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "dist/**/*",
38
+ "README.md"
39
+ ],
40
+ "scripts": {
41
+ "test:lint": "tsc --noEmit",
42
+ "test:unit": "node --test src/**/*.test.ts",
43
+ "test": "npm run test:lint && npm run test:unit",
44
+ "build:dist": "tsc -p tsconfig.build.json",
45
+ "build": "npm run build:dist",
46
+ "prepare": "npm run build"
47
+ },
48
+ "dependencies": {
49
+ "@plurnk/plurnk-execs": "0.3.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^25.8.0",
53
+ "typescript": "^6.0.3"
54
+ }
55
+ }