just-bash 2.0.0 → 2.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/README.md +1 -1
- package/dist/AGENTS.md +131 -3
- package/dist/bin/chunks/chunk-WEONT2KP.js +6 -0
- package/dist/bin/chunks/jq-DT3MD2GZ.js +16 -0
- package/dist/bin/chunks/yq-XRJR6BNP.js +304 -0
- package/dist/bin/just-bash.js +38 -38
- package/dist/bin/shell/chunks/chunk-WEONT2KP.js +6 -0
- package/dist/bin/shell/chunks/jq-DT3MD2GZ.js +16 -0
- package/dist/bin/shell/chunks/yq-XRJR6BNP.js +304 -0
- package/dist/bin/shell/shell.js +54 -54
- package/dist/bundle/browser.js +258 -257
- package/dist/bundle/chunks/chunk-OQ2MSNPG.js +5 -0
- package/dist/bundle/chunks/jq-NZZAXGBX.js +15 -0
- package/dist/bundle/chunks/yq-63LJU3AR.js +303 -0
- package/dist/bundle/index.js +35 -35
- package/dist/commands/query-engine/evaluator.d.ts +25 -0
- package/dist/commands/query-engine/index.d.ts +8 -0
- package/dist/commands/{jq → query-engine}/parser.d.ts +3 -2
- package/dist/commands/registry.d.ts +1 -1
- package/dist/commands/yq/formats.d.ts +64 -0
- package/dist/commands/yq/yq.d.ts +11 -0
- package/package.json +10 -3
- package/dist/bin/chunks/jq-TRAUXD47.js +0 -19
- package/dist/bin/shell/chunks/jq-TRAUXD47.js +0 -19
- package/dist/bundle/chunks/jq-PO3DWIV2.js +0 -18
- package/dist/commands/jq/evaluator.d.ts +0 -18
package/README.md
CHANGED
|
@@ -241,7 +241,7 @@ pnpm shell --no-network
|
|
|
241
241
|
|
|
242
242
|
### Text Processing
|
|
243
243
|
|
|
244
|
-
`awk`, `base64`, `comm`, `cut`, `diff`, `grep` (+ `egrep`, `fgrep`), `head`, `jq`, `md5sum`, `od`, `paste`, `printf`, `sed`, `sha1sum`, `sha256sum`, `sort`, `tac`, `tail`, `tr`, `uniq`, `wc`, `xargs`
|
|
244
|
+
`awk`, `base64`, `comm`, `cut`, `diff`, `grep` (+ `egrep`, `fgrep`), `head`, `jq`, `md5sum`, `od`, `paste`, `printf`, `sed`, `sha1sum`, `sha256sum`, `sort`, `tac`, `tail`, `tr`, `uniq`, `wc`, `xargs`, `yq`
|
|
245
245
|
|
|
246
246
|
### Compression
|
|
247
247
|
|
package/dist/AGENTS.md
CHANGED
|
@@ -64,14 +64,142 @@ const result = await bash.exec("cat input.txt | grep pattern");
|
|
|
64
64
|
|
|
65
65
|
## Available Commands
|
|
66
66
|
|
|
67
|
-
**Text processing**: `awk`, `cat`, `cut`, `grep`, `head`, `jq`, `sed`, `sort`, `tail`, `tr`, `uniq`, `wc`, `xargs`
|
|
67
|
+
**Text processing**: `awk`, `cat`, `comm`, `cut`, `egrep`, `fgrep`, `grep`, `head`, `jq`, `paste`, `sed`, `sort`, `tac`, `tail`, `tr`, `uniq`, `wc`, `xargs`, `yq`
|
|
68
68
|
|
|
69
|
-
**File operations**: `cp`, `find`, `ls`, `mkdir`, `mv`, `rm`, `touch`, `tree`
|
|
69
|
+
**File operations**: `basename`, `chmod`, `cp`, `dirname`, `du`, `file`, `find`, `ln`, `ls`, `mkdir`, `mv`, `od`, `pwd`, `readlink`, `rm`, `stat`, `touch`, `tree`
|
|
70
70
|
|
|
71
|
-
**Utilities**: `base64`, `date`, `diff`, `echo`, `env`, `printf`, `seq`, `tee`
|
|
71
|
+
**Utilities**: `alias`, `base64`, `bash`, `clear`, `curl`, `date`, `diff`, `echo`, `env`, `expr`, `false`, `gzip`, `gunzip`, `help`, `history`, `hostname`, `html-to-markdown`, `md5sum`, `printenv`, `printf`, `seq`, `sh`, `sha1sum`, `sha256sum`, `sleep`, `tee`, `timeout`, `true`, `unalias`, `which`, `zcat`
|
|
72
72
|
|
|
73
73
|
All commands support `--help` for usage details.
|
|
74
74
|
|
|
75
|
+
## Tools by File Format
|
|
76
|
+
|
|
77
|
+
### JSON - `jq`
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Extract field
|
|
81
|
+
jq '.name' data.json
|
|
82
|
+
|
|
83
|
+
# Filter array
|
|
84
|
+
jq '.users[] | select(.active == true)' data.json
|
|
85
|
+
|
|
86
|
+
# Transform structure
|
|
87
|
+
jq '[.items[] | {id, name}]' data.json
|
|
88
|
+
|
|
89
|
+
# From stdin
|
|
90
|
+
echo '{"x":1}' | jq '.x'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### YAML - `yq`
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Extract value
|
|
97
|
+
yq '.config.database.host' config.yaml
|
|
98
|
+
|
|
99
|
+
# Output as JSON
|
|
100
|
+
yq -o json '.' config.yaml
|
|
101
|
+
|
|
102
|
+
# Filter with jq syntax
|
|
103
|
+
yq '.users[] | select(.role == "admin")' users.yaml
|
|
104
|
+
|
|
105
|
+
# Modify file in-place
|
|
106
|
+
yq -i '.version = "2.0"' config.yaml
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### TOML - `yq`
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Read TOML (auto-detected from .toml extension)
|
|
113
|
+
yq '.package.name' Cargo.toml
|
|
114
|
+
yq '.tool.poetry.version' pyproject.toml
|
|
115
|
+
|
|
116
|
+
# Convert TOML to JSON
|
|
117
|
+
yq -o json '.' config.toml
|
|
118
|
+
|
|
119
|
+
# Convert YAML to TOML
|
|
120
|
+
yq -o toml '.' config.yaml
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### CSV/TSV - `yq -p csv`
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Read CSV (auto-detects from .csv/.tsv extension)
|
|
127
|
+
yq '.[0].name' data.csv
|
|
128
|
+
yq '.[0].name' data.tsv
|
|
129
|
+
|
|
130
|
+
# Filter rows
|
|
131
|
+
yq '[.[] | select(.status == "active")]' data.csv
|
|
132
|
+
|
|
133
|
+
# Convert CSV to JSON
|
|
134
|
+
yq -o json '.' data.csv
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Front-matter - `yq --front-matter`
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Extract YAML front-matter from markdown
|
|
141
|
+
yq --front-matter '.title' post.md
|
|
142
|
+
yq -f '.tags[]' blog-post.md
|
|
143
|
+
|
|
144
|
+
# Works with TOML front-matter (+++) too
|
|
145
|
+
yq -f '.date' hugo-post.md
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### XML - `yq -p xml`
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Extract element
|
|
152
|
+
yq '.root.users.user[0].name' data.xml
|
|
153
|
+
|
|
154
|
+
# Access attributes (use +@ prefix)
|
|
155
|
+
yq '.root.item["+@id"]' data.xml
|
|
156
|
+
|
|
157
|
+
# Convert XML to JSON
|
|
158
|
+
yq -p xml -o json '.' data.xml
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### INI - `yq -p ini`
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
# Read INI section value
|
|
165
|
+
yq '.database.host' config.ini
|
|
166
|
+
|
|
167
|
+
# Convert INI to JSON
|
|
168
|
+
yq -p ini -o json '.' config.ini
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### HTML - `html-to-markdown`
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Convert HTML to markdown
|
|
175
|
+
html-to-markdown page.html
|
|
176
|
+
|
|
177
|
+
# From stdin
|
|
178
|
+
echo '<h1>Title</h1><p>Text</p>' | html-to-markdown
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Format Conversion with yq
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
# JSON to YAML
|
|
185
|
+
yq -p json '.' data.json
|
|
186
|
+
|
|
187
|
+
# YAML to JSON
|
|
188
|
+
yq -o json '.' data.yaml
|
|
189
|
+
|
|
190
|
+
# YAML to TOML
|
|
191
|
+
yq -o toml '.' config.yaml
|
|
192
|
+
|
|
193
|
+
# TOML to JSON
|
|
194
|
+
yq -o json '.' Cargo.toml
|
|
195
|
+
|
|
196
|
+
# CSV to JSON
|
|
197
|
+
yq -p csv -o json '.' data.csv
|
|
198
|
+
|
|
199
|
+
# XML to YAML
|
|
200
|
+
yq -p xml '.' data.xml
|
|
201
|
+
```
|
|
202
|
+
|
|
75
203
|
## Common Patterns
|
|
76
204
|
|
|
77
205
|
### Process JSON with jq
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{i as k}from"./chunk-NWWB2XRE.js";var M=1e4;function D(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??M},env:t?.env}}function N(t,e,n){let i=new Map(t.vars);return i.set(e,n),{vars:i,limits:t.limits,env:t.env,root:t.root,currentPath:t.currentPath}}function S(t,e){let n=t;for(let i of e)if(n&&typeof n=="object")n=n[i];else return;return n}function E(t){if(t.type==="Identity")return[];if(t.type==="Field"){let e=t.base?E(t.base):[];return e===null?null:[...e,t.name]}if(t.type==="Index"&&t.index.type==="Literal"){let e=t.base?E(t.base):[];if(e===null)return null;let n=t.index.value;return typeof n=="number"||typeof n=="string"?[...e,n]:null}if(t.type==="Pipe"){let e=E(t.left);return e===null?null:T(e,t.right)}return t.type==="Call"&&(t.name==="parent"||t.name==="root"),null}function T(t,e){if(e.type==="Call"){if(e.name==="parent"){let n=1;if(e.args.length>0&&e.args[0].type==="Literal"){let i=e.args[0].value;typeof i=="number"&&(n=i)}if(n>=0)return t.slice(0,Math.max(0,t.length-n));{let i=-n-1;return t.slice(0,Math.min(i,t.length))}}if(e.name==="root")return[]}if(e.type==="Field"){let n=E(e);if(n!==null)return[...t,...n]}if(e.type==="Index"&&e.index.type==="Literal"){let n=E(e);if(n!==null)return[...t,...n]}if(e.type==="Pipe"){let n=T(t,e.left);return n===null?null:T(n,e.right)}return e.type==="Identity"?t:null}function u(t,e,n){let i=n&&"vars"in n?n:D(n);switch(i.root===void 0&&(i={...i,root:t,currentPath:[]}),e.type){case"Identity":return[t];case"Field":return(e.base?u(t,e.base,i):[t]).flatMap(s=>{if(s&&typeof s=="object"&&!Array.isArray(s)){let o=s[e.name];return[o===void 0?null:o]}return[null]});case"Index":return(e.base?u(t,e.base,i):[t]).flatMap(s=>u(s,e.index,i).flatMap(f=>{if(typeof f=="number"&&Array.isArray(s)){let c=f<0?s.length+f:f;return c>=0&&c<s.length?[s[c]]:[null]}return typeof f=="string"&&s&&typeof s=="object"&&!Array.isArray(s)?[s[f]]:[null]}));case"Slice":return(e.base?u(t,e.base,i):[t]).flatMap(s=>{if(!Array.isArray(s)&&typeof s!="string")return[null];let o=s.length,f=e.start?u(t,e.start,i):[0],c=e.end?u(t,e.end,i):[o];return f.flatMap(p=>c.map(y=>{let h=I(p,o),a=I(y,o);return Array.isArray(s),s.slice(h,a)}))});case"Iterate":return(e.base?u(t,e.base,i):[t]).flatMap(s=>Array.isArray(s)?s:s&&typeof s=="object"?Object.values(s):[]);case"Pipe":{let r=u(t,e.left,i),s=E(e.left);return r.flatMap(o=>{if(s!==null){let f={...i,currentPath:[...i.currentPath??[],...s]};return u(o,e.right,f)}return u(o,e.right,i)})}case"Comma":{let r=u(t,e.left,i),s=u(t,e.right,i);return[...r,...s]}case"Literal":return[e.value];case"Array":return e.elements?[u(t,e.elements,i)]:[[]];case"Object":{let r=[{}];for(let s of e.entries){let o=typeof s.key=="string"?[s.key]:u(t,s.key,i),f=u(t,s.value,i),c=[];for(let p of r)for(let y of o)for(let h of f)c.push({...p,[String(y)]:h});r.length=0,r.push(...c)}return r}case"Paren":return u(t,e.expr,i);case"BinaryOp":return _(t,e.op,e.left,e.right,i);case"UnaryOp":return u(t,e.operand,i).map(s=>e.op==="-"?typeof s=="number"?-s:null:e.op==="not"?!d(s):null);case"Cond":return u(t,e.cond,i).flatMap(s=>{if(d(s))return u(t,e.then,i);for(let o of e.elifs)if(u(t,o.cond,i).some(d))return u(t,o.then,i);return e.else?u(t,e.else,i):[null]});case"Try":try{return u(t,e.body,i)}catch{return e.catch?u(t,e.catch,i):[]}case"Call":return C(t,e.name,e.args,i);case"VarBind":return u(t,e.value,i).flatMap(s=>{let o=N(i,e.name,s);return u(t,e.body,o)});case"VarRef":{if(e.name==="$ENV")return[i.env??{}];let r=i.vars.get(e.name);return r!==void 0?[r]:[null]}case"Recurse":{let r=[],s=new WeakSet,o=f=>{if(f&&typeof f=="object"){if(s.has(f))return;s.add(f)}if(r.push(f),Array.isArray(f))for(let c of f)o(c);else if(f&&typeof f=="object")for(let c of Object.keys(f))o(f[c])};return o(t),r}case"Optional":try{return u(t,e.expr,i)}catch{return[]}case"StringInterp":return[e.parts.map(s=>typeof s=="string"?s:u(t,s,i).map(f=>typeof f=="string"?f:JSON.stringify(f)).join("")).join("")];case"UpdateOp":return[U(t,e.path,e.op,e.value,i)];case"Reduce":{let r=u(t,e.expr,i),s=u(t,e.init,i)[0];for(let o of r){let f=N(i,e.varName,o);s=u(s,e.update,f)[0]}return[s]}case"Foreach":{let r=u(t,e.expr,i),s=u(t,e.init,i)[0],o=[];for(let f of r){let c=N(i,e.varName,f);if(s=u(s,e.update,c)[0],e.extract){let p=u(s,e.extract,c);o.push(...p)}else o.push(s)}return o}default:{let r=e;throw new Error(`Unknown AST node type: ${r.type}`)}}}function I(t,e){return t<0?Math.max(0,e+t):Math.min(t,e)}function U(t,e,n,i,r){function s(c,p){switch(n){case"=":return p;case"|=":return u(c,i,r)[0]??null;case"+=":return typeof c=="number"&&typeof p=="number"||typeof c=="string"&&typeof p=="string"?c+p:Array.isArray(c)&&Array.isArray(p)?[...c,...p]:c&&p&&typeof c=="object"&&typeof p=="object"?{...c,...p}:p;case"-=":return typeof c=="number"&&typeof p=="number"?c-p:c;case"*=":return typeof c=="number"&&typeof p=="number"?c*p:c;case"/=":return typeof c=="number"&&typeof p=="number"?c/p:c;case"%=":return typeof c=="number"&&typeof p=="number"?c%p:c;case"//=":return c===null||c===!1?p:c;default:return p}}function o(c,p,y){switch(p.type){case"Identity":return y(c);case"Field":{if(p.base)return o(c,p.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let a={...h};return a[p.name]=y(a[p.name]),a}return h});if(c&&typeof c=="object"&&!Array.isArray(c)){let h={...c};return h[p.name]=y(h[p.name]),h}return c}case"Index":{let a=u(t,p.index,r)[0];if(p.base)return o(c,p.base,l=>{if(typeof a=="number"&&Array.isArray(l)){let A=[...l],b=a<0?A.length+a:a;return b>=0&&b<A.length&&(A[b]=y(A[b])),A}if(typeof a=="string"&&l&&typeof l=="object"&&!Array.isArray(l)){let A={...l};return A[a]=y(A[a]),A}return l});if(typeof a=="number"&&Array.isArray(c)){let l=[...c],A=a<0?l.length+a:a;return A>=0&&A<l.length&&(l[A]=y(l[A])),l}if(typeof a=="string"&&c&&typeof c=="object"&&!Array.isArray(c)){let l={...c};return l[a]=y(l[a]),l}return c}case"Iterate":{let h=a=>{if(Array.isArray(a))return a.map(l=>y(l));if(a&&typeof a=="object"){let l={};for(let[A,b]of Object.entries(a))l[A]=y(b);return l}return a};return p.base?o(c,p.base,h):h(c)}case"Pipe":{let h=o(c,p.left,a=>a);return o(h,p.right,y)}default:return y(c)}}return o(t,e,c=>{if(n==="|=")return s(c,c);let p=u(t,i,r);return s(c,p[0]??null)})}function B(t,e,n){function i(r,s){switch(s.type){case"Identity":return null;case"Field":{if(r&&typeof r=="object"&&!Array.isArray(r)){let o={...r};return delete o[s.name],o}return r}case"Index":{let f=u(t,s.index,n)[0];if(typeof f=="number"&&Array.isArray(r)){let c=[...r],p=f<0?c.length+f:f;return p>=0&&p<c.length&&c.splice(p,1),c}if(typeof f=="string"&&r&&typeof r=="object"&&!Array.isArray(r)){let c={...r};return delete c[f],c}return r}case"Iterate":return Array.isArray(r)?[]:r&&typeof r=="object"?{}:r;default:return r}}return i(t,e)}function d(t){return t!==null&&t!==!1}function _(t,e,n,i,r){if(e==="and")return u(t,n,r).flatMap(c=>d(c)?u(t,i,r).map(y=>d(y)):[!1]);if(e==="or")return u(t,n,r).flatMap(c=>d(c)?[!0]:u(t,i,r).map(y=>d(y)));if(e==="//"){let c=u(t,n,r).filter(p=>p!=null&&p!==!1);return c.length>0?c:u(t,i,r)}let s=u(t,n,r),o=u(t,i,r);return s.flatMap(f=>o.map(c=>{switch(e){case"+":return typeof f=="number"&&typeof c=="number"||typeof f=="string"&&typeof c=="string"?f+c:Array.isArray(f)&&Array.isArray(c)?[...f,...c]:f&&c&&typeof f=="object"&&typeof c=="object"&&!Array.isArray(f)&&!Array.isArray(c)?{...f,...c}:null;case"-":if(typeof f=="number"&&typeof c=="number")return f-c;if(Array.isArray(f)&&Array.isArray(c)){let p=new Set(c.map(y=>JSON.stringify(y)));return f.filter(y=>!p.has(JSON.stringify(y)))}return null;case"*":return typeof f=="number"&&typeof c=="number"?f*c:typeof f=="string"&&typeof c=="number"?f.repeat(c):f&&c&&typeof f=="object"&&typeof c=="object"&&!Array.isArray(f)&&!Array.isArray(c)?w(f,c):null;case"/":return typeof f=="number"&&typeof c=="number"?f/c:typeof f=="string"&&typeof c=="string"?f.split(c):null;case"%":return typeof f=="number"&&typeof c=="number"?f%c:null;case"==":return g(f,c);case"!=":return!g(f,c);case"<":return j(f,c)<0;case"<=":return j(f,c)<=0;case">":return j(f,c)>0;case">=":return j(f,c)>=0;default:return null}}))}function g(t,e){return JSON.stringify(t)===JSON.stringify(e)}function j(t,e){return typeof t=="number"&&typeof e=="number"?t-e:typeof t=="string"&&typeof e=="string"?t.localeCompare(e):0}function w(t,e){let n={...t};for(let i of Object.keys(e))i in n&&n[i]&&typeof n[i]=="object"&&!Array.isArray(n[i])&&e[i]&&typeof e[i]=="object"&&!Array.isArray(e[i])?n[i]=w(n[i],e[i]):n[i]=e[i];return n}function C(t,e,n,i){switch(e){case"keys":return Array.isArray(t)?[t.map((r,s)=>s)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((r,s)=>s)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"values":return Array.isArray(t)?[t]:t&&typeof t=="object"?[Object.values(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:[null];case"utf8bytelength":return typeof t=="string"?[new TextEncoder().encode(t).length]:[null];case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"empty":return[];case"error":{let r=n.length>0?u(t,n[0],i)[0]:t;throw new Error(String(r))}case"not":return[!d(t)];case"null":return[null];case"true":return[!0];case"false":return[!1];case"first":if(n.length>0){let r=u(t,n[0],i);return r.length>0?[r[0]]:[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(n.length>0){let r=u(t,n[0],i);return r.length>0?[r[r.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(n.length<1)return[null];let s=u(t,n[0],i)[0];if(n.length>1){let o=u(t,n[1],i);return s>=0&&s<o.length?[o[s]]:[]}return Array.isArray(t)?s>=0&&s<t.length?[t[s]]:[null]:[null]}case"range":{if(n.length===0)return[];let r=u(t,n[0],i);if(n.length===1){let p=r[0];return Array.from({length:p},(y,h)=>h)}let s=u(t,n[1],i),o=r[0],f=s[0],c=[];for(let p=o;p<f;p++)c.push(p);return c}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"sort":return Array.isArray(t)?[[...t].sort(m)]:[null];case"sort_by":return!Array.isArray(t)||n.length===0?[null]:[[...t].sort((s,o)=>{let f=u(s,n[0],i)[0],c=u(o,n[0],i)[0];return m(f,c)})];case"unique":if(Array.isArray(t)){let r=new Set,s=[];for(let o of t){let f=JSON.stringify(o);r.has(f)||(r.add(f),s.push(o))}return[s]}return[null];case"unique_by":{if(!Array.isArray(t)||n.length===0)return[null];let r=new Set,s=[];for(let o of t){let f=JSON.stringify(u(o,n[0],i)[0]);r.has(f)||(r.add(f),s.push(o))}return[s]}case"group_by":{if(!Array.isArray(t)||n.length===0)return[null];let r=new Map;for(let s of t){let o=JSON.stringify(u(s,n[0],i)[0]);r.has(o)||r.set(o,[]),r.get(o)?.push(s)}return[[...r.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((r,s)=>m(r,s)>0?r:s)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||n.length===0?[null]:[t.reduce((r,s)=>{let o=u(r,n[0],i)[0],f=u(s,n[0],i)[0];return m(o,f)>0?r:s})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((r,s)=>m(r,s)<0?r:s)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||n.length===0?[null]:[t.reduce((r,s)=>{let o=u(r,n[0],i)[0],f=u(s,n[0],i)[0];return m(o,f)<0?r:s})];case"flatten":{if(!Array.isArray(t))return[null];let r=n.length>0?u(t,n[0],i)[0]:Number.POSITIVE_INFINITY;return[t.flat(r)]}case"add":if(Array.isArray(t)){if(t.length===0)return[null];if(t.every(r=>typeof r=="number"))return[t.reduce((r,s)=>r+s,0)];if(t.every(r=>typeof r=="string"))return[t.join("")];if(t.every(r=>Array.isArray(r)))return[t.flat()];if(t.every(r=>r&&typeof r=="object"&&!Array.isArray(r)))return[Object.assign({},...t)]}return[null];case"any":return n.length>0?Array.isArray(t)?[t.some(r=>d(u(r,n[0],i)[0]))]:[!1]:Array.isArray(t)?[t.some(d)]:[!1];case"all":return n.length>0?Array.isArray(t)?[t.every(r=>d(u(r,n[0],i)[0]))]:[!0]:Array.isArray(t)?[t.every(d)]:[!0];case"select":return n.length===0?[t]:u(t,n[0],i).some(d)?[t]:[];case"map":return n.length===0||!Array.isArray(t)?[null]:[t.flatMap(s=>u(s,n[0],i))];case"map_values":{if(n.length===0)return[null];if(Array.isArray(t))return[t.flatMap(r=>u(r,n[0],i))];if(t&&typeof t=="object"){let r={};for(let[s,o]of Object.entries(t)){let f=u(o,n[0],i);f.length>0&&(r[s]=f[0])}return[r]}return[null]}case"has":{if(n.length===0)return[!1];let s=u(t,n[0],i)[0];return Array.isArray(t)&&typeof s=="number"?[s>=0&&s<t.length]:t&&typeof t=="object"&&typeof s=="string"?[s in t]:[!1]}case"in":{if(n.length===0)return[!1];let s=u(t,n[0],i)[0];return Array.isArray(s)&&typeof t=="number"?[t>=0&&t<s.length]:s&&typeof s=="object"&&typeof t=="string"?[t in s]:[!1]}case"contains":{if(n.length===0)return[!1];let r=u(t,n[0],i);return[O(t,r[0])]}case"inside":{if(n.length===0)return[!1];let r=u(t,n[0],i);return[O(r[0],t)]}case"getpath":{if(n.length===0)return[null];let s=u(t,n[0],i)[0],o=t;for(let f of s){if(o==null)return[null];if(Array.isArray(o)&&typeof f=="number")o=o[f];else if(typeof o=="object"&&typeof f=="string")o=o[f];else return[null]}return[o]}case"setpath":{if(n.length<2)return[null];let s=u(t,n[0],i)[0],f=u(t,n[1],i)[0];return[R(t,s,f)]}case"delpaths":{if(n.length===0)return[t];let s=u(t,n[0],i)[0],o=t;for(let f of s.sort((c,p)=>p.length-c.length))o=x(o,f);return[o]}case"path":{if(n.length===0)return[[]];let r=[];return $(t,n[0],i,[],r),r}case"del":return n.length===0?[t]:[B(t,n[0],i)];case"paths":{let r=[],s=(o,f)=>{if(o&&typeof o=="object")if(Array.isArray(o))for(let c=0;c<o.length;c++)r.push([...f,c]),s(o[c],[...f,c]);else for(let c of Object.keys(o))r.push([...f,c]),s(o[c],[...f,c])};return s(t,[]),n.length>0?r.filter(o=>{let f=t;for(let p of o)if(Array.isArray(f)&&typeof p=="number")f=f[p];else if(f&&typeof f=="object"&&typeof p=="string")f=f[p];else return!1;return u(f,n[0],i).some(d)}):r}case"leaf_paths":{let r=[],s=(o,f)=>{if(o===null||typeof o!="object")r.push(f);else if(Array.isArray(o))for(let c=0;c<o.length;c++)s(o[c],[...f,c]);else for(let c of Object.keys(o))s(o[c],[...f,c])};return s(t,[]),[r]}case"to_entries":return t&&typeof t=="object"&&!Array.isArray(t)?[Object.entries(t).map(([r,s])=>({key:r,value:s}))]:[null];case"from_entries":if(Array.isArray(t)){let r={};for(let s of t)if(s&&typeof s=="object"){let o=s,f=o.key??o.name??o.k,c=o.value??o.v;f!==void 0&&(r[String(f)]=c)}return[r]}return[null];case"with_entries":{if(n.length===0)return[t];if(t&&typeof t=="object"&&!Array.isArray(t)){let s=Object.entries(t).map(([f,c])=>({key:f,value:c})).flatMap(f=>u(f,n[0],i)),o={};for(let f of s)if(f&&typeof f=="object"){let c=f,p=c.key??c.name??c.k,y=c.value??c.v;p!==void 0&&(o[String(p)]=y)}return[o]}return[null]}case"join":{if(!Array.isArray(t))return[null];let r=n.length>0?u(t,n[0],i):[""],s=String(r[0]);return[t.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(s)]}case"split":{if(typeof t!="string"||n.length===0)return[null];let r=u(t,n[0],i),s=String(r[0]);return[t.split(s)]}case"test":{if(typeof t!="string"||n.length===0)return[!1];let r=u(t,n[0],i),s=String(r[0]);try{let o=n.length>1?String(u(t,n[1],i)[0]):"";return[new RegExp(s,o).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||n.length===0)return[null];let r=u(t,n[0],i),s=String(r[0]);try{let o=n.length>1?String(u(t,n[1],i)[0]):"",c=new RegExp(s,`${o}d`).exec(t);if(!c)return[];let p=c.indices;return[{offset:c.index,length:c[0].length,string:c[0],captures:c.slice(1).map((y,h)=>({offset:p?.[h+1]?.[0]??null,length:y?.length??0,string:y??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||n.length===0)return[null];let r=u(t,n[0],i),s=String(r[0]);try{let o=n.length>1?String(u(t,n[1],i)[0]):"",f=new RegExp(s,o),c=t.match(f);return!c||!c.groups?[{}]:[c.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||n.length<2)return[null];let r=u(t,n[0],i),s=u(t,n[1],i),o=String(r[0]),f=String(s[0]);try{let c=n.length>2?String(u(t,n[2],i)[0]):"";return[t.replace(new RegExp(o,c),f)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||n.length<2)return[null];let r=u(t,n[0],i),s=u(t,n[1],i),o=String(r[0]),f=String(s[0]);try{let c=n.length>2?String(u(t,n[2],i)[0]):"g",p=c.includes("g")?c:`${c}g`;return[t.replace(new RegExp(o,p),f)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.toLowerCase()]:[null];case"ascii_upcase":return typeof t=="string"?[t.toUpperCase()]:[null];case"ltrimstr":{if(typeof t!="string"||n.length===0)return[t];let r=u(t,n[0],i),s=String(r[0]);return[t.startsWith(s)?t.slice(s.length):t]}case"rtrimstr":{if(typeof t!="string"||n.length===0)return[t];let r=u(t,n[0],i),s=String(r[0]);return[t.endsWith(s)?t.slice(0,-s.length):t]}case"startswith":{if(typeof t!="string"||n.length===0)return[!1];let r=u(t,n[0],i);return[t.startsWith(String(r[0]))]}case"endswith":{if(typeof t!="string"||n.length===0)return[!1];let r=u(t,n[0],i);return[t.endsWith(String(r[0]))]}case"index":{if(n.length===0)return[null];let s=u(t,n[0],i)[0];if(typeof t=="string"&&typeof s=="string"){let o=t.indexOf(s);return[o>=0?o:null]}if(Array.isArray(t)){let o=t.findIndex(f=>g(f,s));return[o>=0?o:null]}return[null]}case"rindex":{if(n.length===0)return[null];let s=u(t,n[0],i)[0];if(typeof t=="string"&&typeof s=="string"){let o=t.lastIndexOf(s);return[o>=0?o:null]}if(Array.isArray(t)){for(let o=t.length-1;o>=0;o--)if(g(t[o],s))return[o];return[null]}return[null]}case"indices":{if(n.length===0)return[[]];let s=u(t,n[0],i)[0],o=[];if(typeof t=="string"&&typeof s=="string"){let f=t.indexOf(s);for(;f!==-1;)o.push(f),f=t.indexOf(s,f+1)}else if(Array.isArray(t))for(let f=0;f<t.length;f++)g(t[f],s)&&o.push(f);return[o]}case"floor":return typeof t=="number"?[Math.floor(t)]:[null];case"ceil":return typeof t=="number"?[Math.ceil(t)]:[null];case"round":return typeof t=="number"?[Math.round(t)]:[null];case"sqrt":return typeof t=="number"?[Math.sqrt(t)]:[null];case"fabs":case"abs":return typeof t=="number"?[Math.abs(t)]:[null];case"log":return typeof t=="number"?[Math.log(t)]:[null];case"log10":return typeof t=="number"?[Math.log10(t)]:[null];case"log2":return typeof t=="number"?[Math.log2(t)]:[null];case"exp":return typeof t=="number"?[Math.exp(t)]:[null];case"exp10":return typeof t=="number"?[10**t]:[null];case"exp2":return typeof t=="number"?[2**t]:[null];case"pow":{if(typeof t!="number"||n.length===0)return[null];let s=u(t,n[0],i)[0];return[t**s]}case"sin":return typeof t=="number"?[Math.sin(t)]:[null];case"cos":return typeof t=="number"?[Math.cos(t)]:[null];case"tan":return typeof t=="number"?[Math.tan(t)]:[null];case"asin":return typeof t=="number"?[Math.asin(t)]:[null];case"acos":return typeof t=="number"?[Math.acos(t)]:[null];case"atan":return typeof t=="number"?[Math.atan(t)]:[null];case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let r=Number(t);return[Number.isNaN(r)?null:r]}return[null];case"infinite":return[!Number.isFinite(t)];case"nan":return[Number.isNaN(t)];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"now":return[Date.now()/1e3];case"env":return[i.env??{}];case"recurse":{if(n.length===0){let f=[],c=p=>{if(f.push(p),Array.isArray(p))for(let y of p)c(y);else if(p&&typeof p=="object")for(let y of Object.keys(p))c(p[y])};return c(t),f}let r=[],s=new Set,o=f=>{let c=JSON.stringify(f);if(s.has(c))return;s.add(c),r.push(f);let p=u(f,n[0],i);for(let y of p)y!=null&&o(y)};return o(t),r}case"recurse_down":return C(t,"recurse",n,i);case"walk":{if(n.length===0)return[t];let r=new WeakSet,s=o=>{if(o&&typeof o=="object"){if(r.has(o))return o;r.add(o)}let f;if(Array.isArray(o))f=o.map(s);else if(o&&typeof o=="object"){let p={};for(let[y,h]of Object.entries(o))p[y]=s(h);f=p}else f=o;return u(f,n[0],i)[0]};return[s(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let r=Math.max(...t.map(o=>Array.isArray(o)?o.length:0)),s=[];for(let o=0;o<r;o++)s.push(t.map(f=>Array.isArray(f)?f[o]:null));return[s]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(r=>r.codePointAt(0))]:[null];case"implode":return Array.isArray(t)?[String.fromCodePoint(...t)]:[null];case"tojson":case"tojsonstream":return[JSON.stringify(t)];case"fromjson":{if(typeof t=="string")try{return[JSON.parse(t)]}catch{return[null]}return[null]}case"limit":{if(n.length<2)return[];let s=u(t,n[0],i)[0];return u(t,n[1],i).slice(0,s)}case"until":{if(n.length<2)return[t];let r=t,s=i.limits.maxIterations;for(let o=0;o<s;o++){if(u(r,n[0],i).some(d))return[r];let c=u(r,n[1],i);if(c.length===0)return[r];r=c[0]}throw new k(`jq until: too many iterations (${s}), increase executionLimits.maxJqIterations`,"iterations")}case"while":{if(n.length<2)return[t];let r=[],s=t,o=i.limits.maxIterations;for(let f=0;f<o&&u(s,n[0],i).some(d);f++){r.push(s);let p=u(s,n[1],i);if(p.length===0)break;s=p[0]}if(r.length>=o)throw new k(`jq while: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return r}case"repeat":{if(n.length===0)return[t];let r=[],s=t,o=i.limits.maxIterations;for(let f=0;f<o;f++){r.push(s);let c=u(s,n[0],i);if(c.length===0)break;s=c[0]}if(r.length>=o)throw new k(`jq repeat: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return r}case"debug":return[t];case"input_line_number":return[1];case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(s=>{let o=String(s??"");return o.includes(",")||o.includes('"')||o.includes(`
|
|
3
|
+
`)?`"${o.replace(/"/g,'""')}"`:o}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(r=>String(r??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":return[JSON.stringify(t)];case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];case"parent":{if(i.root===void 0||i.currentPath===void 0)return[];let r=i.currentPath;if(r.length===0)return[];let s=n.length>0?u(t,n[0],i)[0]:1;if(s>=0){if(s>r.length)return[];let o=r.slice(0,r.length-s);return[S(i.root,o)]}else{let o=-s-1;if(o>=r.length)return[t];let f=r.slice(0,o);return[S(i.root,f)]}}case"parents":{if(i.root===void 0||i.currentPath===void 0)return[[]];let r=i.currentPath,s=[];for(let o=r.length-1;o>=0;o--)s.push(S(i.root,r.slice(0,o)));return[s]}case"root":return i.root!==void 0?[i.root]:[];default:throw new Error(`Unknown function: ${e}`)}}function m(t,e){let n=s=>s===null?0:typeof s=="boolean"?1:typeof s=="number"?2:typeof s=="string"?3:Array.isArray(s)?4:typeof s=="object"?5:6,i=n(t),r=n(e);if(i!==r)return i-r;if(typeof t=="number"&&typeof e=="number")return t-e;if(typeof t=="string"&&typeof e=="string")return t.localeCompare(e);if(typeof t=="boolean"&&typeof e=="boolean")return(t?1:0)-(e?1:0);if(Array.isArray(t)&&Array.isArray(e)){for(let s=0;s<Math.min(t.length,e.length);s++){let o=m(t[s],e[s]);if(o!==0)return o}return t.length-e.length}return 0}function O(t,e){if(g(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return e.every(n=>t.some(i=>O(i,n)));if(t&&e&&typeof t=="object"&&typeof e=="object"&&!Array.isArray(t)&&!Array.isArray(e)){let n=t,i=e;return Object.keys(i).every(r=>r in n&&O(n[r],i[r]))}return!1}function R(t,e,n){if(e.length===0)return n;let[i,...r]=e;if(typeof i=="number"){let o=Array.isArray(t)?[...t]:[];for(;o.length<=i;)o.push(null);return o[i]=R(o[i],r,n),o}let s=t&&typeof t=="object"&&!Array.isArray(t)?{...t}:{};return s[i]=R(s[i],r,n),s}function x(t,e){if(e.length===0)return null;if(e.length===1){let r=e[0];if(Array.isArray(t)&&typeof r=="number"){let s=[...t];return s.splice(r,1),s}if(t&&typeof t=="object"&&!Array.isArray(t)){let s={...t};return delete s[String(r)],s}return t}let[n,...i]=e;if(Array.isArray(t)&&typeof n=="number"){let r=[...t];return r[n]=x(r[n],i),r}if(t&&typeof t=="object"&&!Array.isArray(t)){let r={...t};return r[String(n)]=x(r[String(n)],i),r}return t}function $(t,e,n,i,r){u(t,e,n).length>0&&r.push(i)}var F={and:"AND",or:"OR",not:"NOT",if:"IF",then:"THEN",elif:"ELIF",else:"ELSE",end:"END",as:"AS",try:"TRY",catch:"CATCH",true:"TRUE",false:"FALSE",null:"NULL",reduce:"REDUCE",foreach:"FOREACH"};function L(t){let e=[],n=0,i=(p=0)=>t[n+p],r=()=>t[n++],s=()=>n>=t.length,o=p=>p>="0"&&p<="9",f=p=>p>="a"&&p<="z"||p>="A"&&p<="Z"||p==="_",c=p=>f(p)||o(p);for(;!s();){let p=n,y=r();if(!(y===" "||y===" "||y===`
|
|
4
|
+
`||y==="\r")){if(y==="#"){for(;!s()&&i()!==`
|
|
5
|
+
`;)r();continue}if(y==="."&&i()==="."){r(),e.push({type:"DOTDOT",pos:p});continue}if(y==="="&&i()==="="){r(),e.push({type:"EQ",pos:p});continue}if(y==="!"&&i()==="="){r(),e.push({type:"NE",pos:p});continue}if(y==="<"&&i()==="="){r(),e.push({type:"LE",pos:p});continue}if(y===">"&&i()==="="){r(),e.push({type:"GE",pos:p});continue}if(y==="/"&&i()==="/"){r(),i()==="="?(r(),e.push({type:"UPDATE_ALT",pos:p})):e.push({type:"ALT",pos:p});continue}if(y==="+"&&i()==="="){r(),e.push({type:"UPDATE_ADD",pos:p});continue}if(y==="-"&&i()==="="){r(),e.push({type:"UPDATE_SUB",pos:p});continue}if(y==="*"&&i()==="="){r(),e.push({type:"UPDATE_MUL",pos:p});continue}if(y==="/"&&i()==="="){r(),e.push({type:"UPDATE_DIV",pos:p});continue}if(y==="%"&&i()==="="){r(),e.push({type:"UPDATE_MOD",pos:p});continue}if(y==="="&&i()!=="="){e.push({type:"ASSIGN",pos:p});continue}if(y==="."){e.push({type:"DOT",pos:p});continue}if(y==="|"){i()==="="?(r(),e.push({type:"UPDATE_PIPE",pos:p})):e.push({type:"PIPE",pos:p});continue}if(y===","){e.push({type:"COMMA",pos:p});continue}if(y===":"){e.push({type:"COLON",pos:p});continue}if(y===";"){e.push({type:"SEMICOLON",pos:p});continue}if(y==="("){e.push({type:"LPAREN",pos:p});continue}if(y===")"){e.push({type:"RPAREN",pos:p});continue}if(y==="["){e.push({type:"LBRACKET",pos:p});continue}if(y==="]"){e.push({type:"RBRACKET",pos:p});continue}if(y==="{"){e.push({type:"LBRACE",pos:p});continue}if(y==="}"){e.push({type:"RBRACE",pos:p});continue}if(y==="?"){e.push({type:"QUESTION",pos:p});continue}if(y==="+"){e.push({type:"PLUS",pos:p});continue}if(y==="-"){if(o(i())){let h=y;for(;!s()&&(o(i())||i()===".");)h+=r();e.push({type:"NUMBER",value:Number(h),pos:p});continue}e.push({type:"MINUS",pos:p});continue}if(y==="*"){e.push({type:"STAR",pos:p});continue}if(y==="/"){e.push({type:"SLASH",pos:p});continue}if(y==="%"){e.push({type:"PERCENT",pos:p});continue}if(y==="<"){e.push({type:"LT",pos:p});continue}if(y===">"){e.push({type:"GT",pos:p});continue}if(o(y)){let h=y;for(;!s()&&(o(i())||i()==="."||i()==="e"||i()==="E");)(i()==="e"||i()==="E")&&(t[n+1]==="+"||t[n+1]==="-")&&(h+=r()),h+=r();e.push({type:"NUMBER",value:Number(h),pos:p});continue}if(y==='"'){let h="";for(;!s()&&i()!=='"';)if(i()==="\\"){if(r(),s())break;let a=r();switch(a){case"n":h+=`
|
|
6
|
+
`;break;case"r":h+="\r";break;case"t":h+=" ";break;case"\\":h+="\\";break;case'"':h+='"';break;case"(":h+="\\(";break;default:h+=a}}else h+=r();s()||r(),e.push({type:"STRING",value:h,pos:p});continue}if(f(y)||y==="$"||y==="@"){let h=y;for(;!s()&&c(i());)h+=r();let a=F[h];a?e.push({type:a,pos:p}):e.push({type:"IDENT",value:h,pos:p});continue}throw new Error(`Unexpected character '${y}' at position ${p}`)}}return e.push({type:"EOF",pos:n}),e}var P=class t{tokens;pos=0;constructor(e){this.tokens=e}peek(e=0){return this.tokens[this.pos+e]??{type:"EOF",pos:-1}}advance(){return this.tokens[this.pos++]}check(e){return this.peek().type===e}match(...e){for(let n of e)if(this.check(n))return this.advance();return null}expect(e,n){if(!this.check(e))throw new Error(`${n} at position ${this.peek().pos}, got ${this.peek().type}`);return this.advance()}parse(){let e=this.parseExpr();if(!this.check("EOF"))throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`);return e}parseExpr(){return this.parsePipe()}parsePipe(){let e=this.parseComma();for(;this.match("PIPE");){let n=this.parseComma();e={type:"Pipe",left:e,right:n}}return e}parseComma(){let e=this.parseVarBind();for(;this.match("COMMA");){let n=this.parseVarBind();e={type:"Comma",left:e,right:n}}return e}parseVarBind(){let e=this.parseUpdate();if(this.match("AS")){let n=this.expect("IDENT","Expected variable name after 'as'"),i=n.value;if(!i.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.pos}`);this.expect("PIPE","Expected '|' after variable binding");let r=this.parseExpr();return{type:"VarBind",name:i,value:e,body:r}}return e}parseUpdate(){let e=this.parseAlt(),n={ASSIGN:"=",UPDATE_ADD:"+=",UPDATE_SUB:"-=",UPDATE_MUL:"*=",UPDATE_DIV:"/=",UPDATE_MOD:"%=",UPDATE_ALT:"//=",UPDATE_PIPE:"|="},i=this.match("ASSIGN","UPDATE_ADD","UPDATE_SUB","UPDATE_MUL","UPDATE_DIV","UPDATE_MOD","UPDATE_ALT","UPDATE_PIPE");if(i){let r=this.parseVarBind();return{type:"UpdateOp",op:n[i.type],path:e,value:r}}return e}parseAlt(){let e=this.parseOr();for(;this.match("ALT");){let n=this.parseOr();e={type:"BinaryOp",op:"//",left:e,right:n}}return e}parseOr(){let e=this.parseAnd();for(;this.match("OR");){let n=this.parseAnd();e={type:"BinaryOp",op:"or",left:e,right:n}}return e}parseAnd(){let e=this.parseNot();for(;this.match("AND");){let n=this.parseNot();e={type:"BinaryOp",op:"and",left:e,right:n}}return e}parseNot(){return this.parseComparison()}parseComparison(){let e=this.parseAddSub(),n={EQ:"==",NE:"!=",LT:"<",LE:"<=",GT:">",GE:">="},i=this.match("EQ","NE","LT","LE","GT","GE");if(i){let r=this.parseAddSub();e={type:"BinaryOp",op:n[i.type],left:e,right:r}}return e}parseAddSub(){let e=this.parseMulDiv();for(;;)if(this.match("PLUS")){let n=this.parseMulDiv();e={type:"BinaryOp",op:"+",left:e,right:n}}else if(this.match("MINUS")){let n=this.parseMulDiv();e={type:"BinaryOp",op:"-",left:e,right:n}}else break;return e}parseMulDiv(){let e=this.parseUnary();for(;;)if(this.match("STAR")){let n=this.parseUnary();e={type:"BinaryOp",op:"*",left:e,right:n}}else if(this.match("SLASH")){let n=this.parseUnary();e={type:"BinaryOp",op:"/",left:e,right:n}}else if(this.match("PERCENT")){let n=this.parseUnary();e={type:"BinaryOp",op:"%",left:e,right:n}}else break;return e}parseUnary(){return this.match("MINUS")?{type:"UnaryOp",op:"-",operand:this.parseUnary()}:this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match("QUESTION"))e={type:"Optional",expr:e};else if(this.check("DOT")&&this.peek(1).type==="IDENT")this.advance(),e={type:"Field",name:this.expect("IDENT","Expected field name").value,base:e};else if(this.check("LBRACKET"))if(this.advance(),this.match("RBRACKET"))e={type:"Iterate",base:e};else if(this.check("COLON")){this.advance();let n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",end:n,base:e}}else{let n=this.parseExpr();if(this.match("COLON")){let i=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),e={type:"Slice",start:n,end:i,base:e}}else this.expect("RBRACKET","Expected ']'"),e={type:"Index",index:n,base:e}}else break;return e}parsePrimary(){if(this.match("DOTDOT"))return{type:"Recurse"};if(this.match("DOT")){if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let n=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:n}}let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:e,end:n}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:e}}return this.check("IDENT")?{type:"Field",name:this.advance().value}:{type:"Identity"}}if(this.match("TRUE"))return{type:"Literal",value:!0};if(this.match("FALSE"))return{type:"Literal",value:!1};if(this.match("NULL"))return{type:"Literal",value:null};if(this.check("NUMBER"))return{type:"Literal",value:this.advance().value};if(this.check("STRING")){let n=this.advance().value;return n.includes("\\(")?this.parseStringInterpolation(n):{type:"Literal",value:n}}if(this.match("LBRACKET")){if(this.match("RBRACKET"))return{type:"Array"};let e=this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Array",elements:e}}if(this.match("LBRACE"))return this.parseObjectConstruction();if(this.match("LPAREN")){let e=this.parseExpr();return this.expect("RPAREN","Expected ')'"),{type:"Paren",expr:e}}if(this.match("IF"))return this.parseIf();if(this.match("TRY")){let e=this.parsePostfix(),n;return this.match("CATCH")&&(n=this.parsePostfix()),{type:"Try",body:e,catch:n}}if(this.match("REDUCE")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after reduce expression");let n=this.expect("IDENT","Expected variable name"),i=n.value;if(!i.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.pos}`);this.expect("LPAREN","Expected '(' after variable");let r=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let s=this.parseExpr();return this.expect("RPAREN","Expected ')' after update expression"),{type:"Reduce",expr:e,varName:i,init:r,update:s}}if(this.match("FOREACH")){let e=this.parsePostfix();this.expect("AS","Expected 'as' after foreach expression");let n=this.expect("IDENT","Expected variable name"),i=n.value;if(!i.startsWith("$"))throw new Error(`Variable name must start with $ at position ${n.pos}`);this.expect("LPAREN","Expected '(' after variable");let r=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let s=this.parseExpr(),o;return this.match("SEMICOLON")&&(o=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions"),{type:"Foreach",expr:e,varName:i,init:r,update:s,extract:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let n=this.advance().value;if(n.startsWith("$"))return{type:"VarRef",name:n};if(this.match("LPAREN")){let i=[];if(!this.check("RPAREN"))for(i.push(this.parseExpr());this.match("SEMICOLON");)i.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:n,args:i}}return{type:"Call",name:n,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let e=[];if(!this.check("RBRACE"))do{let n,i;if(this.match("LPAREN"))n=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),i=this.parseObjectValue();else if(this.check("IDENT")){let r=this.advance().value;this.match("COLON")?(n=r,i=this.parseObjectValue()):(n=r,i={type:"Field",name:r})}else if(this.check("STRING"))n=this.advance().value,this.expect("COLON","Expected ':'"),i=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);e.push({key:n,value:i})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:e}}parseObjectValue(){let e=this.parseVarBind();for(;this.match("PIPE");){let n=this.parseVarBind();e={type:"Pipe",left:e,right:n}}return e}parseIf(){let e=this.parseExpr();this.expect("THEN","Expected 'then'");let n=this.parseExpr(),i=[];for(;this.match("ELIF");){let s=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let o=this.parseExpr();i.push({cond:s,then:o})}let r;return this.match("ELSE")&&(r=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:e,then:n,elifs:i,else:r}}parseStringInterpolation(e){let n=[],i="",r=0;for(;r<e.length;)if(e[r]==="\\"&&e[r+1]==="("){i&&(n.push(i),i=""),r+=2;let s=1,o="";for(;r<e.length&&s>0;)e[r]==="("?s++:e[r]===")"&&s--,s>0&&(o+=e[r]),r++;let f=L(o),c=new t(f);n.push(c.parse())}else i+=e[r],r++;return i&&n.push(i),{type:"StringInterp",parts:n}}};function q(t){let e=L(t);return new P(e).parse()}export{u as a,q as b};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as y,b as x}from"./chunk-WEONT2KP.js";import{i as q}from"./chunk-NWWB2XRE.js";import{a as w,b as N,c as O}from"./chunk-GTNBSMZR.js";import"./chunk-SJXDWN5X.js";var E={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","-j, --join-output don't print newlines after each output","-a, --ascii force ASCII output","-S, --sort-keys sort object keys","-C, --color colorize output (ignored)","-M, --monochrome monochrome output (ignored)"," --tab use tabs for indentation"," --help display this help and exit"]};function g(t,o,d,u,f,l=0){if(t===null||t===void 0)return"null";if(typeof t=="boolean")return String(t);if(typeof t=="number")return Number.isFinite(t)?String(t):"null";if(typeof t=="string")return d?t:JSON.stringify(t);let a=f?" ":" ";if(Array.isArray(t))return t.length===0?"[]":o?`[${t.map(p=>g(p,!0,!1,u,f)).join(",")}]`:`[
|
|
3
|
+
${t.map(p=>a.repeat(l+1)+g(p,!1,!1,u,f,l+1)).join(`,
|
|
4
|
+
`)}
|
|
5
|
+
${a.repeat(l)}]`;if(typeof t=="object"){let n=Object.keys(t);return u&&(n=n.sort()),n.length===0?"{}":o?`{${n.map(c=>`${JSON.stringify(c)}:${g(t[c],!0,!1,u,f)}`).join(",")}}`:`{
|
|
6
|
+
${n.map(c=>{let S=g(t[c],!1,!1,u,f,l+1);return`${a.repeat(l+1)}${JSON.stringify(c)}: ${S}`}).join(`,
|
|
7
|
+
`)}
|
|
8
|
+
${a.repeat(l)}}`}return String(t)}var A={name:"jq",async execute(t,o){if(N(t))return w(E);let d=!1,u=!1,f=!1,l=!1,a=!1,n=!1,p=!1,c=!1,S=".",C=!1,m=[];for(let s=0;s<t.length;s++){let e=t[s];if(e==="-r"||e==="--raw-output")d=!0;else if(e==="-c"||e==="--compact-output")u=!0;else if(e==="-e"||e==="--exit-status")f=!0;else if(e==="-s"||e==="--slurp")l=!0;else if(e==="-n"||e==="--null-input")a=!0;else if(e==="-j"||e==="--join-output")n=!0;else if(!(e==="-a"||e==="--ascii")){if(e==="-S"||e==="--sort-keys")p=!0;else if(!(e==="-C"||e==="--color")){if(!(e==="-M"||e==="--monochrome"))if(e==="--tab")c=!0;else if(e==="-")m.push("-");else{if(e.startsWith("--"))return O("jq",e);if(e.startsWith("-")){for(let r of e.slice(1))if(r==="r")d=!0;else if(r==="c")u=!0;else if(r==="e")f=!0;else if(r==="s")l=!0;else if(r==="n")a=!0;else if(r==="j")n=!0;else if(r!=="a"){if(r==="S")p=!0;else if(r!=="C"){if(r!=="M")return O("jq",`-${r}`)}}}else C?m.push(e):(S=e,C=!0)}}}}let h;if(a)h="";else if(m.length===0||m.length===1&&m[0]==="-")h=o.stdin;else try{let s=o.fs.resolvePath(o.cwd,m[0]);h=await o.fs.readFile(s)}catch{return{stdout:"",stderr:`jq: ${m[0]}: No such file or directory
|
|
9
|
+
`,exitCode:2}}try{let s=x(S),e,r={limits:o.limits?{maxIterations:o.limits.maxJqIterations}:void 0,env:o.env};if(a)e=y(null,s,r);else if(l){let i=[];for(let j of h.trim().split(`
|
|
10
|
+
`))j.trim()&&i.push(JSON.parse(j));e=y(i,s,r)}else{let i=h.trim();if(i.startsWith("{")||i.startsWith("["))e=y(JSON.parse(i),s,r);else{e=[];for(let j of i.split(`
|
|
11
|
+
`))j.trim()&&e.push(...y(JSON.parse(j),s,r))}}let I=e.map(i=>g(i,u,d,p,c)),J=n?"":`
|
|
12
|
+
`,$=I.join(J),b=f&&(e.length===0||e.every(i=>i==null||i===!1))?1:0;return{stdout:$?n?$:`${$}
|
|
13
|
+
`:"",stderr:"",exitCode:b}}catch(s){if(s instanceof q)return{stdout:"",stderr:`jq: ${s.message}
|
|
14
|
+
`,exitCode:q.EXIT_CODE};let e=s.message;return e.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${e}
|
|
15
|
+
`,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${e}
|
|
16
|
+
`,exitCode:5}}}};export{A as jqCommand};
|