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 :: forall a. Serializable a => Record (SpawnOptions (workerData :: Maybe a, eval :: Boolean)) -> Record SpawnImplOptions
|
||||||
spawnOptionsToImpl =
|
spawnOptionsToImpl =
|
||||||
let
|
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 (Just (FixedEnv env)) = Nullable.notNull $ serialize $ Object.fromFoldableWithIndex env
|
||||||
mapEnv Nothing = Nullable.null
|
mapEnv Nothing = Nullable.null
|
||||||
in
|
in
|
||||||
applyRecord
|
applyRecord
|
||||||
{ argv: Nullable.toNullable <<< map (map unsafeToForeign)
|
{ argv: Nullable.toNullable <<< map (map serialize)
|
||||||
, env: mapEnv
|
, env: mapEnv
|
||||||
, eval: Nullable.notNull
|
, eval: Nullable.notNull
|
||||||
, execArgv: Nullable.toNullable
|
, execArgv: Nullable.toNullable
|
||||||
|
@ -25,6 +25,9 @@ import Type.Prelude (Proxy(..))
|
|||||||
|
|
||||||
foreign import undef :: Foreign
|
foreign import undef :: Foreign
|
||||||
|
|
||||||
|
convert :: forall @a. a -> Foreign
|
||||||
|
convert = unsafeToForeign
|
||||||
|
|
||||||
class Serializable a where
|
class Serializable a where
|
||||||
serialize :: a -> Foreign
|
serialize :: a -> Foreign
|
||||||
deserialize :: Foreign -> Either String a
|
deserialize :: Foreign -> Either String a
|
||||||
@ -34,44 +37,44 @@ instance Serializable Foreign where
|
|||||||
deserialize = pure
|
deserialize = pure
|
||||||
|
|
||||||
instance Serializable String where
|
instance Serializable String where
|
||||||
serialize = unsafeToForeign
|
serialize = convert @String
|
||||||
deserialize = lmap show <<< runExcept <<< readString
|
deserialize = lmap show <<< runExcept <<< readString
|
||||||
|
|
||||||
instance Serializable URL where
|
instance Serializable URL where
|
||||||
serialize = unsafeToForeign
|
serialize = convert @URL
|
||||||
deserialize = lmap show <<< runExcept <<< unsafeReadTagged "URL"
|
deserialize = lmap show <<< runExcept <<< unsafeReadTagged "URL"
|
||||||
|
|
||||||
instance Serializable Int where
|
instance Serializable Int where
|
||||||
serialize = unsafeToForeign
|
serialize = convert @Int
|
||||||
deserialize = lmap show <<< runExcept <<< readInt
|
deserialize = lmap show <<< runExcept <<< readInt
|
||||||
|
|
||||||
instance Serializable Number where
|
instance Serializable Number where
|
||||||
serialize = unsafeToForeign
|
serialize = convert @Number
|
||||||
deserialize = lmap show <<< runExcept <<< readNumber
|
deserialize = lmap show <<< runExcept <<< readNumber
|
||||||
|
|
||||||
instance Serializable BigInt where
|
instance Serializable BigInt where
|
||||||
serialize = unsafeToForeign
|
serialize = convert @BigInt
|
||||||
deserialize = lmap show <<< runExcept <<< unsafeReadTagged "BigInt"
|
deserialize = lmap show <<< runExcept <<< unsafeReadTagged "BigInt"
|
||||||
|
|
||||||
instance Serializable Boolean where
|
instance Serializable Boolean where
|
||||||
serialize = unsafeToForeign
|
serialize = convert @Boolean
|
||||||
deserialize = lmap show <<< runExcept <<< readBoolean
|
deserialize = lmap show <<< runExcept <<< readBoolean
|
||||||
|
|
||||||
instance Serializable a => Serializable (Maybe a) where
|
instance Serializable a => Serializable (Maybe a) where
|
||||||
serialize (Just a) = unsafeToForeign a
|
serialize (Just a) = convert @a a
|
||||||
serialize Nothing = undef
|
serialize Nothing = undef
|
||||||
deserialize = flip bind (traverse deserialize) <<< lmap show <<< runExcept <<< readNullOrUndefined
|
deserialize = flip bind (traverse deserialize) <<< lmap show <<< runExcept <<< readNullOrUndefined
|
||||||
|
|
||||||
instance Serializable a => Serializable (Array a) where
|
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
|
deserialize = flip bind (traverse deserialize) <<< lmap show <<< runExcept <<< readArray
|
||||||
|
|
||||||
instance Serializable a => Serializable (NonEmptyArray a) where
|
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
|
deserialize = flip bind (liftMaybe "expected non-empty array" <<< Array.NonEmpty.fromArray) <<< deserialize
|
||||||
|
|
||||||
instance Serializable a => Serializable (Object a) where
|
instance Serializable a => Serializable (Object a) where
|
||||||
serialize a = unsafeToForeign a
|
serialize a = convert @(Object a) a
|
||||||
deserialize a =
|
deserialize a =
|
||||||
if typeOf a == "object" then
|
if typeOf a == "object" then
|
||||||
pure $ unsafeFromForeign a
|
pure $ unsafeFromForeign a
|
||||||
@ -79,7 +82,7 @@ instance Serializable a => Serializable (Object a) where
|
|||||||
throwError $ "expected object, found " <> typeOf a
|
throwError $ "expected object, found " <> typeOf a
|
||||||
|
|
||||||
instance (RowToList r rl, SerializeRecord rl r () to, DeserializeRecord rl () r) => Serializable (Record r) where
|
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)
|
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
|
class DeserializeRecord (rl :: RowList Type) (from :: Row Type) (to :: Row Type) | rl -> from to where
|
||||||
|
Loading…
Reference in New Issue
Block a user