okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
2f43cb2
main
1from __future__import annotations 2 3from albedo_api import Host ,PythonApi ,Record 4import builtins 5from typing import cast 6 7 8class WorkItem (Record ): 9"""One ledger item: item.id and item["id"] both work.""" 10 11id :int 12title :str 13notes :str 14status :str 15parent :int | None 16session :str | None 17run :str | None 18revision :int 19workspace :str # where it was filed: this workspace or a linked one 20 21 22host :Host 23 24 25class Work : 26async def list (self ,after :int = 0 ,limit :int = 50 )-> builtins .list [WorkItem ]: 27return [ 28WorkItem (item ) 29for item in cast ( 30builtins .list [dict ], 31await host ("work.list" , {"after" :after ,"limit" :limit }), 32 ) 33 ] 34 35async def get (self ,id :int )-> WorkItem : 36return WorkItem (cast (dict ,await host ("work.get" , {"id" :id }))) 37 38async def create ( 39self ,title :str ,notes :str = "" ,parent :int | None = None 40 )-> WorkItem : 41return WorkItem ( 42cast ( 43dict , 44await host ( 45"work.create" , {"title" :title ,"notes" :notes ,"parent" :parent } 46 ), 47 ) 48 ) 49 50async def update (self ,id :int ,* ,revision :int ,** changes :object )-> WorkItem : 51allowed = {"title" ,"notes" ,"status" ,"session" ,"run" } 52if changes .keys ()- allowed : 53raise ValueError ("unknown work fields: " + repr (changes .keys ()- allowed )) 54return WorkItem ( 55cast ( 56dict , 57await host ("work.update" , {"id" :id ,"revision" :revision ,** changes }), 58 ) 59 ) 60 61async def delete (self ,id :int ,* ,revision :int )-> WorkItem : 62"""Remove an item at the revision you last read; one with sub-items stays.""" 63return WorkItem ( 64cast (dict ,await host ("work.delete" , {"id" :id ,"revision" :revision })) 65 ) 66 67 68def setup (api :PythonApi )-> dict [str ,object ]: 69global host 70host = api .host 71return {"work" :Work (),"WorkError" :api .HostError }