summaryrefslogtreecommitdiff
path: root/lib/VNWeb/Elm.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-11-08 16:50:04 +0100
committerYorhel <git@yorhel.nl>2020-11-08 16:50:09 +0100
commit40faeebb1ab515b1c9f9bf9ad4f553c721b8754a (patch)
tree1fd51934ba93bea4e2623ae34be77910076ca807 /lib/VNWeb/Elm.pm
parentdc34ce6828878962e016417c4bd337ddccac5d6a (diff)
AdvSearch: Implement a compact search query encoding
The encoding/decoding functions haven't been fully tested yet, in particular regarding string values, but the rest seems to work fine. The format isn't set in stone yet, as the JSON query format isn't exactly fixed yet either, we'll likely be needing more data types and there may be room for optimizations depending on usage patterns. The format should stabilize when this feature goes out of /experimental/.
Diffstat (limited to 'lib/VNWeb/Elm.pm')
-rw-r--r--lib/VNWeb/Elm.pm29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm
index 4e9d435b..18f2ef09 100644
--- a/lib/VNWeb/Elm.pm
+++ b/lib/VNWeb/Elm.pm
@@ -477,11 +477,40 @@ sub write_extlinks {
}
+sub write_advsearch {
+ my $data =<<~'_';
+ type QType = V | R
+ type QVType = QVInt | QVStr | QVQuery QType
+
+ type alias QField =
+ { qtype : QType
+ , name : String
+ , num : Int
+ , vtype : QVType
+ }
+ _
+
+ $data .= def fields => "List QField" => list map {
+ my($t, $n, $f) = @$_;
+ '{ '.join("\n , ",
+ 'qtype = '.uc($t),
+ 'name = '.string($n),
+ 'num = '.$f->{num},
+ 'vtype = '.($f->{vndbid}||$f->{int} ? 'QVInt' : !ref $f->{value} ? 'QVQuery '.uc($f->{value}) : 'QVStr')
+ )."\n }";
+ } map { my $t=$_; map [$t,$_,$VNWeb::AdvSearch::FIELDS{$t}{$_}], sort keys $VNWeb::AdvSearch::FIELDS{$t}->%* } sort keys %VNWeb::AdvSearch::FIELDS;
+
+ write_module AdvSearch => $data;
+}
+
+
+
if(tuwf->{elmgen}) {
mkdir config->{root}.'/elm/Gen';
write_api;
write_types;
write_extlinks;
+ write_advsearch;
open my $F, '>', config->{root}.'/elm/Gen/.generated';
print $F scalar gmtime;
}