Skip to content

Commit

Permalink
feat: update xs.nu to use the underlying xs cli for .cat and .append
Browse files Browse the repository at this point in the history
  • Loading branch information
cablehead committed Sep 16, 2024
1 parent da43fe0 commit 0da4370
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions xs.nu
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ alias and-then = if ($in | is-not-empty)
alias ? = if ($in | is-not-empty) { $in }
alias ?? = ? else { return }

export def store-addr [] {
$env | default "./store" XSPWD | get XSPWD
}

# update to use (store-addr) and the xs cli
def _cat [options: record] {
let params = [
(if ($options | get follow? | default false) {
"follow" + (if $options.pulse? != null { $"=($options.pulse)" } else { "" })
})

(if ($options | get tail? | default false) { "tail" })

(if ($options.last_id? | is-not-empty) { $"last-id=($options.last_id)" })
(if ($options | get follow? | default false) { "--follow" })
(if ($options | get tail? | default false) { "--tail" })

(if ($options.limit? | is-not-empty) { $"limit=($options.limit)" })
] | compact
(if $options.last_id? != null { ["--last-id" $options.last_id] })

let postfix = if ($params | is-not-empty) {
"//?" + ($params | str join "&")
} else { "" }
(if $options.limit? != null { ["--limit" $options.limit] })
(if $options.pulse? != null { ["--pulse" $options.pulse] })
] | compact | flatten

h. get $"./store/sock($postfix)" | lines | each { |x| $x | from json }
xs cat (store-addr) ...$params | lines | each { |x| $x | from json }
}

export def .cat [
Expand Down Expand Up @@ -83,7 +81,11 @@ export def .head [topic: string] {
}

export def .append [topic: string --meta: record] {
h. post $"./store/sock//($topic)" --headers {"xs-meta": ($meta | to json -r)}
let params = [
(if $meta != null { ["--meta" ($meta | to json -r)] })
] | compact | flatten

xs append (store-addr) $topic ...$params | from json
}

export def .pipe [id: string] {
Expand Down

0 comments on commit 0da4370

Please sign in to comment.