git.iko.soy/rowtype-yoga/purescript-uuid
on main help sign in
14 files changed+219−152
since splitsnapshots
unifiedsplit
.eslintrc−4 .github/workflows/node.js.yml+31 .gitignore+6−2 LICENSE+21 README.md+6−4 bower.json−24 bun.lock+14 docs/Data/UUID.md−43 package.json+4−25 purs.json+15 spago.yaml+14 src/Data/UUID.js+17−10 src/Data/UUID.purs+48−20 test/Main.purs+43−20
.eslintrcdeleted−4
@@ -1,4 +0,0 @@
1−---
2−node: true
3−extends:
4− - semistandard
.github/workflows/node.js.ymlnew file+31
@@ -0,0 +1,31 @@
1+# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+name: Build & Test
5+
6+on:
7+ push:
8+ branches: [main]
9+ pull_request:
10+ branches: [main]
11+
12+jobs:
13+ build:
14+ runs-on: ubuntu-latest
15+
16+ strategy:
17+ matrix:
18+ node-version: [12.x, 14.x, 16.x, 17.x, 18.x]
19+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
20+
21+ steps:
22+ - uses: actions/checkout@v2
23+ - name: Use Node.js ${{ matrix.node-version }}
24+ uses: actions/setup-node@v2
25+ with:
26+ node-version: ${{ matrix.node-version }}
27+ cache: "npm"
28+ - run: npm ci
29+ - run: npm run deps --if-present
30+ - run: npm run build --if-present
31+ - run: npm test
.gitignore+6−2
@@ -1,6 +1,10 @@
11/bower_components/
2−/node_modules/
2+node_modules/
33/.pulp-cache/
4−/output/
4+output/
5+/output-pulp/
56/.psci*
67/src/.webpack.js
8+.psc-ide-port
9+/.spago/
10+.purs-repl
LICENSEnew file+21
@@ -0,0 +1,21 @@
1+MIT License
2+
3+Copyright (c) 2018 Madeline Trotter
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+
12+The above copyright notice and this permission notice shall be included in all
13+copies or substantial portions of the Software.
14+
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+SOFTWARE.
README.md+6−4
@@ -1,5 +1,7 @@
1−#purescript-uuid
1+# purescript-uuid
22
3−Wrapper for the `uuid` and `uuid-validate` npm packages.
4−These packages are not installed automatically, as they come from `npm`.
5−Install them with `npm install -S uuid uuid-validate`.
3+[![Build & Test](https://github.com/megamaddu/purescript-uuid/actions/workflows/node.js.yml/badge.svg)](https://github.com/megamaddu/purescript-uuid/actions/workflows/node.js.yml)
4+
5+Wrapper for the `uuid` npm package.
6+This package is not installed automatically, as it comes from `npm`.
7+Install it with `npm install -S uuid`.
bower.jsondeleted−24
@@ -1,24 +0,0 @@
1−{
2− "name": "purescript-uuid",
3− "version": "2.0.0",
4− "moduleType": [
5− "node"
6− ],
7− "ignore": [
8− "**/.*",
9− "node_modules",
10− "bower_components",
11− "output"
12− ],
13− "repository": {
14− "type": "git",
15− "url": "git://github.com/spicydonuts/purescript-uuid.git"
16− },
17− "dependencies": {
18− "purescript-eff": "^1.0.0"
19− },
20− "devDependencies": {
21− "purescript-console": "^1.0.0",
22− "purescript-spec": "~0.8.0"
23− }
24−}
bun.locknew file+14
@@ -0,0 +1,14 @@
1+{
2+ "lockfileVersion": 1,
3+ "workspaces": {
4+ "": {
5+ "name": "purescript-uuid",
6+ "dependencies": {
7+ "uuid": "^13.0.0",
8+ },
9+ },
10+ },
11+ "packages": {
12+ "uuid": ["uuid@13.0.0", "", { "bin": { "uuid": "dist-node/bin/uuid" } }, "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w=="],
13+ }
14+}
docs/Data/UUID.mddeleted−43
@@ -1,43 +0,0 @@
1−## Module Data.UUID
2−
3−#### `UUID`
4−
5−``` purescript
6−newtype UUID
7−```
8−
9−Represents a UUID String.
10−Most UUID instances defer to String
11−
12−##### Instances
13−``` purescript
14−Show UUID
15−Eq UUID
16−Ord UUID
17−```
18−
19−#### `GENUUID`
20−
21−``` purescript
22−data GENUUID :: !
23−```
24−
25−The effect of generating a new UUID.
26−
27−#### `genUUID`
28−
29−``` purescript
30−genUUID :: forall e. Eff (uuid :: GENUUID | e) UUID
31−```
32−
33−Generates a v4 UUID
34−
35−#### `parseUUID`
36−
37−``` purescript
38−parseUUID :: forall e. String -> Maybe UUID
39−```
40−
41−Validates a String as a v4 UUID
42−
43−
package.json+4−25
@@ -1,30 +1,9 @@
11{
22 "name": "purescript-uuid",
3− "version": "1.0.0",
4− "description": "",
5− "main": "index.js",
6− "directories": {
7− "test": "test"
8− },
9− "scripts": {
10− "build": "pulp build",
11− "build:watch": "pulp -w build",
12− "test": "pulp test",
13− "test:watch": "pulp -w test"
14− },
15− "keywords": [],
16− "author": "",
17− "license": "ISC",
3+ "version": "10.0.0",
4+ "type": "module",
5+ "license": "MIT",
186 "dependencies": {
19− "uuid": "^2.0.3",
20− "uuid-validate": "0.0.2"
21− },
22− "devDependencies": {
23− "eslint": "^1.10.3",
24− "eslint-config-semistandard": "^5.0.0",
25− "eslint-config-standard": "^4.4.0",
26− "eslint-plugin-standard": "^1.3.1",
27− "pulp": "^7.0.0",
28− "purescript": "^0.7.6"
7+ "uuid": "^13.0.0"
298 }
309}
purs.jsonnew file+15
@@ -0,0 +1,15 @@
1+{
2+ "name": "uuid",
3+ "version": "9.0.0",
4+ "license": "MIT AND ISC",
5+ "location": {
6+ "githubOwner": "maddie927",
7+ "githubRepo": "purescript-uuid"
8+ },
9+ "ref": "v9.0.0",
10+ "dependencies": {
11+ "effect": ">=4.0.0 <5.0.0",
12+ "maybe": ">=6.0.0 <7.0.0",
13+ "prelude": ">=6.0.0 <7.0.0"
14+ }
15+}
spago.yamlnew file+14
@@ -0,0 +1,14 @@
1+workspace: {}
2+
3+package:
4+ name: uuid
5+ publish:
6+ version: 10.0.0
7+ license: MIT
8+ location:
9+ githubOwner: rowtype-yoga
10+ githubRepo: purescript-uuid
11+ dependencies:
12+ - effect: ">=4.0.0 <5.0.0"
13+ - maybe: ">=6.0.0 <7.0.0"
14+ - prelude: ">=6.0.0 <7.0.0"
src/Data/UUID.js+17−10
@@ -1,15 +1,22 @@
1−'use strict';
2−
31// module Data.UUID
2+import { v3, v4, v5, v7, validate, version } from "uuid";
43
5−var mkV4UUID = null;
6−exports.getUUIDImpl = function () {
7− if (mkV4UUID === null) mkV4UUID = require('uuid').v4;
8− return mkV4UUID();
4+export const getUUID3Impl = function (str) {
5+ return function (namespace) {
6+ return v3(str, namespace);
7+ };
98};
109
11−var validateV4UUID = null;
12−exports.validateV4UUID = function (str) {
13− if (validateV4UUID === null) validateV4UUID = require('uuid-validate');
14− return validateV4UUID(str, 4);
10+export const getUUIDImpl = v4;
11+
12+export const getUUID5Impl = function (str) {
13+ return function (namespace) {
14+ return v5(str, namespace);
15+ };
1516};
17+
18+export const getUUIDv7Impl = v7;
19+
20+export const validateUUID = validate;
21+
22+export const uuidVersionImpl = version;
src/Data/UUID.purs+48−20
@@ -1,38 +1,66 @@
11module Data.UUID
2− ( UUID()
3− , GENUUID()
2+ ( UUID
3+ , emptyUUID
4+ , maxUUID
45 , genUUID
6+ , genUUIDv7
57 , parseUUID
8+ , uuidVersion
9+ , genv3UUID
10+ , genv5UUID
11+ , toString
612 ) where
713
8−import Prelude (class Ord, class Eq, class Show, compare, (==), ($), pure, (<<<), (>>=))
9−import Control.Monad.Eff (Eff)
14+import Prelude
15+
1016import Data.Maybe (Maybe(Nothing, Just))
17+import Effect (Effect)
1118
1219newtype UUID = UUID String
1320
14−-- | The effect of generating a new UUID.
15−foreign import data GENUUID :: !
21+derive instance Eq UUID
22+derive instance Ord UUID
23+
24+instance Show UUID where
25+ show (UUID uuid) = "(UUID " <> uuid <> ")"
26+
27+emptyUUID :: UUID
28+emptyUUID = UUID "00000000-0000-0000-0000-000000000000"
1629
17−foreign import getUUIDImpl :: forall e. Eff (uuid :: GENUUID | e) String
30+maxUUID :: UUID
31+maxUUID = UUID "ffffffff-ffff-ffff-ffff-ffffffffffff"
1832
19−-- | Generates a v4 UUID
20−genUUID :: forall e. Eff (uuid :: GENUUID | e) UUID
33+foreign import getUUIDImpl :: Effect String
34+
35+genUUID :: Effect UUID
2136genUUID = getUUIDImpl >>= pure <<< UUID
2237
23−foreign import validateV4UUID :: String -> Boolean
38+foreign import getUUIDv7Impl :: Effect String
39+
40+genUUIDv7 :: Effect UUID
41+genUUIDv7 = getUUIDv7Impl >>= pure <<< UUID
42+
43+foreign import validateUUID :: String -> Boolean
2444
25−-- | Validates a String as a v4 UUID
2645parseUUID :: String -> Maybe UUID
27−parseUUID str = case validateV4UUID str of
28− true -> Just $ UUID str
29− _ -> Nothing
46+parseUUID str = case validateUUID str of
47+ true -> Just (UUID str)
48+ _ -> Nothing
49+
50+foreign import uuidVersionImpl :: String -> Int
51+
52+uuidVersion :: UUID -> Int
53+uuidVersion (UUID s) = uuidVersionImpl s
54+
55+foreign import getUUID3Impl :: String -> String -> String
56+
57+genv3UUID :: String -> UUID -> UUID
58+genv3UUID s (UUID n) = UUID (getUUID3Impl s n)
3059
31−instance showUUID :: Show UUID where
32− show (UUID uuid) = uuid
60+foreign import getUUID5Impl :: String -> String -> String
3361
34−instance eqUUID :: Eq UUID where
35− eq (UUID uA) (UUID uB) = uA == uB
62+genv5UUID :: String -> UUID -> UUID
63+genv5UUID s (UUID n) = UUID (getUUID5Impl s n)
3664
37−instance ordUUID :: Ord UUID where
38− compare (UUID uA) (UUID uB) = compare uA uB
65+toString :: UUID -> String
66+toString (UUID uuid) = uuid
test/Main.purs+43−20
@@ -1,32 +1,55 @@
11module Test.Main where
22
33import Prelude
4−import Control.Monad.Eff (Eff)
5−import Control.Monad.Eff.Class (liftEff)
6−import Control.Monad.Eff.Console (CONSOLE)
74import Data.Maybe (Maybe(..), fromJust)
85import Data.String (length)
9−import Data.UUID (parseUUID, genUUID, GENUUID)
10−import Node.Process (PROCESS)
6+import Data.UUID (genUUID, genv3UUID, genv5UUID, parseUUID, toString)
7+import Effect (Effect)
8+import Effect.Aff (launchAff_)
9+import Effect.Class (liftEffect)
10+import Effect.Unsafe (unsafePerformEffect)
1111import Partial.Unsafe (unsafePartial)
1212import Test.Spec (it, describe)
1313import Test.Spec.Assertions (shouldEqual)
1414import Test.Spec.Reporter.Console (consoleReporter)
15−import Test.Spec.Runner (run)
15+import Test.Spec.Runner (runSpec)
1616
17−main :: forall e. Eff (uuid :: GENUUID, console :: CONSOLE, process :: PROCESS | e) Unit
18−main = unsafePartial $ run [consoleReporter] do
19− describe "Data.UUID" do
20− it "`genUUID` returns a uuid" do
21− uuid <- liftEff genUUID
22− (length <<< show) uuid `shouldEqual` 36
17+main :: Effect Unit
18+main =
19+ launchAff_ do
20+ runSpec [ consoleReporter ] do
21+ describe "UUID" do
22+ it "`genUUID` returns a uuid" do
23+ let
24+ uuid = unsafePerformEffect genUUID
25+ (length <<< toString) uuid `shouldEqual` 36
26+ it "`genv3UUID` returns a uuid" do
27+ namespace <- liftEffect genUUID
28+ let
29+ uuid = genv3UUID "foo" namespace
30+ (length <<< toString) uuid `shouldEqual` 36
31+ it "`genv5UUID` returns a uuid" do
32+ namespace <- liftEffect genUUID
33+ let
34+ uuid = genv5UUID "foo" namespace
35+ (length <<< toString) uuid `shouldEqual` 36
36+ it "`parseUUID` parses a valid uuid as Just UUID" do
37+ let
38+ uuidStr = "d0778cf2-3a4c-42ef-acbd-1269b6bec204"
2339
24− it "`parseUUID` parses a valid uuid as Just UUID" do
25− let uuidStr = "d0778cf2-3a4c-42ef-acbd-1269b6bec204"
26− uuid = parseUUID uuidStr
27− uuidStr `shouldEqual` (show $ fromJust uuid)
40+ uuid = parseUUID uuidStr
41+ uuidStr `shouldEqual` (toString $ unsafePartial $ fromJust uuid)
42+ it "`parseUUID` parses an invalid uuid as Nothing" do
43+ let
44+ uuidStr = "foo"
2845
29− it "`parseUUID` parses an invalid uuid as Nothing" do
30− let uuidStr = "foo"
31− uuid = parseUUID uuidStr
32− Nothing `shouldEqual` uuid
46+ uuid = parseUUID uuidStr
47+ Nothing `shouldEqual` uuid
48+ it "`show` returns a console-friendly representation of the UUID type" do
49+ let
50+ uuidStr = "d0778cf2-3a4c-42ef-acbd-1269b6bec204"
51+
52+ showUUID = "(UUID d0778cf2-3a4c-42ef-acbd-1269b6bec204)"
53+
54+ uuid = parseUUID uuidStr
55+ showUUID `shouldEqual` (show $ unsafePartial $ fromJust uuid)