2024-11-07 21:45:22 +00:00
|
|
|
include "dropins";
|
|
|
|
|
|
|
|
import "lib/typeLib" as typeLib;
|
2024-11-07 11:39:39 +00:00
|
|
|
|
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 21:45:22 +00:00
|
|
|
def ensureIngestion:
|
|
|
|
. as $ingestion |
|
|
|
|
typeLib::ensureObject |
|
|
|
|
|
|
|
|
$ingestion | typeLib::ensureKey("ingestion"; "substanceName") |
|
|
|
|
.substanceName | typeLib::ensureWrapError("experience:substanceName"; typeLib::ensureString);
|
|
|
|
|
|
|
|
def ensureTimedNote:
|
|
|
|
. as $timedNote |
|
|
|
|
if typeLib::typecheckingEnabled then
|
|
|
|
$timedNote | typeLib::ensureObject |
|
|
|
|
$timedNote | typeLib::ensureKey("timedNote"; "color") |
|
|
|
|
$timedNote.color | typeLib::ensureWrapError("timedNote:color"; typeLib::ensureString) |
|
|
|
|
$timedNote | typeLib::ensureKey("timedNote"; "creationDate") |
|
|
|
|
$timedNote.creationDate | typeLib::ensureWrapError("timedNote:creationDate"; typeLib::ensureNumber) |
|
|
|
|
$timedNote | typeLib::ensureKey("timedNote"; "isPartOfTimeline") |
|
|
|
|
$timedNote.isPartOfTimeline | typeLib::ensureWrapError("timedNote:isPartOfTimeline"; typeLib::ensureBool) |
|
|
|
|
$timedNote | typeLib::ensureKey("timedNote"; "note") |
|
|
|
|
$timedNote.note | typeLib::ensureWrapError("timedNote:note"; typeLib::ensureString) |
|
|
|
|
$timedNote | typeLib::ensureKey("timedNote"; "time") |
|
|
|
|
$timedNote.time | typeLib::ensureWrapError("timedNote:time"; typeLib::ensureNumber)
|
|
|
|
end;
|
|
|
|
|
2024-11-07 11:39:39 +00:00
|
|
|
def ensureExperience:
|
|
|
|
. as $experience |
|
2024-11-07 21:45:22 +00:00
|
|
|
if typeLib::typecheckingEnabled then
|
|
|
|
$experience | typeLib::ensureObject |
|
2024-11-07 13:10:18 +00:00
|
|
|
|
2024-11-07 21:45:22 +00:00
|
|
|
$experience | typeLib::ensureKey("experience"; "title") |
|
|
|
|
$experience.title | typeLib::ensureWrapError("experience:title"; typeLib::ensureString) |
|
2024-11-07 13:10:18 +00:00
|
|
|
|
2024-11-07 21:45:22 +00:00
|
|
|
$experience | typeLib::ensureKey("experience"; "text") |
|
|
|
|
$experience.text | typeLib::ensureWrapError("experience:text"; typeLib::ensureString) |
|
2024-11-07 11:39:39 +00:00
|
|
|
|
2024-11-07 21:45:22 +00:00
|
|
|
$experience | typeLib::ensureKey("experience"; "creationDate") |
|
|
|
|
$experience.creationDate | typeLib::ensureWrapError("experience:creationDate"; typeLib::ensureNumber) |
|
2024-11-07 13:10:18 +00:00
|
|
|
|
2024-11-07 21:45:22 +00:00
|
|
|
$experience | typeLib::ensureKey("experience"; "sortDate") |
|
|
|
|
$experience.sortDate | typeLib::ensureWrapError("experience:sortDate"; typeLib::ensureNumber) |
|
2024-11-07 13:10:18 +00:00
|
|
|
|
2024-11-07 21:45:22 +00:00
|
|
|
$experience | typeLib::ensureKey("experience"; "isFavorite") |
|
|
|
|
$experience.isFavorite | typeLib::ensureWrapError("experience:isFavorite"; typeLib::ensureBool) |
|
2024-11-07 13:10:18 +00:00
|
|
|
|
2024-11-07 21:45:22 +00:00
|
|
|
$experience | typeLib::ensureKey("experience"; "timedNotes") |
|
|
|
|
$experience.timedNotes | typeLib::ensureWrapError("experience:timedNotes"; typeLib::ensureArray) |
|
|
|
|
(reduce $experience.timedNotes[] as $timedNote (null; $timedNote | ensureTimedNote)) |
|
2024-11-07 13:10:18 +00:00
|
|
|
|
2024-11-07 21:45:22 +00:00
|
|
|
$experience | typeLib::ensureKey("experience"; "ingestions") |
|
|
|
|
$experience.ingestions | typeLib::ensureWrapError("experience:ingestions"; typeLib::ensureArray) |
|
|
|
|
(reduce $experience.ingestions[] as $ingestion (null; $ingestion | ensureIngestion))
|
|
|
|
|
|
|
|
end;
|
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;
|