@plurnk/plurnk-execs-jq 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 +21 -0
- package/README.md +31 -0
- package/dist/Jq.d.ts +9 -0
- package/dist/Jq.d.ts.map +1 -0
- package/dist/Jq.js +75 -0
- package/dist/Jq.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
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,31 @@
|
|
|
1
|
+
# @plurnk/plurnk-execs-jq
|
|
2
|
+
|
|
3
|
+
`jq` runtime executor for [plurnk-service](https://github.com/plurnk/plurnk-service)'s `exec` scheme. Drives `EXEC[jq]` by shelling the system `jq` binary to filter/transform JSON — no third-party JSON-filter library.
|
|
4
|
+
|
|
5
|
+
A `@plurnk/plurnk-execs-*` sibling built on the [plurnk-execs](https://github.com/plurnk/plurnk-execs) framework.
|
|
6
|
+
|
|
7
|
+
## Invocation model
|
|
8
|
+
|
|
9
|
+
**body = the jq program** (defaults to `.` if empty) · **target = optional data source** — present → jq reads it; **absent → `-n` (null input)** so the body is self-contained.
|
|
10
|
+
|
|
11
|
+
| EXEC | runs | does |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| `<<EXEC[jq]:{"a":1}:EXEC` | `jq -n '{"a":1}'` | construct / validate inline JSON |
|
|
14
|
+
| `<<EXEC[jq]:[1,2,3] \| add:EXEC` | `jq -n '[1,2,3] \| add'` | pure compute, no data |
|
|
15
|
+
| `<<EXEC[jq](data.json):.users[].name:EXEC` | `jq '.users[].name' data.json` | filter a file |
|
|
16
|
+
| `<<EXEC[jq](data.json):EXEC` | `jq '.' data.json` | empty body → identity (pretty-print) |
|
|
17
|
+
| `<<EXEC[jq](exec://…/EXEC#results):.items[]:EXEC` | filter a **prior op's output** | once the service resolves the scheme target ([plurnk-service#201](https://github.com/plurnk/plurnk-service/issues/201)) |
|
|
18
|
+
|
|
19
|
+
Output → the `results` channel (`application/json`).
|
|
20
|
+
|
|
21
|
+
## Effect & availability
|
|
22
|
+
|
|
23
|
+
- **`effect`** — inline/`-n` → `pure`; a file-path data source → `read` (filesystem). Both **auto-run** (jq is a pure filter — no host writes or exec).
|
|
24
|
+
- **`probe`** — `jq` on PATH (`jq --version`).
|
|
25
|
+
- **Errors** emit a `TelemetryEvent` (`source: "exec:jq"`): `jq_error` (program/parse failure), `jq_spawn_failed`.
|
|
26
|
+
|
|
27
|
+
jq is a leaf process, so cancellation is a plain signal kill — no process-group handling needed.
|
|
28
|
+
|
|
29
|
+
## Tests
|
|
30
|
+
|
|
31
|
+
`test:lint`, `test:unit`. jq-dependent tests auto-skip where `jq` is absent.
|
package/dist/Jq.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseExecutor } from "@plurnk/plurnk-execs";
|
|
2
|
+
import type { ChannelDecl, Effect, ExecArgs, ExecResult, RuntimeAvailability } from "@plurnk/plurnk-execs";
|
|
3
|
+
export default class Jq extends BaseExecutor {
|
|
4
|
+
get channels(): Readonly<Record<string, ChannelDecl>>;
|
|
5
|
+
effect(target: string | null): Effect;
|
|
6
|
+
probe(): Promise<RuntimeAvailability>;
|
|
7
|
+
run({ command, cwd, signal, write, setState, emit }: ExecArgs): Promise<ExecResult>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=Jq.d.ts.map
|
package/dist/Jq.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Jq.d.ts","sourceRoot":"","sources":["../src/Jq.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAc3G,MAAM,CAAC,OAAO,OAAO,EAAG,SAAQ,YAAY;IACxC,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAEpD;IAGQ,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM;IAI/B,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAY9C,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CA+B5F"}
|
package/dist/Jq.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { BaseExecutor } from "@plurnk/plurnk-execs";
|
|
3
|
+
// jq executor — shells the system `jq` binary (no third-party JSON-filter lib).
|
|
4
|
+
// Invocation model:
|
|
5
|
+
// body = the jq program (defaults to `.` identity if empty)
|
|
6
|
+
// target = optional data source; present → jq reads that file; absent → `-n`
|
|
7
|
+
// (null input) so the body is self-contained.
|
|
8
|
+
// So `EXEC[jq](data.json):.users[].name` filters a file, `EXEC[jq]:[1,2,3]|add`
|
|
9
|
+
// computes inline, `EXEC[jq](exec://…):.items[]` filters a prior op's output once
|
|
10
|
+
// the service resolves the scheme target to a path (plurnk-service#201).
|
|
11
|
+
//
|
|
12
|
+
// jq is a leaf process (no shell, no grandchildren), so a plain signal-based
|
|
13
|
+
// spawn is sufficient — no process-group machinery needed. It's a pure filter
|
|
14
|
+
// (no host writes / exec), so `effect` is `pure`/`read` — always auto-run.
|
|
15
|
+
export default class Jq extends BaseExecutor {
|
|
16
|
+
get channels() {
|
|
17
|
+
return { results: { mimetype: "application/json" } };
|
|
18
|
+
}
|
|
19
|
+
// Inline/`-n` → pure; a file-path data source → read (filesystem). Both auto-run.
|
|
20
|
+
effect(target) {
|
|
21
|
+
return target ? "read" : "pure";
|
|
22
|
+
}
|
|
23
|
+
async probe() {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
let out = "";
|
|
26
|
+
const child = spawn("jq", ["--version"], { signal: AbortSignal.timeout(3000) });
|
|
27
|
+
child.stdout?.on("data", (c) => { out += c.toString("utf8"); });
|
|
28
|
+
child.on("error", () => resolve({ available: false, detail: "jq not on PATH" }));
|
|
29
|
+
child.on("close", (code) => resolve(code === 0
|
|
30
|
+
? { available: true, detail: out.trim() || "jq" }
|
|
31
|
+
: { available: false, detail: `jq --version exited ${code}` }));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async run({ command, cwd, signal, write, setState, emit }) {
|
|
35
|
+
const program = command.trim() || ".";
|
|
36
|
+
const path = cwd && cwd.length > 0 ? cwd : null;
|
|
37
|
+
// Target present → jq reads the file; absent → -n, the program stands alone.
|
|
38
|
+
const args = path !== null ? [program, path] : ["-n", program];
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
let settled = false;
|
|
41
|
+
const finish = (result, state) => {
|
|
42
|
+
if (settled)
|
|
43
|
+
return;
|
|
44
|
+
settled = true;
|
|
45
|
+
setState("results", state);
|
|
46
|
+
resolve(result);
|
|
47
|
+
};
|
|
48
|
+
let err = "";
|
|
49
|
+
const child = spawn("jq", args, { signal });
|
|
50
|
+
child.stdout?.on("data", (c) => write("results", c.toString("utf8")));
|
|
51
|
+
child.stderr?.on("data", (c) => { err += c.toString("utf8"); });
|
|
52
|
+
child.on("error", (e) => {
|
|
53
|
+
if (e.code === "ABORT_ERR") {
|
|
54
|
+
finish({ status: 499 }, "errored");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
emit({ source: "exec:jq", kind: "jq_spawn_failed", message: e.message });
|
|
58
|
+
finish({ status: 500 }, "errored");
|
|
59
|
+
});
|
|
60
|
+
child.on("close", (code) => {
|
|
61
|
+
if (signal.aborted) {
|
|
62
|
+
finish({ status: 499 }, "errored");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (code === 0) {
|
|
66
|
+
finish({ status: 200 }, "closed");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
emit({ source: "exec:jq", kind: "jq_error", message: err.trim() || `jq exited ${code}` });
|
|
70
|
+
finish({ status: 500 }, "errored");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=Jq.js.map
|
package/dist/Jq.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Jq.js","sourceRoot":"","sources":["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AM,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;YACvC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plurnk/plurnk-execs-jq",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "jq runtime executor for plurnk-service's exec scheme — shells the system jq binary to filter/transform JSON for EXEC[jq].",
|
|
5
|
+
"keywords": ["plurnk", "exec", "runtime", "executor", "jq", "json", "filter"],
|
|
6
|
+
"homepage": "https://github.com/plurnk/plurnk-execs-jq#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/plurnk/plurnk-execs-jq/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/plurnk/plurnk-execs-jq.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": "jq", "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.4.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^25.8.0",
|
|
53
|
+
"typescript": "^6.0.3"
|
|
54
|
+
}
|
|
55
|
+
}
|