just-bash 1.3.1 → 1.4.1

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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * hostname - show or set the system's host name
3
+ *
4
+ * Usage: hostname [NAME]
5
+ *
6
+ * In sandboxed environment, always returns "localhost".
7
+ */
8
+ import type { Command } from "../../types.js";
9
+ export declare const hostname: Command;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * jq AST evaluator
3
+ *
4
+ * Evaluates a parsed jq AST against a JSON value.
5
+ */
6
+ import type { AstNode } from "./parser.js";
7
+ export type JqValue = unknown;
8
+ export interface JqExecutionLimits {
9
+ maxIterations?: number;
10
+ }
11
+ export interface EvalContext {
12
+ vars: Map<string, JqValue>;
13
+ limits: Required<JqExecutionLimits>;
14
+ }
15
+ export interface EvaluateOptions {
16
+ limits?: JqExecutionLimits;
17
+ }
18
+ export declare function evaluate(value: JqValue, ast: AstNode, ctxOrOptions?: EvalContext | EvaluateOptions): JqValue[];
@@ -1,14 +1,7 @@
1
1
  /**
2
2
  * jq - Command-line JSON processor
3
3
  *
4
- * Supports a subset of jq syntax:
5
- * - . (identity)
6
- * - .key, .key.nested (object access)
7
- * - .[0], .[-1] (array indexing)
8
- * - .[] (array/object iteration)
9
- * - .key[] (access then iterate)
10
- * - keys, values, length, type
11
- * - Pipes: .foo | .bar
4
+ * Full jq implementation with proper parser and evaluator.
12
5
  */
13
6
  import type { Command } from "../../types.js";
14
7
  export declare const jqCommand: Command;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * jq filter parser
3
+ *
4
+ * Tokenizes and parses jq filter expressions into an AST.
5
+ */
6
+ export type TokenType = "DOT" | "PIPE" | "COMMA" | "COLON" | "SEMICOLON" | "LPAREN" | "RPAREN" | "LBRACKET" | "RBRACKET" | "LBRACE" | "RBRACE" | "QUESTION" | "PLUS" | "MINUS" | "STAR" | "SLASH" | "PERCENT" | "EQ" | "NE" | "LT" | "LE" | "GT" | "GE" | "AND" | "OR" | "NOT" | "ALT" | "ASSIGN" | "UPDATE_ADD" | "UPDATE_SUB" | "UPDATE_MUL" | "UPDATE_DIV" | "UPDATE_MOD" | "UPDATE_ALT" | "UPDATE_PIPE" | "IDENT" | "NUMBER" | "STRING" | "IF" | "THEN" | "ELIF" | "ELSE" | "END" | "AS" | "TRY" | "CATCH" | "TRUE" | "FALSE" | "NULL" | "REDUCE" | "FOREACH" | "DOTDOT" | "EOF";
7
+ export interface Token {
8
+ type: TokenType;
9
+ value?: string | number;
10
+ pos: number;
11
+ }
12
+ export type AstNode = IdentityNode | FieldNode | IndexNode | SliceNode | IterateNode | PipeNode | CommaNode | LiteralNode | ArrayNode | ObjectNode | ParenNode | BinaryOpNode | UnaryOpNode | CondNode | TryNode | CallNode | VarBindNode | VarRefNode | RecurseNode | OptionalNode | StringInterpNode | UpdateOpNode | ReduceNode | ForeachNode;
13
+ export interface IdentityNode {
14
+ type: "Identity";
15
+ }
16
+ export interface FieldNode {
17
+ type: "Field";
18
+ name: string;
19
+ base?: AstNode;
20
+ }
21
+ export interface IndexNode {
22
+ type: "Index";
23
+ index: AstNode;
24
+ base?: AstNode;
25
+ }
26
+ export interface SliceNode {
27
+ type: "Slice";
28
+ start?: AstNode;
29
+ end?: AstNode;
30
+ base?: AstNode;
31
+ }
32
+ export interface IterateNode {
33
+ type: "Iterate";
34
+ base?: AstNode;
35
+ }
36
+ export interface PipeNode {
37
+ type: "Pipe";
38
+ left: AstNode;
39
+ right: AstNode;
40
+ }
41
+ export interface CommaNode {
42
+ type: "Comma";
43
+ left: AstNode;
44
+ right: AstNode;
45
+ }
46
+ export interface LiteralNode {
47
+ type: "Literal";
48
+ value: unknown;
49
+ }
50
+ export interface ArrayNode {
51
+ type: "Array";
52
+ elements?: AstNode;
53
+ }
54
+ export interface ObjectNode {
55
+ type: "Object";
56
+ entries: {
57
+ key: AstNode | string;
58
+ value: AstNode;
59
+ }[];
60
+ }
61
+ export interface ParenNode {
62
+ type: "Paren";
63
+ expr: AstNode;
64
+ }
65
+ export interface BinaryOpNode {
66
+ type: "BinaryOp";
67
+ op: "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "and" | "or" | "//";
68
+ left: AstNode;
69
+ right: AstNode;
70
+ }
71
+ export interface UnaryOpNode {
72
+ type: "UnaryOp";
73
+ op: "-" | "not";
74
+ operand: AstNode;
75
+ }
76
+ export interface CondNode {
77
+ type: "Cond";
78
+ cond: AstNode;
79
+ then: AstNode;
80
+ elifs: {
81
+ cond: AstNode;
82
+ then: AstNode;
83
+ }[];
84
+ else?: AstNode;
85
+ }
86
+ export interface TryNode {
87
+ type: "Try";
88
+ body: AstNode;
89
+ catch?: AstNode;
90
+ }
91
+ export interface CallNode {
92
+ type: "Call";
93
+ name: string;
94
+ args: AstNode[];
95
+ }
96
+ export interface VarBindNode {
97
+ type: "VarBind";
98
+ name: string;
99
+ value: AstNode;
100
+ body: AstNode;
101
+ }
102
+ export interface VarRefNode {
103
+ type: "VarRef";
104
+ name: string;
105
+ }
106
+ export interface RecurseNode {
107
+ type: "Recurse";
108
+ }
109
+ export interface OptionalNode {
110
+ type: "Optional";
111
+ expr: AstNode;
112
+ }
113
+ export interface StringInterpNode {
114
+ type: "StringInterp";
115
+ parts: (string | AstNode)[];
116
+ }
117
+ export interface UpdateOpNode {
118
+ type: "UpdateOp";
119
+ op: "+=" | "-=" | "*=" | "/=" | "%=" | "//=" | "=" | "|=";
120
+ path: AstNode;
121
+ value: AstNode;
122
+ }
123
+ export interface ReduceNode {
124
+ type: "Reduce";
125
+ expr: AstNode;
126
+ varName: string;
127
+ init: AstNode;
128
+ update: AstNode;
129
+ }
130
+ export interface ForeachNode {
131
+ type: "Foreach";
132
+ expr: AstNode;
133
+ varName: string;
134
+ init: AstNode;
135
+ update: AstNode;
136
+ extract?: AstNode;
137
+ }
138
+ export declare function parse(input: string): AstNode;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * od - dump files in octal and other formats
3
+ *
4
+ * Usage: od [OPTION]... [FILE]...
5
+ *
6
+ * Write an unambiguous representation, octal bytes by default,
7
+ * of FILE to standard output.
8
+ */
9
+ import type { Command } from "../../types.js";
10
+ export declare const od: Command;
@@ -1,6 +1,6 @@
1
1
  import type { Command } from "../types.js";
