generated from tpl/purs
fix: bug
This commit is contained in:
parent
30eed65e65
commit
fcf3b78b8f
@ -114,12 +114,12 @@ emptySpawnOptions =
|
||||
spawnOptionsToImpl :: forall a. Serializable a => Record (SpawnOptions (workerData :: Maybe a, eval :: Boolean)) -> Record SpawnImplOptions
|
||||
spawnOptionsToImpl =
|
||||
let
|
||||
mapEnv (Just InheritEnv) = Nullable.notNull $ unsafeToForeign shareEnv
|
||||
mapEnv (Just InheritEnv) = Nullable.notNull $ (unsafeToForeign :: Symbol -> Foreign) shareEnv
|
||||
mapEnv (Just (FixedEnv env)) = Nullable.notNull $ serialize $ Object.fromFoldableWithIndex env
|
||||
mapEnv Nothing = Nullable.null
|
||||
in
|
||||
applyRecord
|
||||
{ argv: Nullable.toNullable <<< map (map unsafeToForeign)
|
||||
{ argv: Nullable.toNullable <<< map (map serialize)
|
||||
, env: mapEnv
|
||||
, eval: Nullable.notNull
|
||||
, execArgv: Nullable.toNullable
|
||||
|
@ -25,6 +25,9 @@ import Type.Prelude (Proxy(..))
|
||||
|
||||
foreign import undef :: Foreign
|
||||
|
||||
convert :: forall @a. a -> Foreign
|
||||
convert = unsafeToForeign
|
||||
|
||||
class Serializable a where
|
||||
serialize :: a -> Foreign
|
||||
deserialize :: Foreign -> Either String a
|
||||
@ -34,44 +37,44 @@ instance Serializable Foreign where
|
||||
deserialize = pure
|
||||
|
||||
instance Serializable String where
|
||||
serialize = unsafeToForeign
|
||||
serialize = convert @String
|
||||
deserialize = lmap show <<< runExcept <<< readString
|
||||
|
||||
instance Serializable URL where
|
||||
serialize = unsafeToForeign
|
||||
serialize = convert @URL
|
||||
deserialize = lmap show <<< runExcept <<< unsafeReadTagged "URL"
|
||||
|
||||
instance Serializable Int where
|
||||
serialize = unsafeToForeign
|
||||
serialize = convert @Int
|
||||
deserialize = lmap show <<< runExcept <<< readInt
|
||||
|
||||
instance Serializable Number where
|
||||
serialize = unsafeToForeign
|
||||
serialize = convert @Number
|
||||
deserialize = lmap show <<< runExcept <<< readNumber
|
||||
|
||||
instance Serializable BigInt where
|
||||
serialize = unsafeToForeign
|
||||
serialize = convert @BigInt
|
||||
deserialize = lmap show <<< runExcept <<< unsafeReadTagged "BigInt"
|
||||
|
||||
instance Serializable Boolean where
|
||||
serialize = unsafeToForeign
|
||||
serialize = convert @Boolean
|
||||
deserialize = lmap show <<< runExcept <<< readBoolean
|
||||
|
||||
instance Serializable a => Serializable (Maybe a) where
|
||||
serialize (Just a) = unsafeToForeign a
|
||||
serialize (Just a) = convert @a a
|
||||
serialize Nothing = undef
|
||||
deserialize = flip bind (traverse deserialize) <<< lmap show <<< runExcept <<< readNullOrUndefined
|
||||
|
||||
instance Serializable a => Serializable (Array a) where
|
||||
serialize a = unsafeToForeign a
|
||||
serialize a = convert @(Array a) a
|
||||
deserialize = flip bind (traverse deserialize) <<< lmap show <<< runExcept <<< readArray
|
||||
|
||||
instance Serializable a => Serializable (NonEmptyArray a) where
|
||||
serialize a = unsafeToForeign $ Array.NonEmpty.toArray a
|
||||
serialize a = convert @(Array a) $ Array.NonEmpty.toArray a
|
||||
deserialize = flip bind (liftMaybe "expected non-empty array" <<< Array.NonEmpty.fromArray) <<< deserialize
|
||||
|
||||
instance Serializable a => Serializable (Object a) where
|
||||
serialize a = unsafeToForeign a
|
||||
serialize a = convert @(Object a) a
|
||||
deserialize a =
|
||||
if typeOf a == "object" then
|
||||
pure $ unsafeFromForeign a
|
||||
@ -79,7 +82,7 @@ instance Serializable a => Serializable (Object a) where
|
||||
throwError $ "expected object, found " <> typeOf a
|
||||
|
||||
instance (RowToList r rl, SerializeRecord rl r () to, DeserializeRecord rl () r) => Serializable (Record r) where
|
||||
serialize a = unsafeToForeign $ serializeFields (Proxy @rl) a
|
||||
serialize a = convert @(Record to) $ Record.Builder.buildFromScratch $ serializeFields (Proxy @rl) a
|
||||
deserialize a = map (flip Record.Builder.build {}) (deserializeFields (Proxy @rl) a)
|
||||
|
||||
class DeserializeRecord (rl :: RowList Type) (from :: Row Type) (to :: Row Type) | rl -> from to where
|
||||
|
Loading…
Reference in New Issue
Block a user