git.iko.soy/purestack-dev/project-m36-rest
on 69f708b help sign in
5 files changed+24−87
since splitsnapshots
unifiedsplit
flake.lock+1−17 flake.nix+2−44 package.yaml−1 result−1 src/ProjectM36/Rest.hs+21−24
flake.lock+1−17
@@ -35,23 +35,7 @@
3535 "root": {
3636 "inputs": {
3737 "flake-utils": "flake-utils",
38− "nixpkgs": "nixpkgs",
39− "stacklock2nix": "stacklock2nix"
40− }
41− },
42− "stacklock2nix": {
43− "locked": {
44− "lastModified": 1743151034,
45− "narHash": "sha256-2QgpxnOyQg475wd0f/qzgG4fNqce1UearDjzZyrmMG8=",
46− "owner": "cdepillabout",
47− "repo": "stacklock2nix",
48− "rev": "108f6ab6d0208e3842443bea26dfd72b37d82f28",
49− "type": "github"
50− },
51− "original": {
52− "owner": "cdepillabout",
53− "repo": "stacklock2nix",
54− "type": "github"
38+ "nixpkgs": "nixpkgs"
5539 }
5640 },
5741 "systems": {
flake.nix+2−44
@@ -2,53 +2,16 @@
22 inputs = {
33 nixpkgs.url = "nixpkgs/nixos-unstable";
44 flake-utils.url = "flake-utils";
5− stacklock2nix.url = "github:cdepillabout/stacklock2nix";
65 };
76
8− outputs = { self, flake-utils, nixpkgs, stacklock2nix }:
7+ outputs = { self, flake-utils, nixpkgs }:
98 let
109 supportedSystems =
1110 [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ];
1211 compilerVersion = "966";
1312 in flake-utils.lib.eachSystem supportedSystems (system:
14− let
15− pkgs = import nixpkgs {
16− inherit system;
17− overlays = [ stacklock2nix.overlay ];
18− };
19− appendGhcFlags = opts: drv:
20− pkgs.haskell.lib.appendBuildFlag drv
21− ''--ghc-options="${builtins.concatStringsSep " " opts}"'';
22− insaneOptimizationFlags =
23− [ "-O2" "-fexpose-all-unfoldings" "-fspecialise-aggressively" ];
24− justStatic = package:
25− (pkgs.haskell.lib.overrideCabal
26− (pkgs.haskell.lib.justStaticExecutables package)
27− (drv: { disallowGhcReference = false; }));
13+ let pkgs = import nixpkgs { inherit system; };
2814 in {
29− packages = {
30− default = justStatic (pkgs.stacklock2nix {
31− stackYaml = ./stack.yaml;
32− baseHaskellPkgSet = pkgs.haskell.packages."ghc${compilerVersion}";
33− additionalHaskellPkgSetOverrides = (hfinal: hprev:
34− builtins.mapAttrs (name: value:
35− if (builtins.tryEval (!(builtins.isAttrs value)
36− || !(value ? pname))).value or true then
37− value
38− else if value ? doCheck && value.pname != "ghc" then
39− pkgs.lib.pipe value (with pkgs.haskell.lib; [
40− dontCheck
41− dontHaddock
42− doJailbreak
43− doStrip
44− disableLibraryProfiling
45− disableExecutableProfiling
46− (appendGhcFlags insaneOptimizationFlags)
47− ])
48− else
49− value) hprev);
50− }).pkgSet.project-m36-rest;
51− };
5215 devShells.default = pkgs.mkShell {
5316 buildInputs = with pkgs; [
5417 haskell.compiler."ghc${compilerVersion}"
@@ -58,9 +21,4 @@
5821 ];
5922 };
6023 });
61− nixConfig = {
62− extra-substituters = [ "https://cache.garnix.io" ];
63− extra-trusted-public-keys =
64− [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
65− };
6624}
package.yaml−1
@@ -15,7 +15,6 @@ library:
1515 - base64
1616 - text
1717 - containers
18− - wai-logger
1918
2019executable:
2120 main: Main.hs
resultdeleted−1
@@ -1 +0,0 @@
1−/nix/store/r7qq705mq8sp0l20wmj1b66vxm78zvl8-project-m36-rest-0.0.0
src/ProjectM36/Rest.hs+21−24
@@ -19,7 +19,6 @@ import Data.Traversable
1919import Data.Vector qualified as V
2020import GHC.Generics (Generic)
2121import Network.Wai.Handler.Warp qualified as Warp
22−import Network.Wai.Logger (withStdoutLogger)
2322import Options.Applicative
2423import ProjectM36.Base
2524import ProjectM36.Client
@@ -98,23 +97,25 @@ encodeRelation (Relation (Attributes attrs) (RelationTupleSet tuples)) =
9897 "vals" A..= (tuples <&> (\(RelationTuple _ atoms) -> encodeAtom <$> atoms))
9998 ]
10099
101−decodeRelationType :: V.Vector (Text, A.Value) -> A.Parser (V.Vector Attribute)
102−decodeRelationType =
103− traverse
104− ( \(key, v) ->
105− Attribute key <$> case v of
106− A.String "int" -> pure IntAtomType
107− A.String "integer" -> pure IntegerAtomType
108− A.String "scientific" -> pure ScientificAtomType
109− A.String "double" -> pure DoubleAtomType
110− A.String "text" -> pure TextAtomType
111− A.String "day" -> pure DayAtomType
112− A.String "datetime" -> pure DateTimeAtomType
113− A.String "bytestring" -> pure ByteStringAtomType
114− A.String "bool" -> pure BoolAtomType
115− A.String "uuid" -> pure UUIDAtomType
116− x -> parseJSON x >>= fmap (RelationAtomType . Attributes) . decodeRelationType
117− )
100+decodeRelationType :: A.Array -> A.Parser (V.Vector Attribute)
101+decodeRelationType o =
102+ traverse parseJSON o
103+ >>= traverse
104+ ( \(key, v) ->
105+ Attribute (Key.toText key) <$> case v of
106+ A.String "int" -> pure IntAtomType
107+ A.String "integer" -> pure IntegerAtomType
108+ A.String "scientific" -> pure ScientificAtomType
109+ A.String "double" -> pure DoubleAtomType
110+ A.String "text" -> pure TextAtomType
111+ A.String "day" -> pure DayAtomType
112+ A.String "datetime" -> pure DateTimeAtomType
113+ A.String "bytestring" -> pure ByteStringAtomType
114+ A.String "bool" -> pure BoolAtomType
115+ A.String "uuid" -> pure UUIDAtomType
116+ A.Array x -> RelationAtomType . Attributes <$> decodeRelationType x
117+ _ -> fail $ "unknown type: " <> show v
118+ )
118119
119120decodeExpr :: A.Value -> A.Parser RelationalExpr
120121decodeExpr = withObject "Expr" $ \o -> case KeyMap.toList o of
@@ -224,12 +225,8 @@ run = do
224225 Right x -> pure x
225226 )
226227 close
227− ( \conn -> withStdoutLogger $ \logger ->
228+ ( \conn ->
228229 Warp.runSettings
229− ( Warp.defaultSettings
230− & Warp.setServerName "project-m36-rest"
231− & Warp.setPort opts.port
232− & Warp.setLogger logger
233− )
230+ (Warp.defaultSettings & Warp.setServerName "project-m36-rest" & Warp.setPort opts.port)
234231 (genericServe (server conn))
235232 )