2
2
  /** All available built-in command names (excludes network commands like curl) */
3
- export type CommandName = "echo" | "cat" | "printf" | "ls" | "mkdir" | "touch" | "rm" | "cp" | "mv" | "ln" | "chmod" | "pwd" | "readlink" | "head" | "tail" | "wc" | "stat" | "grep" | "fgrep" | "egrep" | "sed" | "awk" | "sort" | "uniq" | "comm" | "cut" | "paste" | "tr" | "tee" | "find" | "basename" | "dirname" | "tree" | "du" | "env" | "printenv" | "alias" | "unalias" | "history" | "xargs" | "true" | "false" | "clear" | "bash" | "sh" | "jq" | "base64" | "diff" | "date" | "sleep" | "timeout" | "seq" | "expr" | "md5sum" | "sha1sum" | "sha256sum" | "file" | "html-to-markdown" | "help" | "which";
3
+ export type CommandName = "echo" | "cat" | "printf" | "ls" | "mkdir" | "touch" | "rm" | "cp" | "mv" | "ln" | "chmod" | "pwd" | "readlink" | "head" | "tail" | "wc" | "stat" | "grep" | "fgrep" | "egrep" | "sed" | "awk" | "sort" | "uniq" | "comm" | "cut" | "paste" | "tr" | "tee" | "find" | "basename" | "dirname" | "tree" | "du" | "env" | "printenv" | "alias" | "unalias" | "history" | "xargs" | "true" | "false" | "clear" | "bash" | "sh" | "jq" | "base64" | "diff" | "date" | "sleep" | "timeout" | "seq" | "expr" | "md5sum" | "sha1sum" | "sha256sum" | "file" | "html-to-markdown" | "help" | "which" | "tac" | "hostname" | "od";
4
4
  /** Network command names (only available when network is configured) */
5
5
  export type NetworkCommandName = "curl";
6
6
  /** All command names including network commands */
@@ -0,0 +1,9 @@
1
+ /**
2
+ * tac - concatenate and print files in reverse
3
+ *
4
+ * Usage: tac [OPTION]... [FILE]...
5
+ *
6
+ * Writes each FILE to standard output, last line first.
7
+ */
8
+ import type { Command } from "../../types.js";
9
+ export declare const tac: Command;
@@ -28,6 +28,7 @@ export { handleExit } from "./exit.js";
28
28
  export { handleExport } from "./export.js";
29
29
  export { handleLet } from "./let.js";
30
30
  export { handleLocal } from "./local.js";
31
+ export { handleMapfile } from "./mapfile.js";
31
32
  export { handleRead } from "./read.js";
32
33
  export { handleReturn } from "./return.js";
33
34
  export { handleSet } from "./set.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * mapfile/readarray - Read lines from stdin into an array
