Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
ded212c5
Verified
Commit
ded212c5
authored
Jun 26, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[refactoring] cache refactoring (highlight)
Also, tests fixed a bit (at least they work).
parent
68d3856d
Pipeline
#4269
canceled with stage
Changes
12
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
73 additions
and
29 deletions
+73
-29
package.json
package.json
+2
-1
shell.nix
shell.nix
+7
-1
spago.dhall
spago.dhall
+0
-1
Field.purs
src/Gargantext/Components/Annotation/Field.purs
+1
-1
CodeSection.purs
src/Gargantext/Components/Corpus/CodeSection.purs
+4
-4
Layout.purs
src/Gargantext/Components/Document/Layout.purs
+1
-1
Functions.purs
src/Gargantext/Core/NgramsTable/Functions.purs
+2
-2
Crypto.js
src/Gargantext/Utils/Crypto.js
+14
-0
Crypto.purs
src/Gargantext/Utils/Crypto.purs
+24
-11
Spec.purs
test/Test/Gargantext/Utils/Spec.purs
+6
-4
Main.purs
test/Test/Main.purs
+7
-3
yarn.lock
yarn.lock
+5
-0
No files found.
package.json
View file @
ded212c5
...
...
@@ -63,7 +63,8 @@
"
react-tooltip
"
:
"
^4.2.8
"
,
"
secp256k1
"
:
"
^4.0.2
"
,
"
sigma
"
:
"
^2.4.0
"
,
"
twgl.js
"
:
"
^5.0.4
"
"
twgl.js
"
:
"
^5.0.4
"
,
"
uuid
"
:
"
8.3.2
"
},
"devDependencies"
:
{
"
@babel/core
"
:
"
^7.15.0
"
,
...
...
shell.nix
View file @
ded212c5
...
...
@@ -100,11 +100,16 @@ let
#spago build
#build-purs
echo "Testing"
spago -x test.dhall test --main Test.Main
spago -v -x test.dhall test --main Test.Main
# spago -x test.dhall bundle-app --main Test.Main --to dist/test-bundle.js --platform node
# pulp browserify --skip-compile -t dist/bundle.js --src-path output
# pulp test --src-path output --test-path output
#NODE_PATH=output node -e "require('Test.Main').main();"
''
;
# TODO: Remove this when nixpkgs is updated to newer version (23.05
# has nodejs 20.2.1 and we need >= 20.3.1 for crypto to work)
#nodejs_20_3_1 = pkgs.callPackage ./nix/nodejs-v20.nix {};
in
pkgs
.
mkShell
{
buildInputs
=
[
...
...
@@ -126,6 +131,7 @@ pkgs.mkShell {
pkgs
.
nodejs
#pkgs.nodePackages.purescript-language-server
#pkgs.python # needed for msgpack etc
#nodejs_20_3_1
repl
serve
pkgs
.
pulp
...
...
spago.dhall
View file @
ded212c5
...
...
@@ -74,7 +74,6 @@ to generate this file without the comments in this block.
, "sequences"
, "simple-json"
, "simple-json-generics"
, "simplecrypto"
, "string-search"
, "strings"
, "strings-extra"
...
...
src/Gargantext/Components/Annotation/Field.purs
View file @
ded212c5
...
...
@@ -148,7 +148,7 @@ compile ::
-> NgramsTable
-> Maybe String
-> Array HighlightElement
compile cache ngrams = maybe [] (highlightNgrams
CTabTerms ngrams cache
)
compile cache ngrams = maybe [] (highlightNgrams
cache CTabTerms ngrams
)
-- Runs
...
...
src/Gargantext/Components/Corpus/CodeSection.purs
View file @
ded212c5
...
...
@@ -12,7 +12,7 @@ import Data.List as List
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Show.Generic (genericShow)
import Effect (Effect)
import Effect.Aff (throwError)
import Effect.Aff (
Aff,
throwError)
import Effect.Exception (error)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (ComponentStatus(..), Variant(..))
...
...
@@ -27,7 +27,7 @@ import Gargantext.Routes (SessionRoute(Children, NodeAPI))
import Gargantext.Sessions (Session, get, put)
import Gargantext.Types (AffETableResult, NodeType(..), ID)
import Gargantext.Utils ((?))
import Gargantext.Utils.Crypto as Crypto
--
import Gargantext.Utils.Crypto as Crypto
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
...
...
@@ -112,8 +112,8 @@ fieldsCodeEditorCpt = here.component "fieldsCodeEditorCpt" cpt
recomputeIndices :: FTFieldsWithIndex -> FTFieldsWithIndex
recomputeIndices (FTFieldsWithIndex lst) = FTFieldsWithIndex $ mapWithIndex (\idx -> \{ ftField } -> { idx, ftField }) lst
hash :: FTFieldWithIndex ->
Hash
hash { idx, ftField } = Crypto.hash $ "--idx--" <> (show idx) <> "--field--" <> (show ftField)
-- hash :: FTFieldWithIndex -> Aff
Hash
--
hash { idx, ftField } = Crypto.hash $ "--idx--" <> (show idx) <> "--field--" <> (show ftField)
type FieldCodeEditorProps =
( idx :: Int
...
...
src/Gargantext/Components/Document/Layout.purs
View file @
ded212c5
src/Gargantext/Core/NgramsTable/Functions.purs
View file @
ded212c5
...
...
@@ -165,8 +165,8 @@ computeCache ngrams contextNgrams = { contextNgrams, pm, pats }
-- TODO: while this function works well with word boundaries,
-- it inserts too many spaces.
highlightNgrams ::
CTabNgramType -> NgramsTable -> Record Cach
e -> String -> Array HighlightElement
highlightNgrams
ntype table@(NgramsTable {ngrams_repo_elements: elts}) cache@{ pm, pats }
input0 =
highlightNgrams ::
Record Cache -> CTabNgramType -> NgramsTabl
e -> String -> Array HighlightElement
highlightNgrams
cache@{ pm, pats } ntype table@(NgramsTable {ngrams_repo_elements: elts})
input0 =
-- trace {pats, input0, input, ixs} \_ ->
A.fromFoldable ((\(s /\ ls)-> undb s /\ ls) <$> unsafePartial (foldl goFold ((input /\ Nil) : Nil) ixs))
where
...
...
src/Gargantext/Utils/Crypto.js
0 → 100644
View file @
ded212c5
//import crypto from 'crypto';
async
function
getSHA256Hash
(
input
)
{
const
textAsBuffer
=
new
TextEncoder
().
encode
(
input
);
const
hashBuffer
=
await
globalThis
.
crypto
.
subtle
.
digest
(
"SHA-256"
,
textAsBuffer
);
const
hashArray
=
Array
.
from
(
new
Uint8Array
(
hashBuffer
));
const
hash
=
hashArray
.
map
((
item
)
=>
item
.
toString
(
16
).
padStart
(
2
,
"0"
))
.
join
(
""
);
return
hash
;
};
export
const
getSHA256HashImpl
=
(
s
)
=>
()
=>
getSHA256Hash
(
s
);
src/Gargantext/Utils/Crypto.purs
View file @
ded212c5
module Gargantext.Utils.Crypto where
import C
rypto.Simple as Crypto
import C
ontrol.Promise (Promise, toAffE)
import Data.Set (Set)
import Data.Set as Set
import Data.Array as Array
import Effect (Effect)
import Effect.Aff (Aff)
import Gargantext.Prelude
foreign import getSHA256HashImpl :: String -> Effect (Promise String)
getSHA256Hash :: String -> Aff String
getSHA256Hash = getSHA256HashImpl >>> toAffE
-- | TODO use newtype to disambiguate Set String and Set Hash
-- Set String needs Set.map hash
-- Set Hash does not need Set.map hash (just concat)
type Hash = String
hash' :: forall a. Crypto.Hashable a => a -> String
hash' = Crypto.toString <<< Crypto.hash Crypto.SHA256
hash' :: String -> Aff String
hash' = getSHA256Hash
--hash' :: forall a. Crypto.Hashable a => a -> String
--hash' = Crypto.toString <<< Crypto.hash Crypto.SHA256
class IsHashable a where
hash :: a -> Hash
hash :: a ->
Aff
Hash
instance IsHashable String
where
hash = hash'
instance (Crypto.Hashable a, IsHashable a) => IsHashable (Array a)
--instance (Crypto.Hashable a, IsHashable a) => IsHashable (Array a)
-- where
-- hash = hash <<< Set.fromFoldable <<< map hash
instance IsHashable (Array String) where
hash = hash <<< concat
where
hash = hash <<< Set.fromFoldable <<< map hash
concat :: Array Hash -> String
concat = Array.foldl (<>) ""
instance IsHashable (Set String) where
hash = hash <<<
concat <<<
toArray
hash = hash <<< toArray
where
toArray :: forall a. Set a -> Array a
toArray = Set.toUnfoldable
concat :: Array Hash -> String
concat = Array.foldl (<>) ""
test/Test/Gargantext/Utils/Spec.purs
View file @
ded212c5
...
...
@@ -119,19 +119,21 @@ spec =
let text = "To hash with backend"
let hashed = "8a69a94d164279af2b7d1443ce08da6184b3d7e815406076e148159c284b53c3"
-- ^ hash from backend with text above
Crypto.hash text `shouldEqual` hashed
h <- Crypto.hash text
h `shouldEqual` hashed
it "Hash List with backend works" do
let list = ["a","b"]
let hashed = "ab19ec537f09499b26f0f62eed7aefad46ab9f498e06a7328ce8e8ef90da6d86"
-- ^ hash from backend with text above
Crypto.hash list `shouldEqual` hashed
h <- Crypto.hash list
h`shouldEqual` hashed
------------------------------------------------------------------------
-- | TODO property based tests
it "Hash works with any order of list" do
let hash1 =
Crypto.hash ["a","b"]
let hash2 =
Crypto.hash ["b","a"]
hash1 <-
Crypto.hash ["a","b"]
hash2 <-
Crypto.hash ["b","a"]
hash1 `shouldEqual` hash2
------------------------------------------------------------------------
...
...
test/Test/Main.purs
View file @
ded212c5
...
...
@@ -3,11 +3,15 @@ module Test.Main where
import Prelude
import Effect (Effect)
import Effect.Aff (launchAff_)
-- import Effect.Uncurried (EffectFn1, runEffectFn1)
import Test.Spec.Discovery (discover)
import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (runSpec)
-- foreign import _cryptoFix :: forall e. EffectFn1 e Unit
main :: Effect Unit
main = launchAff_ do
specs <- discover "Gargantext\\..*Spec"
main = do
launchAff_ do
specs <- discover "Test\\.Gargantext\\..*Spec"
runSpec [consoleReporter] specs
yarn.lock
View file @
ded212c5
...
...
@@ -8778,6 +8778,11 @@ utility-types@^3.10.0:
resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.10.0.tgz#ea4148f9a741015f05ed74fd615e1d20e6bed82b"
integrity sha512-O11mqxmi7wMKCo6HKFt5AhO4BwY3VV68YU07tgxfz8zJTIxr4BpsezN49Ffwy9j3ZpwwJp4fkRwjRzq3uWE6Rg==
uuid@8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
uuid@^3.3.2:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment