hsjuiz 0.6.1 → 0.7.0
raw patch · 4 files changed
+34/−6 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Juiz.Type: unionFromValue :: Text -> [(Text, [Text], Value -> Either Text a)] -> Value -> Either Text a
+ Juiz.Type: unionValue :: Text -> Value -> Value
+ Juiz.Type: unsafeUnionTypeInfo :: Text -> Text -> TypeInfo
Files
- CHANGELOG.md +6/−0
- README.md +5/−5
- hsjuiz.cabal +1/−1
- src/Juiz/Type.hs +22/−0
CHANGELOG.md view
@@ -3,6 +3,12 @@ hsjuiz の版は juiz(crates.io の juiz_app、PyPI の pyjuiz / juiz-cli)と同じ番号にそろえています。 使う libjuiz_sdk も同じ版にしてください。 +## 0.7.0++- レコードの union(`data Action = ActionRelocalize Relocalize | ActionHold Hold`)を juiz-idl で生成できるようにした。+ 生成コードが使う `unsafeUnionTypeInfo`・`unionFromValue`・`unionValue` を `Juiz.Type` に足した+ (docs/spec/datatype.md §11.1、juiz#702)。既存の API は変えていない。+ ## 0.6.1 - hsjuiz の API は 0.6.0 から変えていない(pyjuiz の基本型の戻り値の型参照 #674 の公開に版をそろえた)。
README.md view
@@ -352,7 +352,7 @@ `scripts/install-juiz-sdk.sh` で取得して `~/.juiz/sdk/<版>` に展開できます。 ```terminal-curl -fsSL https://raw.githubusercontent.com/OpenJUIZ/juiz/main/scripts/install-juiz-sdk.sh | sh -s -- 0.6.1+curl -fsSL https://raw.githubusercontent.com/OpenJUIZ/juiz/main/scripts/install-juiz-sdk.sh | sh -s -- 0.7.0 ``` それより前の版では、juiz のソースを同じ版のタグで取得し、`cargo build --release -p juiz_sdk` でできる `target/release` の libjuiz_sdk を使います。@@ -366,8 +366,8 @@ packages: . package hsjuiz- extra-lib-dirs: /home/me/.juiz/sdk/0.6.1/lib- ghc-options: -optl-Wl,-rpath,/home/me/.juiz/sdk/0.6.1/lib+ extra-lib-dirs: /home/me/.juiz/sdk/0.7.0/lib+ ghc-options: -optl-Wl,-rpath,/home/me/.juiz/sdk/0.7.0/lib ``` ```terminal@@ -379,11 +379,11 @@ その `bindings/hsjuiz` を `cabal.project` の `packages:` に足します。 ```cabal-packages: . /home/me/juiz-0.6.1/bindings/hsjuiz+packages: . /home/me/juiz-0.7.0/bindings/hsjuiz ``` ```terminal-git clone --depth 1 --branch v0.6.1 https://github.com/OpenJUIZ/juiz.git /home/me/juiz-0.6.1+git clone --depth 1 --branch v0.7.0 https://github.com/OpenJUIZ/juiz.git /home/me/juiz-0.7.0 ``` juiz のリポジトリの中でビルドするときは、`cargo build` でできる `target/debug` の libjuiz_sdk を
hsjuiz.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: hsjuiz-version: 0.6.1+version: 0.7.0 synopsis: Write juiz processes and containers in Haskell description: Write Process / Container / Component plugins of
src/Juiz/Type.hs view
@@ -30,10 +30,13 @@ , typeInfoFingerprint , newTypeInfo , unsafeTypeInfo+ , unsafeUnionTypeInfo -- * 生成したコードが使う関数 , recordFromValue , field , enumFromValue+ , unionFromValue+ , unionValue ) where import Control.Exception (bracket)@@ -89,6 +92,25 @@ -- 型ごとに 1 度だけ作るよう、@{-# NOINLINE … #-}@ を付けたトップレベルの値にすること unsafeTypeInfo :: Text -> TypeInfo unsafeTypeInfo = unsafePerformIO . newTypeInfo++-- | レコードの union の型 (docs/spec/datatype.md §3.5・§11.1)。1 つ目は null を除いた union、2 つ目は null を含む union+-- ('Maybe' の結果の output_schema に使う) の Avro のスキーマ。null の枝の位置は宣言のとおり (並べ替えると指紋が変わる)。+-- 'unsafeTypeInfo' と同じく、@{-# NOINLINE … #-}@ を付けたトップレベルの値にすること+unsafeUnionTypeInfo :: Text -> Text -> TypeInfo+unsafeUnionTypeInfo avro withNull = (unsafeTypeInfo avro) {typeInfoOptional = unsafeTypeInfo withNull}++-- | レコードの union を辞書から読む (仕様 §4)。値は鍵 1 つのオブジェクト @{"<完全名>": {...}}@ で、+-- 鍵は枝の完全名かその別名。枝ごとに (完全名, 別名の完全名, 中身を読む関数) を渡す+unionFromValue :: Text -> [(Text, [Text], Value -> Either Text a)] -> Value -> Either Text a+unionFromValue name branches v = case v of+ JObject o | [(k, inner)] <- Map.toList o -> case [r | (full, aliases, r) <- branches, k == full || k `elem` aliases] of+ (r : _) -> either (\msg -> Left (k <> ": " <> msg)) Right (r inner)+ [] -> Left (k <> " is not a record of " <> name)+ _ -> Left ("expected " <> name <> " (an object with one key, the full name of a record), but got " <> T.pack (show v))++-- | レコードの union の値を辞書にする (完全名を鍵にした 1 鍵のオブジェクト、仕様 §4)+unionValue :: Text -> Value -> Value+unionValue full inner = JObject (Map.singleton full inner) -- | record を辞書 (オブジェクト) から読む。オブジェクトでなければ Left recordFromValue :: Text -> Value -> (Map Text Value -> Either Text a) -> Either Text a