git.iko.soy/rowtype-yoga/purescript-vault
on master help sign in
13 files changed+160−150
since splitsnapshots
unifiedsplit
.github/workflows/ci.yml+19 .tidyrc.json+10 CHANGELOG.md+16−1 CONTRIBUTING.md+49−2 README.md+31−9 bower.json+6−5 packages.dhall+2−2 shell.nix+2−2 spago.dhall+8−1 src/Data/Vault.purs+16−17 src/Data/Vault/Internal.js−49 src/Data/Vault/Internal.purs−61 test.dhall+1−1
.github/workflows/ci.yml+19
@@ -15,6 +15,16 @@ jobs:
1515
1616 - name: Set up a PureScript toolchain
1717 uses: purescript-contrib/setup-purescript@main
18+ with:
19+ bower: "latest"
20+ purescript: "latest"
21+ psa: "latest"
22+ pulp: "latest"
23+ spago: "latest"
24+ purs-tidy: "latest"
25+
26+ - name: Check formatting
27+ run: purs-tidy check src test
1828
1929 - name: Cache PureScript dependencies
2030 uses: actions/cache@v2
@@ -32,3 +42,12 @@ jobs:
3242
3343 - name: Run tests
3444 run: spago -x test.dhall test
45+
46+ - name: Verify Bower & Pulp
47+ run: |
48+ npm install bower pulp@16.0.0-0
49+ npx bower install
50+ npx pulp build -- --censor-lib --strict
51+ if [ -d "test" ]; then
52+ npx pulp test
53+ fi
.tidyrc.jsonnew file+10
@@ -0,0 +1,10 @@
1+{
2+ "importSort": "source",
3+ "importWrap": "source",
4+ "indent": 2,
5+ "operatorsFile": null,
6+ "ribbon": 1,
7+ "typeArrowPlacement": "first",
8+ "unicode": "never",
9+ "width": null
10+}
CHANGELOG.md+16−1
@@ -4,15 +4,30 @@ Notable changes to this project are documented in this file. The format is based
44
55## [Unreleased]
66
7+Breaking changes:
8+
9+New features:
10+
11+Bugfixes:
12+
13+Other improvements:
14+- Updated the project for its new home in the Rowtype Yoga organization. ([c86a9a9](https://github.com/rowtype-yoga/purescript-vault/commit/c86a9a97840bb871e7b687f3056fedead99b925b) by @nsaunders)
15+
16+## [1.0.0] - 2023-03-09
17+
718Breaking changes:
819- Updated to v0.15 of the compiler, dropping support for previous versions. (#1 by @nsaunders)
920
1021New features:
22+- Added the `adjust` function which allows the value corresponding to a given key to be modified. (#2 by @nsaunders)
1123
1224Bugfixes:
25+- Fixed `union` function which previously ignored the first argument. (#2 by @nsaunders)
1326
1427Other improvements:
15−- Updated the project to the standards of the [purescript-contrib](https://github.com/purescript-contrib) organization. ([713fd52](https://github.com/purescript-community/purescript-vault/commit/713fd521362c2833cea5f9ef3afb1e600164b903) by @nsaunders)
28+- Updated the project to the standards of the [purescript-contrib](https://github.com/purescript-contrib) organization. ([713fd52](https://github.com/rowtype-yoga/purescript-vault/commit/713fd521362c2833cea5f9ef3afb1e600164b903) by @nsaunders)
29+- Updated the test suite to include better coverage. (#2 by @nsaunders)
30+- New implementation removes FFI code. (#3 by @nsaunders)
1631
1732## [0.1.0] - 2017-10-30
1833
CONTRIBUTING.md+49−2
@@ -1,3 +1,50 @@
1−# Contributing to Vault
1+Contributing
2+============
23
3−Thanks for your interest in contributing to `vault`! We welcome new contributions regardless of your level of experience or familiarity with PureScript.
4+Welcome, and thanks for your interest in Vault. Whether you are new to PureScript or here to teach us new tricks, we're glad to have you and look forward to your contributions. Listed below are a few ways you can help.
5+
6+Asking questions
7+----------------
8+If you have a question, please [open an issue](https://github.com/rowtype-yoga/purescript-vault/issues/new?labels=question) to discuss it. This might help us to find a defect; reveal an opportunity to improve the documentation or developer experience; or help someone facing a similar issue in the future.
9+
10+Reporting bugs
11+--------------
12+Please [open an issue](https://github.com/rowtype-yoga/purescript-vault/issues/new?labels=bug&template=bug-report.md) to discuss any defects you find.
13+
14+Enhancements
15+------------
16+Please [open an issue](https://github.com/rowtype-yoga/purescript-vault/issues/new?labels=enhancement&template=change-request.md) to discuss potential enhancements to the library. When submitting design ideas, please note that, for the most part, this library is intended as a direct port of the Haskell [vault](https://hackage.haskell.org/package/vault) package as described in [this blog post](https://apfelmus.nfshost.com/blog/2011/09/04-vault.html).
17+
18+Improving documentation
19+-----------------------
20+Please share any suggestions for improving or adding to the documentation by [submitting a pull request](https://github.com/rowtype-yoga/purescript-vault/compare) or [opening an issue](https://github.com/rowtype-yoga/purescript-vault/issues/new?labels=documentation).
21+
22+Sharing resources
23+-----------------
24+If you have created a tutorial, auxiliary library, interesting code example, or other resource related to Vault, please [share it with the PureScript community](https://discourse.purescript.org). Increasing awareness will bring more users (and potential contributors) to the project.
25+
26+Submitting code
27+---------------
28+Pull requests are welcome, but we ask that you [open an issue](https://github.com/rowtype-yoga/purescript-vault/issues/new) to discuss your plans before making any significant investment of your valuable time.
29+
30+### Development environment
31+
32+You can use [Nix](https://github.com/NixOS/nix) to create a development environment with all required tooling. Simply run `nix-shell` in the root project directory, and you'll have everything you need to get started.
33+
34+### Making changes
35+
36+* After making any changes, run `purs-tidy format-in-place src test` to format the code.
37+* Unit test(s) should accompany each change.
38+
39+### Preparing your submission
40+
41+Please verify your changes before submitting a pull request using the following commands:
42+1. `purs-tidy check src test`, which ensures that modules in the `src` and `test` directories conform to the project's formatting standards; and
43+1. `spago -x test.dhall test`, which runs the unit tests.
44+
45+### Submitting a pull request
46+
47+When you are ready to [submit a pull request](https://github.com/rowtype-yoga/purescript-vault/compare), please make sure to include:
48+1. a brief description of the change;
49+1. a link to the related issue, if applicable; and
50+1. any design considerations you feel are important.
README.md+31−9
@@ -1,13 +1,13 @@
11# Vault
22
3−[![CI](https://github.com/purescript-community/purescript-vault/workflows/CI/badge.svg?branch=master)](https://github.com/purescript-community/purescript-vault/actions?query=workflow%3ACI+branch%3Amaster)
4−[![Release](https://img.shields.io/github/release/purescript-community/purescript-vault.svg)](https://github.com/purescript-community/purescript-vault/releases)
3+[![CI](https://github.com/rowtype-yoga/purescript-vault/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-vault/actions?query=workflow%3ACI+branch%3Amaster)
4+[![Release](https://img.shields.io/github/release/rowtype-yoga/purescript-vault.svg)](https://github.com/rowtype-yoga/purescript-vault/releases)
55[![Pursuit](https://pursuit.purescript.org/packages/purescript-vault/badge)](https://pursuit.purescript.org/packages/purescript-vault)
66[![Maintainer: nsaunders](https://img.shields.io/badge/maintainer-nsaunders-teal.svg)](https://github.com/nsaunders)
77
8−A typed, persistent store for values of arbitrary types. This is a port of the haskell [Vault](https://github.com/HeinrichApfelmus/vault) library Heinrich Apfelmus.
8+A typed, persistent store for values of arbitrary types, ported from the Haskell [Vault](https://github.com/HeinrichApfelmus/vault) library by Heinrich Apfelmus.
99
10−Think of it as Map that can store for values of arbitrary types, but it's type-safe. You can store of any types by creating Key a first, this key used to parameterized the type you are going to store in vault.
10+Think of a vault like a map that can store any value in a type-safe manner. The first step is to generate a new `Key a` value using the `newKey` function. Then, use `insert`, `lookup`, `delete`, etc., just like their [Data.Map](https://pursuit.purescript.org/packages/purescript-ordered-collections/3.0.0/docs/Data.Map) analogs.
1111
1212```purescript
1313data Vault
@@ -15,9 +15,10 @@ data Key a
1515
1616newKey :: forall a. Effect (Key a)
1717empty :: Vault
18−lookup :: forall a. Key a -> Vault -> Maybe a
1918insert :: forall a. Key a -> a -> Vault -> Vault
19+lookup :: forall a. Key a -> Vault -> Maybe a
2020delete :: forall a. Key a -> Vault -> Vault
21+adjust :: forall a. (a -> a) -> Key a -> Vault -> Vault
2122```
2223
2324## Installation
@@ -28,13 +29,34 @@ Install `vault` with [Spago](https://github.com/purescript/spago):
2829spago install vault
2930```
3031
32+If `vault` is not included in your package set, include it in `packages.dhall`, e.g.
33+
34+```dhall
35+let upstream = -- <package set URL here>
36+in upstream
37+ with vault =
38+ { dependencies =
39+ [ "effect"
40+ , "maybe"
41+ , "ordered-collections"
42+ , "prelude"
43+ , "refs"
44+ , "unique"
45+ ]
46+ , repo =
47+ "https://github.com/rowtype-yoga/purescript-vault.git"
48+ , version =
49+ "v1.0.0"
50+ }
51+```
52+
3153## Quick start
3254
3355The quick start hasn't been written yet (contributions are welcome!). The quick start covers a common, minimal use case for the library, whereas longer examples and tutorials are kept in the [docs directory](./docs).
3456
3557## Documentation
3658
37−`vault` documentation is stored in a few places:
59+Vault documentation is stored in a few places:
3860
39611. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-vault).
40622. Written documentation is kept in the [docs directory](./docs).
@@ -42,14 +64,14 @@ The quick start hasn't been written yet (contributions are welcome!). The quick
4264
4365If you get stuck, there are several ways to get help:
4466
45−- [Open an issue](https://github.com/purescript-community/purescript-vault/issues) if you have encountered a bug or problem.
67+- [Open an issue](https://github.com/rowtype-yoga/purescript-vault/issues/new?labels=bug&template=bug-report.md) if you have encountered a bug or problem.
4668- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://discord.com/invite/sMqwYUbvz6) chat.
4769
4870## Contributing
4971
50−You can contribute to `vault` in several ways:
72+You can contribute to Vault in several ways:
5173
52−1. If you encounter a problem or have a question, please [open an issue](https://github.com/purescript-community/purescript-vault/issues). We'll do our best to work with you to resolve or answer it.
74+1. If you encounter a problem or have a question, please [open an issue](https://github.com/rowtype-yoga/purescript-vault/issues). We'll do our best to work with you to resolve or answer it.
5375
54762. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions.
5577
bower.json+6−5
@@ -6,7 +6,7 @@
66 ],
77 "repository": {
88 "type": "git",
9− "url": "git://github.com/julienchan/purescript-vault.git"
9+ "url": "git://github.com/rowtype-yoga/purescript-vault.git"
1010 },
1111 "ignore": [
1212 "**/.*",
@@ -16,13 +16,14 @@
1616 ],
1717 "dependencies": {
1818 "purescript-prelude": "^6.0.0",
19− "purescript-functions": "^6.0.0",
2019 "purescript-effect": "^4.0.0",
20+ "purescript-ordered-collections": "^3.0.0",
2121 "purescript-refs": "^6.0.0",
22− "purescript-maybe": "^6.0.0"
22+ "purescript-maybe": "^6.0.0",
23+ "purescript-unique": "^0.6.0"
2324 },
2425 "devDependencies": {
25− "purescript-psci-support": "^6.0.0",
26− "purescript-console": "^6.0.0"
26+ "purescript-aff": "^7.0.0",
27+ "purescript-spec": "^7.0.0"
2728 }
2829}
packages.dhall+2−2
@@ -1,5 +1,5 @@
11let upstream =
2− https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221015/packages.dhall
3− sha256:4949f9f5c3626ad6a83ea6b8615999043361f50905f736bc4b7795cba6251927
2+ https://github.com/purescript/package-sets/releases/download/psc-0.15.7-20230306/packages.dhall
3+ sha256:0757626c7422b8b5b5b1d0df3d3628e5deac755d7f89c433a9bf89009787dcbd
44
55in upstream
shell.nix+2−2
@@ -10,8 +10,8 @@ let
1010 pursPkgs = import (pkgs.fetchFromGitHub {
1111 owner = "justinwoo";
1212 repo = "easy-purescript-nix";
13− rev = "ee51a6d459b8fecfcb10f24ca9728e649c6a9e00";
14− sha256 = "1w4k6mcayyg6388na0cca5qx94sm99xn3na26x2w34jlyz3bwl3m";
13+ rev = "11d3bd58ce6e32703bf69cec04dc7c38eabe14ba";
14+ sha256 = "0q24hb4a3fvcizns17ddd4pshlbkfdq2m6pgcjfslwlvgnbrli5l";
1515 }) {inherit pkgs;};
1616in
1717 pkgs.stdenv.mkDerivation {
spago.dhall+8−1
@@ -1,5 +1,12 @@
11{ name = "vault"
2−, dependencies = [ "effect", "functions", "maybe", "prelude", "refs" ]
2+, dependencies =
3+ [ "effect"
4+ , "maybe"
5+ , "ordered-collections"
6+ , "prelude"
7+ , "refs"
8+ , "unique"
9+ ]
310, packages = ./packages.dhall
411, sources = [ "src/**/*.purs" ]
512}
src/Data/Vault.purs+16−17
@@ -17,15 +17,16 @@ import Effect.Unsafe (unsafePerformEffect)
1717import Effect.Ref (Ref)
1818import Effect.Ref as Ref
1919
20−import Data.Function.Uncurried as Fn
20+import Data.Map (Map)
21+import Data.Map as Map
2122import Data.Maybe (Maybe(..), fromMaybe)
22−import Data.Vault.Internal as V
23+import Data.Unique (Unique, newUnique)
2324
2425-- | A persistent store for values of arbitrary types.
25−newtype Vault = Vault (V.UniqueMap Item)
26+newtype Vault = Vault (Map Unique Item)
2627
2728-- | Key for an item in vault
28−data Key a = Key V.Unique (Item' a)
29+data Key a = Key Unique (Item' a)
2930
3031type Item = Effect Unit
3132
@@ -33,18 +34,18 @@ type Item' a = Ref (Maybe a)
3334
3435-- | The empty vault
3536empty :: Vault
36−empty = Vault V.empty
37+empty = Vault Map.empty
3738
3839-- | Create a new key for use with a vault.
3940newKey :: forall a. Effect (Key a)
4041newKey = do
41− k <- V.newUnique
42+ k <- newUnique
4243 ref <- Ref.new Nothing
4344 pure $ Key k ref
4445
4546-- | Insert a value for a given key. Overwrites any previous value.
4647insert :: forall a. Key a -> a -> Vault -> Vault
47−insert (Key k ref) a (Vault m) = Vault (Fn.runFn3 V.insert k (Ref.write (Just a) ref) m)
48+insert (Key k ref) a (Vault m) = Vault $ Map.insert k (Ref.write (Just a) ref) m
4849
4950-- | Modify the value corresponding to the specified key by applying the specified function.
5051adjust :: forall a. (a -> a) -> Key a -> Vault -> Vault
@@ -52,18 +53,16 @@ adjust f k m = fromMaybe m $ lookup k m >>= \x -> pure $ insert k (f x) m
5253
5354-- | Delete a key from the vault.
5455delete :: forall a. Key a -> Vault -> Vault
55−delete (Key k _) (Vault m) = Vault (Fn.runFn2 V.delete k m)
56+delete (Key k _) (Vault m) = Vault $ Map.delete k m
5657
5758-- | Lookup the value of a key in the vault.
5859lookup :: forall a. Key a -> Vault -> Maybe a
59−lookup (Key k ref) (Vault m) = case Fn.runFn4 V.lookup Nothing Just k m of
60− Nothing -> Nothing
61− Just act -> unsafePerformEffect do
62− _ <- act
63− Ref.modify' rollItem ref
60+lookup (Key k ref) (Vault m) =
61+ Map.lookup k m >>= \item -> unsafePerformEffect do
62+ item
63+ maybeX <- Ref.read ref
64+ Ref.write Nothing ref
65+ pure maybeX
6466
6567union :: Vault -> Vault -> Vault
66−union (Vault m) (Vault n) = Vault (Fn.runFn2 V.union m n)
67−
68−rollItem :: forall a. Maybe a -> { state :: Maybe a, value :: Maybe a }
69−rollItem a = { state: Nothing, value: a }
68+union (Vault m) (Vault n) = Vault $ Map.union m n
src/Data/Vault/Internal.jsdeleted−49
@@ -1,49 +0,0 @@
1−"use strict";
2−
3−export function newUnique() {
4− return Symbol();
5−}
6−
7−export const empty = Object.create(null);
8−
9−function _copySM(m) {
10− var keys = Object.getOwnPropertySymbols(m),
11− sm = Object.create(null);
12− for (var i = 0, len = keys.length; i < len; i++) {
13− sm[keys[i]] = m[keys[i]];
14− }
15− return sm;
16−}
17−
18−export function lookup(no, yes, k, m) {
19− return k in m ? yes(m[k]) : no;
20−}
21−
22−export function insert(k, v, m) {
23− var n = _copySM(m);
24− n[k] = v;
25− return n;
26−}
27−
28−export function _delete(k, m) {
29− var result = Object.create(null);
30− var keys = Object.getOwnPropertySymbols(m);
31− for (var i = 0, len = keys.length; i < len; i++) {
32− if (keys[i] === k) continue;
33− result[keys[i]] = m[keys[i]];
34− }
35− return result
36−}
37−
38−export function union(m, n) {
39− var result = Object.create(null);
40− var k1 = Object.getOwnPropertySymbols(n);
41− for (var i = 0, len = k1.length; i < len; i++) {
42− result[k1[i]] = n[k1[i]];
43− }
44− var k2 = Object.getOwnPropertySymbols(m);
45− for (var j = 0, length = k2.length; j < length; j++) {
46− result[k2[j]] = m[k2[j]];
47− }
48− return result;
49−}
src/Data/Vault/Internal.pursdeleted−61
@@ -1,61 +0,0 @@
1−module Data.Vault.Internal
2− ( Unique
3− , newUnique
4− , UniqueMap
5− , empty
6− , lookup
7− , insert
8− , union
9− , delete
10− ) where
11−
12−import Effect (Effect)
13−import Data.Function.Uncurried as Fn
14−import Data.Maybe (Maybe)
15−
16−foreign import data Unique :: Type
17−
18−foreign import newUnique :: Effect Unique
19−
20−foreign import data UniqueMap :: Type -> Type
21−
22−foreign import empty :: forall a. UniqueMap a
23−
24−foreign import _delete
25− :: forall a
26− . Fn.Fn2
27− Unique
28− (UniqueMap a)
29− (UniqueMap a)
30−
31−delete
32− :: forall a
33− . Fn.Fn2
34− Unique
35− (UniqueMap a)
36− (UniqueMap a)
37−delete = _delete
38−
39−foreign import lookup
40− :: forall a
41− . Fn.Fn4
42− (forall x. Maybe x)
43− (forall x. x -> Maybe x)
44− Unique
45− (UniqueMap a)
46− (Maybe a)
47−
48−foreign import insert
49− :: forall a
50− . Fn.Fn3
51− Unique
52− a
53− (UniqueMap a)
54− (UniqueMap a)
55−
56−foreign import union
57− :: forall a
58− . Fn.Fn2
59− (UniqueMap a)
60− (UniqueMap a)
61− (UniqueMap a)
test.dhall+1−1
@@ -2,5 +2,5 @@ let conf = ./spago.dhall
22
33in conf // {
44 sources = conf.sources # ["test/**/*.purs"],
5− dependencies = conf.dependencies # ["aff", "console", "spec"]
5+ dependencies = conf.dependencies # ["aff", "spec"]
66}