diff --git a/.eslintrc.json b/.eslintrc.json index 39963d3..81104c4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,9 @@ { "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 6, + "sourceType": "module" }, "extends": "eslint:recommended", - "env": { - "commonjs": true - }, "rules": { "strict": [2, "global"], "block-scoped-var": 2, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43d2897..b6ebf3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: - uses: actions/checkout@v2 - uses: purescript-contrib/setup-purescript@main + with: + purescript: "unstable" - uses: actions/setup-node@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index bf067cc..eeae3fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: +- Migrate FFI to ES modules (#81 by @kl0tl and @JordanMartinez) +- Replaced polymorphic proxies with monomorphic `Proxy` (#81 by @JordanMartinez) New features: diff --git a/bower.json b/bower.json index 4f90f39..28a4814 100644 --- a/bower.json +++ b/bower.json @@ -17,11 +17,11 @@ "package.json" ], "dependencies": { - "purescript-functions": "^5.0.0", - "purescript-prelude": "^5.0.0", - "purescript-unsafe-coerce": "^5.0.0" + "purescript-functions": "master", + "purescript-prelude": "master", + "purescript-unsafe-coerce": "master" }, "devDependencies": { - "purescript-assert": "^5.0.0" + "purescript-assert": "master" } } diff --git a/package.json b/package.json index 3ed6897..8382d60 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ }, "devDependencies": { "eslint": "^7.15.0", - "purescript-psa": "^0.8.0", - "pulp": "^15.0.0", + "purescript-psa": "^0.8.2", + "pulp": "16.0.0-0", "rimraf": "^3.0.2" } } diff --git a/src/Record.purs b/src/Record.purs index 3b2c583..11154ca 100644 --- a/src/Record.purs +++ b/src/Record.purs @@ -34,10 +34,10 @@ import Unsafe.Coerce (unsafeCoerce) -- | get (Proxy :: Proxy "x") :: forall r a. { x :: a | r } -> a -- | ``` get - :: forall proxy r r' l a + :: forall r r' l a . IsSymbol l => Cons l a r' r - => proxy l + => Proxy l -> Record r -> a get l r = unsafeGet (reflectSymbol l) r @@ -52,11 +52,11 @@ get l r = unsafeGet (reflectSymbol l) r -- | :: forall r a b. a -> { x :: b | r } -> { x :: a | r } -- | ``` set - :: forall proxy r1 r2 r l a b + :: forall r1 r2 r l a b . IsSymbol l => Cons l a r r1 => Cons l b r r2 - => proxy l + => Proxy l -> b -> Record r1 -> Record r2 @@ -72,11 +72,11 @@ set l b r = unsafeSet (reflectSymbol l) b r -- | :: forall r a b. (a -> b) -> { x :: a | r } -> { x :: b | r } -- | ``` modify - :: forall proxy r1 r2 r l a b + :: forall r1 r2 r l a b . IsSymbol l => Cons l a r r1 => Cons l b r r2 - => proxy l + => Proxy l -> (a -> b) -> Record r1 -> Record r2 @@ -92,11 +92,11 @@ modify l f r = set l (f (get l r)) r -- | :: forall r a. Lacks "x" r => a -> { | r } -> { x :: a | r } -- | ``` insert - :: forall proxy r1 r2 l a + :: forall r1 r2 l a . IsSymbol l => Lacks l r1 => Cons l a r1 r2 - => proxy l + => Proxy l -> a -> Record r1 -> Record r2 @@ -115,11 +115,11 @@ insert l a r = unsafeSet (reflectSymbol l) a r -- | :: forall r a. Lacks "x" r => { x :: a | r } -> { | r } -- | ``` delete - :: forall proxy r1 r2 l a + :: forall r1 r2 l a . IsSymbol l => Lacks l r1 => Cons l a r1 r2 - => proxy l + => Proxy l -> Record r2 -> Record r1 delete l r = unsafeDelete (reflectSymbol l) r @@ -136,15 +136,15 @@ delete l r = unsafeDelete (reflectSymbol l) r -- | rename (Proxy :: Proxy "x") (Proxy :: Proxy "y") -- | :: forall a r. Lacks "x" r => Lacks "y" r => { x :: a | r} -> { y :: a | r} -- | ``` -rename :: forall proxy prev next ty input inter output +rename :: forall prev next ty input inter output . IsSymbol prev => IsSymbol next => Cons prev ty inter input => Lacks prev inter => Cons next ty inter output => Lacks next inter - => proxy prev - -> proxy next + => Proxy prev + -> Proxy next -> Record input -> Record output rename prev next record = @@ -224,7 +224,7 @@ equal equal a b = equalFields (Proxy :: Proxy rs) a b class EqualFields (rs :: RowList Type) (row :: Row Type) | rs -> row where - equalFields :: forall rlproxy. rlproxy rs -> Record row -> Record row -> Boolean + equalFields :: Proxy rs -> Record row -> Record row -> Boolean instance equalFieldsCons :: diff --git a/src/Record/Builder.js b/src/Record/Builder.js index 89df61c..bae6e96 100644 --- a/src/Record/Builder.js +++ b/src/Record/Builder.js @@ -1,6 +1,4 @@ -"use strict"; - -exports.copyRecord = function(rec) { +export function copyRecord(rec) { var copy = {}; for (var key in rec) { if ({}.hasOwnProperty.call(rec, key)) { @@ -8,34 +6,34 @@ exports.copyRecord = function(rec) { } } return copy; -}; +} -exports.unsafeInsert = function(l) { +export function unsafeInsert(l) { return function(a) { return function(rec) { rec[l] = a; return rec; }; }; -}; +} -exports.unsafeModify = function(l) { +export function unsafeModify(l) { return function (f) { return function(rec) { rec[l] = f(rec[l]); return rec; }; }; -}; +} -exports.unsafeDelete = function(l) { +export function unsafeDelete(l) { return function(rec) { delete rec[l]; return rec; }; -}; +} -exports.unsafeRename = function(l1) { +export function unsafeRename(l1) { return function (l2) { return function (rec) { rec[l2] = rec[l1]; @@ -43,4 +41,4 @@ exports.unsafeRename = function(l1) { return rec; }; }; -}; +} diff --git a/src/Record/Builder.purs b/src/Record/Builder.purs index a3bea60..acc204f 100644 --- a/src/Record/Builder.purs +++ b/src/Record/Builder.purs @@ -20,6 +20,7 @@ import Data.Function.Uncurried (runFn2) import Data.Symbol (class IsSymbol, reflectSymbol) import Prim.Row as Row import Record.Unsafe.Union (unsafeUnionFn) +import Type.Proxy (Proxy) import Unsafe.Coerce (unsafeCoerce) foreign import copyRecord :: forall r1. Record r1 -> Record r1 @@ -61,46 +62,46 @@ derive newtype instance categoryBuilder :: Category Builder -- | Build by inserting a new field. insert - :: forall proxy l a r1 r2 + :: forall l a r1 r2 . Row.Cons l a r1 r2 => Row.Lacks l r1 => IsSymbol l - => proxy l + => Proxy l -> a -> Builder (Record r1) (Record r2) insert l a = Builder \r1 -> unsafeInsert (reflectSymbol l) a r1 -- | Build by modifying an existing field. modify - :: forall proxy l a b r r1 r2 + :: forall l a b r r1 r2 . Row.Cons l a r r1 => Row.Cons l b r r2 => IsSymbol l - => proxy l + => Proxy l -> (a -> b) -> Builder (Record r1) (Record r2) modify l f = Builder \r1 -> unsafeModify (reflectSymbol l) f r1 -- | Build by deleting an existing field. delete - :: forall proxy l a r1 r2 + :: forall l a r1 r2 . IsSymbol l => Row.Lacks l r1 => Row.Cons l a r1 r2 - => proxy l + => Proxy l -> Builder (Record r2) (Record r1) delete l = Builder \r2 -> unsafeDelete (reflectSymbol l) r2 -- | Build by renaming an existing field. -rename :: forall proxy l1 l2 a r1 r2 r3 +rename :: forall l1 l2 a r1 r2 r3 . IsSymbol l1 => IsSymbol l2 => Row.Cons l1 a r2 r1 => Row.Lacks l1 r2 => Row.Cons l2 a r2 r3 => Row.Lacks l2 r2 - => proxy l1 - -> proxy l2 + => Proxy l1 + -> Proxy l2 -> Builder (Record r1) (Record r3) rename l1 l2 = Builder \r1 -> unsafeRename (reflectSymbol l1) (reflectSymbol l2) r1 diff --git a/src/Record/Unsafe/Union.js b/src/Record/Unsafe/Union.js index 637d503..01efccf 100644 --- a/src/Record/Unsafe/Union.js +++ b/src/Record/Unsafe/Union.js @@ -1,6 +1,4 @@ -"use strict"; - -exports.unsafeUnionFn = function(r1, r2) { +export function unsafeUnionFn(r1, r2) { var copy = {}; for (var k1 in r2) { if ({}.hasOwnProperty.call(r2, k1)) { @@ -13,4 +11,4 @@ exports.unsafeUnionFn = function(r1, r2) { } } return copy; -}; +}