only list if recursively not deleted and test

master
Bel LaPointe 2022-02-07 13:15:58 -07:00
parent 0a3943561f
commit 1c6cdec2c0
2 changed files with 63 additions and 14 deletions

View File

@ -6,6 +6,42 @@ notea() (
}
ids() {
for id in $(_tree_ids); do
if ! _is_deleted $id; then
echo $id
fi
done
}
meta() {
local cache_key="notea cache meta $1"
if cache get "$cache_key"; then
return 0
fi
_meta "$@" | cache put "$cache_key"
}
_meta() {
ncurl $NOTEA_ADDR/api/notes/$1/meta
}
_is_deleted() {
local id="$1"
if [ "$id" == "root" ] || [ "$id" == "null" ]; then
return 1
fi
local meta="$(meta "$id")"
if echo "$meta" | jq .deleted | grep -q 1; then
return 0
fi
local pid="$(echo "$meta" | jq -r .pid)"
if [ -z "$pid" ]; then
return 0
fi
_is_deleted "$pid"
}
_tree_ids() {
ncurl $NOTEA_ADDR/api/tree \
| jq '.items | to_entries[].value.id' \
| grep -v '^null$' \

View File

@ -3,20 +3,33 @@
test_ids() {
notea eval "$(cat <<EOF
ncurl() {
echo "$*" | grep -q \/api\/tree
echo '{
"items": {
"root": {
"children": [
"abc"
]
},
"abc": {
"id": "def"
},
"def": {}
}
}'
case "\$1" in
*/api/tree )
echo '{
"items": {
"root": {
"children": [
"abc"
]
},
"abc": {
"id": "def"
},
"def": {
"pid": "root"
}
}
}'
;;
*/api/notes/def/meta )
echo '{
"deleted": 0
}'
;;
* )
echo UNKNOWN NCURL "\$*" >&2
;;
esac
}
ids | wc -l | grep -q 1 || return 101
ids | grep -q def || return 102