3
+ *
4
+ * Usage: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [array]
5
+ * readarray [-d delim] [-n count] [-O origin] [-s count] [-t] [array]
6
+ *
7
+ * Options:
8
+ * -d delim Use delim as line delimiter (default: newline)
9
+ * -n count Read at most count lines (0 = all)
10
+ * -O origin Start assigning at index origin (default: 0)
11
+ * -s count Skip first count lines
12
+ * -t Remove trailing delimiter from each line
13
+ * array Array name (default: MAPFILE)
14
+ */
15
+ import type { ExecResult } from "../../types.js";
16
+ import type { InterpreterContext } from "../types.js";
17
+ export declare function handleMapfile(ctx: InterpreterContext, args: string[], stdin: string): ExecResult;
package/dist/limits.d.ts CHANGED
@@ -19,6 +19,8 @@ export interface ExecutionLimits {
19
19
  maxAwkIterations?: number;
20
20
  /** Maximum command iterations for SED (branch loops) (default: 10000) */
21
21
  maxSedIterations?: number;
22
+ /** Maximum iterations for jq loops (until, while, repeat) (default: 10000) */
23
+ maxJqIterations?: number;
22
24
  }
23
25
  /**
24
26
  * Resolve execution limits by merging user-provided limits with defaults.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81",
84
84
  "scripts": {
85
- "build": "tsc && pnpm build:lib && pnpm build:ai && pnpm build:cli && pnpm build:shell && pnpm build:clean",
85
+ "build": "rm -rf dist && tsc && pnpm build:lib && pnpm build:ai && pnpm build:cli && pnpm build:shell && pnpm build:clean",
86
86
  "build:clean": "find dist -name '*.test.js' -delete && find dist -name '*.test.d.ts' -delete",
87
87
  "build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown",
88
88
  "build:ai": "esbuild dist/ai/index.js --bundle --platform=node --format=esm --minify --outfile=dist/bundle/ai/index.js --external:ai --external:zod --external:diff --external:minimatch --external:sprintf-js --external:turndown",
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as d,b as N,c as g}from"./chunk-GTNBSMZR.js";import"./chunk-SJXDWN5X.js";var O={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input"," --help display this help and exit"]};function b(r,o,e,t=0){if(r===null||r===void 0)return"null";if(typeof r=="boolean"||typeof r=="number")return String(r);if(typeof r=="string")return e?r:JSON.stringify(r);if(Array.isArray(r))return r.length===0?"[]":o?`[${r.map(n=>b(n,!0,!1)).join(",")}]`:`[
3
- ${r.map(n=>" ".repeat(t+1)+b(n,!1,!1,t+1)).join(`,
4
- `)}
5
- ${" ".repeat(t)}]`;if(typeof r=="object"){let u=Object.keys(r);return u.length===0?"{}":o?`{${u.map(s=>`${JSON.stringify(s)}:${b(r[s],!0,!1)}`).join(",")}}`:`{
6
- ${u.map(s=>{let i=b(r[s],!1,!1,t+1);return`${" ".repeat(t+1)}${JSON.stringify(s)}: ${i}`}).join(`,
7
- `)}
8
- ${" ".repeat(t)}}`}return String(r)}function h(r,o){if(o===""||o===".")return[r];let e=o.startsWith(".")?o.slice(1):o;if(e==="")return[r];if(e.startsWith("[]")){let s=e.slice(2);return Array.isArray(r)?r.flatMap(i=>h(i,`.${s}`)):r&&typeof r=="object"?Object.values(r).flatMap(i=>h(i,`.${s}`)):[]}let t=e.match(/^\[(-?\d+)\](.*)/);if(t){let s=Number.parseInt(t[1],10),i=t[2];if(Array.isArray(r)){let c=s<0?r.length+s:s;if(c>=0&&c<r.length)return h(r[c],`.${i}`)}return[null]}let u=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(.*)/);if(u){let s=u[1],i=u[2];if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r[s];if(i.startsWith("[]"))return i=i.slice(2),Array.isArray(a)?a.flatMap(p=>h(p,`.${i}`)):a&&typeof a=="object"?Object.values(a).flatMap(p=>h(p,`.${i}`)):[];if(i.startsWith(".")||i.startsWith("[")||i==="")return h(a,i||".")}return[null]}let n=e.match(/^\["([^"]+)"\](.*)/);if(n){let s=n[1],i=n[2];return r&&typeof r=="object"&&!Array.isArray(r)?h(r[s],`.${i}`):[null]}return[null]}function j(r,o){let e=o.trim();if(e.includes("|")){let t=e.split("|").map(n=>n.trim()),u=[r];for(let n of t)u=u.flatMap(s=>j(s,n));return u}if(e==="keys")return Array.isArray(r)?[r.map((t,u)=>u)]:r&&typeof r=="object"?[Object.keys(r)]:[null];if(e==="values")return Array.isArray(r)?[r]:r&&typeof r=="object"?[Object.values(r)]:[null];if(e==="length")return typeof r=="string"?[r.length]:Array.isArray(r)?[r.length]:r&&typeof r=="object"?[Object.keys(r).length]:r===null?[0]:[null];if(e==="type")return r===null?["null"]:Array.isArray(r)?["array"]:[typeof r];if(e==="first")return Array.isArray(r)&&r.length>0?[r[0]]:[null];if(e==="last")return Array.isArray(r)&&r.length>0?[r[r.length-1]]:[null];if(e==="reverse")return Array.isArray(r)?[[...r].reverse()]:typeof r=="string"?[r.split("").reverse().join("")]:[null];if(e==="sort")return Array.isArray(r)?[[...r].sort()]:[null];if(e==="unique")return Array.isArray(r)?[[...new Set(r.map(t=>JSON.stringify(t)))].map(t=>JSON.parse(t))]:[null];if(e==="flatten")return Array.isArray(r)?[r.flat()]:[null];if(e==="add")return Array.isArray(r)?r.length===0?[null]:r.every(t=>typeof t=="number")?[r.reduce((t,u)=>t+u,0)]:r.every(t=>typeof t=="string")?[r.join("")]:r.every(t=>Array.isArray(t))?[r.flat()]:[null]:[null];if(e==="min")return Array.isArray(r)&&r.length>0?[Math.min(...r)]:[null];if(e==="max")return Array.isArray(r)&&r.length>0?[Math.max(...r)]:[null];if(e==="empty")return[];if(e==="not")return[!r];if(e==="to_entries")return r&&typeof r=="object"&&!Array.isArray(r)?[Object.entries(r).map(([t,u])=>({key:t,value:u}))]:[null];if(e==="from_entries"){if(Array.isArray(r)){let t={};for(let u of r)if(u&&typeof u=="object"){let n=u,s=n.key??n.name??n.k,i=n.value??n.v;s!==void 0&&(t[String(s)]=i)}return[t]}return[null]}if(e==="with_entries")return r&&typeof r=="object"&&!Array.isArray(r)?[Object.entries(r).map(([t,u])=>({key:t,value:u}))]:[null];if(e==="has")return[r!=null];if(e==="in")return[!1];if(e==="getpath")return[r];if(e==="paths"){let t=[],u=(n,s)=>{if(n&&typeof n=="object")if(Array.isArray(n))for(let i=0;i<n.length;i++)t.push([...s,i]),u(n[i],[...s,i]);else for(let i of Object.keys(n))t.push([...s,i]),u(n[i],[...s,i])};return u(r,[]),[t]}if(e==="leaf_paths"){let t=[],u=(n,s)=>{if(n&&typeof n=="object")if(Array.isArray(n))if(n.length===0)t.push(s);else for(let i=0;i<n.length;i++)u(n[i],[...s,i]);else{let i=Object.keys(n);if(i.length===0)t.push(s);else for(let c of i)u(n[c],[...s,c])}else t.push(s)};return u(r,[]),[t]}if(e==="any")return Array.isArray(r)?[r.some(Boolean)]:[!1];if(e==="all")return Array.isArray(r)?[r.every(Boolean)]:[!0];if(e==="group_by")return Array.isArray(r)?[[r]]:[null];if(e==="unique_by")return Array.isArray(r)?[r]:[null];if(e==="join")return Array.isArray(r)?[r.join("")]:[null];if(e==="splits"||e==="split")return typeof r=="string"?[[r]]:[null];if(e==="ascii_downcase"||e==="ascii_upcase")return typeof r=="string"?[e==="ascii_downcase"?r.toLowerCase():r.toUpperCase()]:[null];if(e==="ltrimstr"||e==="rtrimstr")return[r];if(e==="startswith"||e==="endswith")return[!1];if(e==="contains")return[!1];if(e==="inside")return[!1];if(e==="indices")return[[]];if(e==="index"||e==="rindex")return[null];if(e==="test"||e==="match"||e==="capture")return[null];if(e==="floor")return typeof r=="number"?[Math.floor(r)]:[null];if(e==="ceil")return typeof r=="number"?[Math.ceil(r)]:[null];if(e==="round")return typeof r=="number"?[Math.round(r)]:[null];if(e==="sqrt")return typeof r=="number"?[Math.sqrt(r)]:[null];if(e==="fabs"||e==="abs")return typeof r=="number"?[Math.abs(r)]:[null];if(e==="tostring")return typeof r=="string"?[r]:[JSON.stringify(r)];if(e==="tonumber"){if(typeof r=="number")return[r];if(typeof r=="string"){let t=Number(r);return[Number.isNaN(t)?null:t]}return[null]}if(e==="infinite")return[!Number.isFinite(r)];if(e==="nan")return[Number.isNaN(r)];if(e==="isinfinite")return[typeof r=="number"&&!Number.isFinite(r)];if(e==="isnan")return[typeof r=="number"&&Number.isNaN(r)];if(e==="isnormal")return[typeof r=="number"&&Number.isFinite(r)&&r!==0];if(e==="env")return[{}];if(e==="now")return[Date.now()/1e3];if(e===".."){let t=[],u=n=>{if(t.push(n),Array.isArray(n))for(let s of n)u(s);else if(n&&typeof n=="object")for(let s of Object.keys(n))u(n[s])};return u(r),t}return h(r,e)}var $={name:"jq",async execute(r,o){if(N(r))return d(O);let e=!1,t=!1,u=!1,n=!1,s=!1,i=".",c=!1,a=[];for(let l=0;l<r.length;l++){let f=r[l];if(f==="-r"||f==="--raw-output")e=!0;else if(f==="-c"||f==="--compact-output")t=!0;else if(f==="-e"||f==="--exit-status")u=!0;else if(f==="-s"||f==="--slurp")n=!0;else if(f==="-n"||f==="--null-input")s=!0;else if(f==="-")a.push("-");else{if(f.startsWith("--"))return g("jq",f);if(f.startsWith("-"))for(let m of f.slice(1))if(m==="r")e=!0;else if(m==="c")t=!0;else if(m==="e")u=!0;else if(m==="s")n=!0;else if(m==="n")s=!0;else return g("jq",`-${m}`);else c?a.push(f):(i=f,c=!0)}}let p;if(s)p="";else if(a.length===0||a.length===1&&a[0]==="-")p=o.stdin;else try{let l=o.fs.resolvePath(o.cwd,a[0]);p=await o.fs.readFile(l)}catch{return{stdout:"",stderr:`jq: ${a[0]}: No such file or directory
9
- `,exitCode:2}}try{let l;if(s)l=j(null,i);else if(n){let y=[];for(let A of p.trim().split(`
10
- `))A.trim()&&y.push(JSON.parse(A));l=j(y,i)}else{let y=p.trim();if(y.startsWith("{")||y.startsWith("["))l=j(JSON.parse(y),i);else{l=[];for(let A of y.split(`
11
- `))A.trim()&&l.push(...j(JSON.parse(A),i))}}let f=l.map(y=>b(y,t,e)).join(`
12
- `),m=u&&(l.length===0||l.every(y=>y==null||y===!1))?1:0;return{stdout:f?`${f}
13
- `:"",stderr:"",exitCode:m}}catch(l){return{stdout:"",stderr:`jq: parse error: ${l.message}
14
- `,exitCode:5}}}};export{$ as jqCommand};
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as d,b as N,c as g}from"./chunk-GTNBSMZR.js";import"./chunk-SJXDWN5X.js";var O={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input"," --help display this help and exit"]};function b(r,o,e,t=0){if(r===null||r===void 0)return"null";if(typeof r=="boolean"||typeof r=="number")return String(r);if(typeof r=="string")return e?r:JSON.stringify(r);if(Array.isArray(r))return r.length===0?"[]":o?`[${r.map(n=>b(n,!0,!1)).join(",")}]`:`[
3
- ${r.map(n=>" ".repeat(t+1)+b(n,!1,!1,t+1)).join(`,
4
- `)}
5
- ${" ".repeat(t)}]`;if(typeof r=="object"){let u=Object.keys(r);return u.length===0?"{}":o?`{${u.map(s=>`${JSON.stringify(s)}:${b(r[s],!0,!1)}`).join(",")}}`:`{
6
- ${u.map(s=>{let i=b(r[s],!1,!1,t+1);return`${" ".repeat(t+1)}${JSON.stringify(s)}: ${i}`}).join(`,
7
- `)}
8
- ${" ".repeat(t)}}`}return String(r)}function h(r,o){if(o===""||o===".")return[r];let e=o.startsWith(".")?o.slice(1):o;if(e==="")return[r];if(e.startsWith("[]")){let s=e.slice(2);return Array.isArray(r)?r.flatMap(i=>h(i,`.${s}`)):r&&typeof r=="object"?Object.values(r).flatMap(i=>h(i,`.${s}`)):[]}let t=e.match(/^\[(-?\d+)\](.*)/);if(t){let s=Number.parseInt(t[1],10),i=t[2];if(Array.isArray(r)){let c=s<0?r.length+s:s;if(c>=0&&c<r.length)return h(r[c],`.${i}`)}return[null]}let u=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(.*)/);if(u){let s=u[1],i=u[2];if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r[s];if(i.startsWith("[]"))return i=i.slice(2),Array.isArray(a)?a.flatMap(p=>h(p,`.${i}`)):a&&typeof a=="object"?Object.values(a).flatMap(p=>h(p,`.${i}`)):[];if(i.startsWith(".")||i.startsWith("[")||i==="")return h(a,i||".")}return[null]}let n=e.match(/^\["([^"]+)"\](.*)/);if(n){let s=n[1],i=n[2];return r&&typeof r=="object"&&!Array.isArray(r)?h(r[s],`.${i}`):[null]}return[null]}function j(r,o){let e=o.trim();if(e.includes("|")){let t=e.split("|").map(n=>n.trim()),u=[r];for(let n of t)u=u.flatMap(s=>j(s,n));return u}if(e==="keys")return Array.isArray(r)?[r.map((t,u)=>u)]:r&&typeof r=="object"?[Object.keys(r)]:[null];if(e==="values")return Array.isArray(r)?[r]:r&&typeof r=="object"?[Object.values(r)]:[null];if(e==="length")return typeof r=="string"?[r.length]:Array.isArray(r)?[r.length]:r&&typeof r=="object"?[Object.keys(r).length]:r===null?[0]:[null];if(e==="type")return r===null?["null"]:Array.isArray(r)?["array"]:[typeof r];if(e==="first")return Array.isArray(r)&&r.length>0?[r[0]]:[null];if(e==="last")return Array.isArray(r)&&r.length>0?[r[r.length-1]]:[null];if(e==="reverse")return Array.isArray(r)?[[...r].reverse()]:typeof r=="string"?[r.split("").reverse().join("")]:[null];if(e==="sort")return Array.isArray(r)?[[...r].sort()]:[null];if(e==="unique")return Array.isArray(r)?[[...new Set(r.map(t=>JSON.stringify(t)))].map(t=>JSON.parse(t))]:[null];if(e==="flatten")return Array.isArray(r)?[r.flat()]:[null];if(e==="add")return Array.isArray(r)?r.length===0?[null]:r.every(t=>typeof t=="number")?[r.reduce((t,u)=>t+u,0)]:r.every(t=>typeof t=="string")?[r.join("")]:r.every(t=>Array.isArray(t))?[r.flat()]:[null]:[null];if(e==="min")return Array.isArray(r)&&r.length>0?[Math.min(...r)]:[null];if(e==="max")return Array.isArray(r)&&r.length>0?[Math.max(...r)]:[null];if(e==="empty")return[];if(e==="not")return[!r];if(e==="to_entries")return r&&typeof r=="object"&&!Array.isArray(r)?[Object.entries(r).map(([t,u])=>({key:t,value:u}))]:[null];if(e==="from_entries"){if(Array.isArray(r)){let t={};for(let u of r)if(u&&typeof u=="object"){let n=u,s=n.key??n.name??n.k,i=n.value??n.v;s!==void 0&&(t[String(s)]=i)}return[t]}return[null]}if(e==="with_entries")return r&&typeof r=="object"&&!Array.isArray(r)?[Object.entries(r).map(([t,u])=>({key:t,value:u}))]:[null];if(e==="has")return[r!=null];if(e==="in")return[!1];if(e==="getpath")return[r];if(e==="paths"){let t=[],u=(n,s)=>{if(n&&typeof n=="object")if(Array.isArray(n))for(let i=0;i<n.length;i++)t.push([...s,i]),u(n[i],[...s,i]);else for(let i of Object.keys(n))t.push([...s,i]),u(n[i],[...s,i])};return u(r,[]),[t]}if(e==="leaf_paths"){let t=[],u=(n,s)=>{if(n&&typeof n=="object")if(Array.isArray(n))if(n.length===0)t.push(s);else for(let i=0;i<n.length;i++)u(n[i],[...s,i]);else{let i=Object.keys(n);if(i.length===0)t.push(s);else for(let c of i)u(n[c],[...s,c])}else t.push(s)};return u(r,[]),[t]}if(e==="any")return Array.isArray(r)?[r.some(Boolean)]:[!1];if(e==="all")return Array.isArray(r)?[r.every(Boolean)]:[!0];if(e==="group_by")return Array.isArray(r)?[[r]]:[null];if(e==="unique_by")return Array.isArray(r)?[r]:[null];if(e==="join")return Array.isArray(r)?[r.join("")]:[null];if(e==="splits"||e==="split")return typeof r=="string"?[[r]]:[null];if(e==="ascii_downcase"||e==="ascii_upcase")return typeof r=="string"?[e==="ascii_downcase"?r.toLowerCase():r.toUpperCase()]:[null];if(e==="ltrimstr"||e==="rtrimstr")return[r];if(e==="startswith"||e==="endswith")return[!1];if(e==="contains")return[!1];if(e==="inside")return[!1];if(e==="indices")return[[]];if(e==="index"||e==="rindex")return[null];if(e==="test"||e==="match"||e==="capture")return[null];if(e==="floor")return typeof r=="number"?[Math.floor(r)]:[null];if(e==="ceil")return typeof r=="number"?[Math.ceil(r)]:[null];if(e==="round")return typeof r=="number"?[Math.round(r)]:[null];if(e==="sqrt")return typeof r=="number"?[Math.sqrt(r)]:[null];if(e==="fabs"||e==="abs")return typeof r=="number"?[Math.abs(r)]:[null];if(e==="tostring")return typeof r=="string"?[r]:[JSON.stringify(r)];if(e==="tonumber"){if(typeof r=="number")return[r];if(typeof r=="string"){let t=Number(r);return[Number.isNaN(t)?null:t]}return[null]}if(e==="infinite")return[!Number.isFinite(r)];if(e==="nan")return[Number.isNaN(r)];if(e==="isinfinite")return[typeof r=="number"&&!Number.isFinite(r)];if(e==="isnan")return[typeof r=="number"&&Number.isNaN(r)];if(e==="isnormal")return[typeof r=="number"&&Number.isFinite(r)&&r!==0];if(e==="env")return[{}];if(e==="now")return[Date.now()/1e3];if(e===".."){let t=[],u=n=>{if(t.push(n),Array.isArray(n))for(let s of n)u(s);else if(n&&typeof n=="object")for(let s of Object.keys(n))u(n[s])};return u(r),t}return h(r,e)}var $={name:"jq",async execute(r,o){if(N(r))return d(O);let e=!1,t=!1,u=!1,n=!1,s=!1,i=".",c=!1,a=[];for(let l=0;l<r.length;l++){let f=r[l];if(f==="-r"||f==="--raw-output")e=!0;else if(f==="-c"||f==="--compact-output")t=!0;else if(f==="-e"||f==="--exit-status")u=!0;else if(f==="-s"||f==="--slurp")n=!0;else if(f==="-n"||f==="--null-input")s=!0;else if(f==="-")a.push("-");else{if(f.startsWith("--"))return g("jq",f);if(f.startsWith("-"))for(let m of f.slice(1))if(m==="r")e=!0;else if(m==="c")t=!0;else if(m==="e")u=!0;else if(m==="s")n=!0;else if(m==="n")s=!0;else return g("jq",`-${m}`);else c?a.push(f):(i=f,c=!0)}}let p;if(s)p="";else if(a.length===0||a.length===1&&a[0]==="-")p=o.stdin;else try{let l=o.fs.resolvePath(o.cwd,a[0]);p=await o.fs.readFile(l)}catch{return{stdout:"",stderr:`jq: ${a[0]}: No such file or directory
9
- `,exitCode:2}}try{let l;if(s)l=j(null,i);else if(n){let y=[];for(let A of p.trim().split(`
10
- `))A.trim()&&y.push(JSON.parse(A));l=j(y,i)}else{let y=p.trim();if(y.startsWith("{")||y.startsWith("["))l=j(JSON.parse(y),i);else{l=[];for(let A of y.split(`
11
- `))A.trim()&&l.push(...j(JSON.parse(A),i))}}let f=l.map(y=>b(y,t,e)).join(`
12
- `),m=u&&(l.length===0||l.every(y=>y==null||y===!1))?1:0;return{stdout:f?`${f}
13
- `:"",stderr:"",exitCode:m}}catch(l){return{stdout:"",stderr:`jq: parse error: ${l.message}
14
- `,exitCode:5}}}};export{$ as jqCommand};
@@ -1,13 +0,0 @@
1
- import{a as d,b as N,c as g}from"./chunk-74CEPOFO.js";import"./chunk-2RUN43TJ.js";var O={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input"," --help display this help and exit"]};function b(r,o,e,t=0){if(r===null||r===void 0)return"null";if(typeof r=="boolean"||typeof r=="number")return String(r);if(typeof r=="string")return e?r:JSON.stringify(r);if(Array.isArray(r))return r.length===0?"[]":o?`[${r.map(n=>b(n,!0,!1)).join(",")}]`:`[
2
- ${r.map(n=>" ".repeat(t+1)+b(n,!1,!1,t+1)).join(`,
3
- `)}
4
- ${" ".repeat(t)}]`;if(typeof r=="object"){let u=Object.keys(r);return u.length===0?"{}":o?`{${u.map(s=>`${JSON.stringify(s)}:${b(r[s],!0,!1)}`).join(",")}}`:`{
5
- ${u.map(s=>{let i=b(r[s],!1,!1,t+1);return`${" ".repeat(t+1)}${JSON.stringify(s)}: ${i}`}).join(`,
6
- `)}
7
- ${" ".repeat(t)}}`}return String(r)}function h(r,o){if(o===""||o===".")return[r];let e=o.startsWith(".")?o.slice(1):o;if(e==="")return[r];if(e.startsWith("[]")){let s=e.slice(2);return Array.isArray(r)?r.flatMap(i=>h(i,`.${s}`)):r&&typeof r=="object"?Object.values(r).flatMap(i=>h(i,`.${s}`)):[]}let t=e.match(/^\[(-?\d+)\](.*)/);if(t){let s=Number.parseInt(t[1],10),i=t[2];if(Array.isArray(r)){let c=s<0?r.length+s:s;if(c>=0&&c<r.length)return h(r[c],`.${i}`)}return[null]}let u=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(.*)/);if(u){let s=u[1],i=u[2];if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r[s];if(i.startsWith("[]"))return i=i.slice(2),Array.isArray(a)?a.flatMap(p=>h(p,`.${i}`)):a&&typeof a=="object"?Object.values(a).flatMap(p=>h(p,`.${i}`)):[];if(i.startsWith(".")||i.startsWith("[")||i==="")return h(a,i||".")}return[null]}let n=e.match(/^\["([^"]+)"\](.*)/);if(n){let s=n[1],i=n[2];return r&&typeof r=="object"&&!Array.isArray(r)?h(r[s],`.${i}`):[null]}return[null]}function j(r,o){let e=o.trim();if(e.includes("|")){let t=e.split("|").map(n=>n.trim()),u=[r];for(let n of t)u=u.flatMap(s=>j(s,n));return u}if(e==="keys")return Array.isArray(r)?[r.map((t,u)=>u)]:r&&typeof r=="object"?[Object.keys(r)]:[null];if(e==="values")return Array.isArray(r)?[r]:r&&typeof r=="object"?[Object.values(r)]:[null];if(e==="length")return typeof r=="string"?[r.length]:Array.isArray(r)?[r.length]:r&&typeof r=="object"?[Object.keys(r).length]:r===null?[0]:[null];if(e==="type")return r===null?["null"]:Array.isArray(r)?["array"]:[typeof r];if(e==="first")return Array.isArray(r)&&r.length>0?[r[0]]:[null];if(e==="last")return Array.isArray(r)&&r.length>0?[r[r.length-1]]:[null];if(e==="reverse")return Array.isArray(r)?[[...r].reverse()]:typeof r=="string"?[r.split("").reverse().join("")]:[null];if(e==="sort")return Array.isArray(r)?[[...r].sort()]:[null];if(e==="unique")return Array.isArray(r)?[[...new Set(r.map(t=>JSON.stringify(t)))].map(t=>JSON.parse(t))]:[null];if(e==="flatten")return Array.isArray(r)?[r.flat()]:[null];if(e==="add")return Array.isArray(r)?r.length===0?[null]:r.every(t=>typeof t=="number")?[r.reduce((t,u)=>t+u,0)]:r.every(t=>typeof t=="string")?[r.join("")]:r.every(t=>Array.isArray(t))?[r.flat()]:[null]:[null];if(e==="min")return Array.isArray(r)&&r.length>0?[Math.min(...r)]:[null];if(e==="max")return Array.isArray(r)&&r.length>0?[Math.max(...r)]:[null];if(e==="empty")return[];if(e==="not")return[!r];if(e==="to_entries")return r&&typeof r=="object"&&!Array.isArray(r)?[Object.entries(r).map(([t,u])=>({key:t,value:u}))]:[null];if(e==="from_entries"){if(Array.isArray(r)){let t={};for(let u of r)if(u&&typeof u=="object"){let n=u,s=n.key??n.name??n.k,i=n.value??n.v;s!==void 0&&(t[String(s)]=i)}return[t]}return[null]}if(e==="with_entries")return r&&typeof r=="object"&&!Array.isArray(r)?[Object.entries(r).map(([t,u])=>({key:t,value:u}))]:[null];if(e==="has")return[r!=null];if(e==="in")return[!1];if(e==="getpath")return[r];if(e==="paths"){let t=[],u=(n,s)=>{if(n&&typeof n=="object")if(Array.isArray(n))for(let i=0;i<n.length;i++)t.push([...s,i]),u(n[i],[...s,i]);else for(let i of Object.keys(n))t.push([...s,i]),u(n[i],[...s,i])};return u(r,[]),[t]}if(e==="leaf_paths"){let t=[],u=(n,s)=>{if(n&&typeof n=="object")if(Array.isArray(n))if(n.length===0)t.push(s);else for(let i=0;i<n.length;i++)u(n[i],[...s,i]);else{let i=Object.keys(n);if(i.length===0)t.push(s);else for(let c of i)u(n[c],[...s,c])}else t.push(s)};return u(r,[]),[t]}if(e==="any")return Array.isArray(r)?[r.some(Boolean)]:[!1];if(e==="all")return Array.isArray(r)?[r.every(Boolean)]:[!0];if(e==="group_by")return Array.isArray(r)?[[r]]:[null];if(e==="unique_by")return Array.isArray(r)?[r]:[null];if(e==="join")return Array.isArray(r)?[r.join("")]:[null];if(e==="splits"||e==="split")return typeof r=="string"?[[r]]:[null];if(e==="ascii_downcase"||e==="ascii_upcase")return typeof r=="string"?[e==="ascii_downcase"?r.toLowerCase():r.toUpperCase()]:[null];if(e==="ltrimstr"||e==="rtrimstr")return[r];if(e==="startswith"||e==="endswith")return[!1];if(e==="contains")return[!1];if(e==="inside")return[!1];if(e==="indices")return[[]];if(e==="index"||e==="rindex")return[null];if(e==="test"||e==="match"||e==="capture")return[null];if(e==="floor")return typeof r=="number"?[Math.floor(r)]:[null];if(e==="ceil")return typeof r=="number"?[Math.ceil(r)]:[null];if(e==="round")return typeof r=="number"?[Math.round(r)]:[null];if(e==="sqrt")return typeof r=="number"?[Math.sqrt(r)]:[null];if(e==="fabs"||e==="abs")return typeof r=="number"?[Math.abs(r)]:[null];if(e==="tostring")return typeof r=="string"?[r]:[JSON.stringify(r)];if(e==="tonumber"){if(typeof r=="number")return[r];if(typeof r=="string"){let t=Number(r);return[Number.isNaN(t)?null:t]}return[null]}if(e==="infinite")return[!Number.isFinite(r)];if(e==="nan")return[Number.isNaN(r)];if(e==="isinfinite")return[typeof r=="number"&&!Number.isFinite(r)];if(e==="isnan")return[typeof r=="number"&&Number.isNaN(r)];if(e==="isnormal")return[typeof r=="number"&&Number.isFinite(r)&&r!==0];if(e==="env")return[{}];if(e==="now")return[Date.now()/1e3];if(e===".."){let t=[],u=n=>{if(t.push(n),Array.isArray(n))for(let s of n)u(s);else if(n&&typeof n=="object")for(let s of Object.keys(n))u(n[s])};return u(r),t}return h(r,e)}var $={name:"jq",async execute(r,o){if(N(r))return d(O);let e=!1,t=!1,u=!1,n=!1,s=!1,i=".",c=!1,a=[];for(let l=0;l<r.length;l++){let f=r[l];if(f==="-r"||f==="--raw-output")e=!0;else if(f==="-c"||f==="--compact-output")t=!0;else if(f==="-e"||f==="--exit-status")u=!0;else if(f==="-s"||f==="--slurp")n=!0;else if(f==="-n"||f==="--null-input")s=!0;else if(f==="-")a.push("-");else{if(f.startsWith("--"))return g("jq",f);if(f.startsWith("-"))for(let m of f.slice(1))if(m==="r")e=!0;else if(m==="c")t=!0;else if(m==="e")u=!0;else if(m==="s")n=!0;else if(m==="n")s=!0;else return g("jq",`-${m}`);else c?a.push(f):(i=f,c=!0)}}let p;if(s)p="";else if(a.length===0||a.length===1&&a[0]==="-")p=o.stdin;else try{let l=o.fs.resolvePath(o.cwd,a[0]);p=await o.fs.readFile(l)}catch{return{stdout:"",stderr:`jq: ${a[0]}: No such file or directory
8
- `,exitCode:2}}try{let l;if(s)l=j(null,i);else if(n){let y=[];for(let A of p.trim().split(`
9
- `))A.trim()&&y.push(JSON.parse(A));l=j(y,i)}else{let y=p.trim();if(y.startsWith("{")||y.startsWith("["))l=j(JSON.parse(y),i);else{l=[];for(let A of y.split(`
10
- `))A.trim()&&l.push(...j(JSON.parse(A),i))}}let f=l.map(y=>b(y,t,e)).join(`
11
- `),m=u&&(l.length===0||l.every(y=>y==null||y===!1))?1:0;return{stdout:f?`${f}
12
- `:"",stderr:"",exitCode:m}}catch(l){return{stdout:"",stderr:`jq: parse error: ${l.message}
13
- `,exitCode:5}}}};export{$ as jqCommand};