journal/tool/types.jq

42 lines
1.8 KiB
Plaintext
Raw Normal View History

2024-11-07 11:39:39 +00:00
import "typeLib" as typeLib;
2024-11-07 13:10:18 +00:00
#["DEBUG:",{"creationDate":"number","ingestions":[{"administrationRoute":"string","consumerName":"null","creationDate":"number","customUnitId":"null","dose":"number","estimatedDoseStandardDeviation":"null","isDoseAnEstimate":"boolean","notes":"string","stomachFullness":"null","substanceName":"string","time":"number","units":"string"}],"isFavorite":"boolean","location":"null","ratings":"array:empty/unknown","sortDate":"number","text":"string","timedNotes":"array:empty/unknown","title":"string"}]
2024-11-07 11:39:39 +00:00
def ensureExperience:
. as $experience |
typeLib::ensureObject |
2024-11-07 13:10:18 +00:00
debug(. | typeLib::dumpType) |
2024-11-07 11:39:39 +00:00
$experience |
typeLib::ensureKey("experience"; "title") |
2024-11-07 13:10:18 +00:00
.title | typeLib::ensureWrapError("experience:title"; typeLib::ensureString) |
2024-11-07 11:39:39 +00:00
$experience |
typeLib::ensureKey("experience"; "text") |
2024-11-07 13:10:18 +00:00
.text | typeLib::ensureWrapError("experience:text"; typeLib::ensureString) |
$experience |
typeLib::ensureKey("experience"; "creationDate") |
.creationDate | typeLib::ensureWrapError("experience:creationDate"; typeLib::ensureNumber) |
$experience |
typeLib::ensureKey("experience"; "sortDate") |
.sortDate | typeLib::ensureWrapError("experience:sortDate"; typeLib::ensureNumber) |
$experience |
typeLib::ensureKey("experience"; "isFavorite") |
.isFavorite | typeLib::ensureWrapError("experience:isFavorite"; typeLib::ensureBool)
2024-11-07 11:39:39 +00:00
;
def ensureExportData:
. as $exportData |
if typeLib::typecheckingEnabled then
typeLib::ensureObject |
typeLib::ensureKey("exportData"; "customSubstances") |
typeLib::ensureKey("exportData"; "customUnits") |
typeLib::ensureKey("exportData"; "experiences") |
typeLib::ensureKey("exportData"; "substanceCompanions") |
2024-11-07 13:10:18 +00:00
(reduce .experiences[] as $experience (null; $experience | ensureExperience))
2024-11-07 11:39:39 +00:00
end;