├── .npmrc ├── dist └── package.json ├── .gitignore ├── CHANGELOG.md ├── index.d.ts ├── .config ├── .editorconfig ├── .eslintrc.json ├── scripts ├── test └── prepublish ├── .github └── workflows │ └── test.yml ├── rollup.config.js ├── LICENSE ├── package.json ├── test └── index.js ├── CONTRIBUTING.md ├── README.md └── index.js /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /dist/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /coverage/ 2 | /dist/* 3 | /node_modules/ 4 | 5 | !/dist/package.json 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | Please refer to the [release notes](https://github.com/fluture-js/fluture-sanctuary-types/releases). 4 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'fluture-sanctuary-types' { 2 | export const env: ReadonlyArray 3 | export const FutureType: any 4 | export const ConcurrentFutureType: any 5 | } 6 | -------------------------------------------------------------------------------- /.config: -------------------------------------------------------------------------------- 1 | author-name = Aldwin Vlasblom 2 | repo-owner = fluture-js 3 | repo-name = fluture-sanctuary-types 4 | source-files = index.js 5 | module-type = esm 6 | opening-delimiter = ```js 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": ["./node_modules/sanctuary-style/eslint-es3.json"], 4 | "parserOptions": {"sourceType": "module"}, 5 | "env": {"shared-node-browser": true, "es6": true}, 6 | "overrides": [ 7 | { 8 | "files": ["README.md"], 9 | "rules": {"no-undef": ["off"]} 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /scripts/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eufo pipefail 3 | 4 | # shellcheck source=../node_modules/sanctuary-scripts/functions 5 | source "${BASH_SOURCE%/*}/../node_modules/sanctuary-scripts/functions" 6 | 7 | branches="$(get min-branch-coverage)" 8 | 9 | c8 --check-coverage \ 10 | --branches "$branches" \ 11 | --reporter lcov \ 12 | --reporter text \ 13 | oletus 14 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | 9 | jobs: 10 | test: 11 | name: Automated Tests 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout Code 15 | uses: actions/checkout@v1 16 | - name: Install NodeJS 17 | uses: actions/setup-node@v1 18 | with: 19 | node-version: 14.x 20 | - name: Install Dependencies 21 | run: npm install 22 | - name: Execute Tests 23 | run: npm test 24 | - name: Upload Coverage Report 25 | run: npm run codecov 26 | env: 27 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 28 | -------------------------------------------------------------------------------- /scripts/prepublish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eufo pipefail 3 | 4 | echo "Publishing as $(npm whoami)." 5 | 6 | if ! npm outdated --long; then 7 | read -rp "Continue? [y/N] " choice 8 | if [[ "${choice-n}" != 'y' ]]; then 9 | echo 'Package distribution aborted.' 10 | exit 2 11 | fi 12 | fi 13 | 14 | source 'node_modules/sanctuary-scripts/functions' 15 | 16 | pkg="$(get repo-name)" 17 | files=($(get source-files)) 18 | 19 | sed --in-place "s/$pkg@0.0.0/$pkg@$VERSION/" "${files[@]}" 20 | sed --in-place "s/$pkg@$PREVIOUS_VERSION/$pkg@$VERSION/" "${files[@]}" 21 | 22 | git add -- "${files[@]}" 23 | 24 | npm run build 25 | 26 | sanctuary-prepublish "$@" 27 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import pkg from './package.json'; 2 | 3 | const dependencyNames = Array.prototype.concat.call ( 4 | Object.keys (pkg.dependencies), 5 | Object.keys (pkg.peerDependencies), 6 | ['fluture/index.js'] 7 | ); 8 | 9 | export default { 10 | input: 'index.js', 11 | external: dependencyNames, 12 | output: { 13 | format: 'umd', 14 | name: 'flutureSanctuaryTypes', 15 | file: 'dist/umd.js', 16 | interop: false, 17 | exports: 'named', 18 | globals: { 19 | 'fluture/index.js': 'Fluture', 20 | 'sanctuary-def': 'sanctuaryDef', 21 | 'sanctuary-type-identifiers': 'sanctuaryTypeIdentifiers' 22 | }, 23 | paths: { 24 | 'fluture/index.js': 'fluture' 25 | } 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2021 Aldwin Vlasblom 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fluture-sanctuary-types", 3 | "version": "7.1.0", 4 | "description": "Fluture type definitions for Sanctuary", 5 | "keywords": [ 6 | "fluture", 7 | "sanctuary", 8 | "types", 9 | "typings", 10 | "future", 11 | "algebraic-data-types" 12 | ], 13 | "type": "module", 14 | "main": "./dist/umd.js", 15 | "module": "index.js", 16 | "exports": { 17 | ".": { 18 | "import": "./index.js", 19 | "require": "./dist/umd.js" 20 | }, 21 | "./index.js": "./index.js" 22 | }, 23 | "scripts": { 24 | "build": "rollup -c rollup.config.js", 25 | "codecov": "codecov", 26 | "doctest": "sanctuary-doctest", 27 | "lint": "sanctuary-lint", 28 | "release": "sanctuary-release", 29 | "test": "npm run lint && sanctuary-test && npm run doctest" 30 | }, 31 | "repository": { 32 | "type": "git", 33 | "url": "git://github.com/fluture-js/fluture-sanctuary-types.git" 34 | }, 35 | "files": [ 36 | "/dist", 37 | "/index.d.ts", 38 | "/index.js", 39 | "/LICENSE", 40 | "/package.json", 41 | "/README.md" 42 | ], 43 | "author": "Aldwin Vlasblom (https://github.com/Avaq)", 44 | "license": "MIT", 45 | "dependencies": { 46 | "sanctuary-type-identifiers": "^3.0.0" 47 | }, 48 | "peerDependencies": { 49 | "fluture": ">=12.0.0-beta.6 <15.0.0", 50 | "sanctuary-def": ">=0.20.0 <0.23.0" 51 | }, 52 | "devDependencies": { 53 | "c8": "^7.1.0", 54 | "codecov": "^3.2.0", 55 | "fluture": "^14.0.0", 56 | "oletus": "^3.0.0", 57 | "rollup": "^2.0.0", 58 | "sanctuary-def": "^0.22.0", 59 | "sanctuary-scripts": "^4.0.0", 60 | "sanctuary-show": "^2.0.0", 61 | "sanctuary-type-classes": "^12.0.0" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'assert'; 2 | import $ from 'sanctuary-def'; 3 | import show from 'sanctuary-show'; 4 | import Z from 'sanctuary-type-classes'; 5 | import type from 'sanctuary-type-identifiers'; 6 | import {Future, Par, resolve} from 'fluture'; 7 | import {FutureType, ConcurrentFutureType} from '../index.js'; 8 | import test from 'oletus'; 9 | 10 | const $test = $.test ([]); 11 | 12 | function eq(actual, expected) { 13 | assert.strictEqual (arguments.length, eq.length); 14 | assert.strictEqual (show (actual), show (expected)); 15 | assert.strictEqual (Z.equals (actual, expected), true); 16 | } 17 | 18 | test ('FutureType', () => { 19 | eq (typeof FutureType, 'function'); 20 | eq (FutureType.length, 1); 21 | eq (typeof FutureType ($.Unknown), 'function'); 22 | eq (FutureType ($.Unknown).length, 1); 23 | eq (typeof FutureType ($.Unknown) ($.Unknown), 'object'); 24 | 25 | const Type = FutureType ($.Unknown) ($.Unknown); 26 | const typeInfo = type.parse (type (Type)); 27 | 28 | eq (typeInfo.namespace, 'sanctuary-def'); 29 | eq (typeInfo.name, 'Type'); 30 | 31 | eq ($test (Type) (Future), false); 32 | eq ($test (Type) (Par (resolve (1))), false); 33 | eq ($test (Type) (resolve (1)), true); 34 | }); 35 | 36 | test ('ConcurrentFutureType', () => { 37 | eq (typeof ConcurrentFutureType, 'function'); 38 | eq (ConcurrentFutureType.length, 1); 39 | eq (typeof ConcurrentFutureType ($.Unknown), 'function'); 40 | eq (ConcurrentFutureType ($.Unknown).length, 1); 41 | eq (typeof ConcurrentFutureType ($.Unknown) ($.Unknown), 'object'); 42 | 43 | const Type = ConcurrentFutureType ($.Unknown) ($.Unknown); 44 | const typeInfo = type.parse (type (Type)); 45 | 46 | eq (typeInfo.namespace, 'sanctuary-def'); 47 | eq (typeInfo.name, 'Type'); 48 | 49 | eq ($test (Type) (Par), false); 50 | eq ($test (Type) (Par (resolve (1))), true); 51 | eq ($test (Type) (resolve (1)), false); 52 | }); 53 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guideline 2 | 3 | ## Making a contribution 4 | 5 | 1. Fork the repo if you do not have write access 6 | 1. Clone the remote (fork) from GitHub 7 | 1. Create a branch named `/` 8 | 1. Make one or more atomic commits 9 | 1. Make sure the tests pass locally 10 | 1. Create a pull request on GitHub 11 | 12 | ## Publishing a new version 13 | 14 | 1. Make sure you have write access to the module on npm 15 | 1. Make sure you have write access to the master branch on GitHub 16 | 1. Checkout `master` and make sure it's up to date with the remote 17 | 1. Run `npm run release `, where `` can be any of: 'major', 18 | 'minor', 'patch', 'premajor', 'preminor', 'prepatch', or 'prerelease'. 19 | 20 | ## Dependency Management 21 | 22 | When adding a dependency, first consider whether to add it as 23 | a *regular* or as a *peer* dependency. 24 | 25 | Make sure to update `rollup.config.js` and the usage instructions in `index.js` 26 | after installing a new dependency . Peer dependencies need to be included in the 27 | `npm install` example, and all dependencies need to be mentioned in the UMD 28 | scripting instructions. 29 | 30 | ### Regular Dependency 31 | 32 | Choose a regular dependency when its internal structure is hidden from the 33 | end-user. For example, if you depend on Fluture internally, but never expose 34 | Future instances from any of your public facing functions. 35 | 36 | The version of a regular dependency should be pinned at the major version 37 | number. For example `^1.1.0` would allow any versions greater than `1.1.0` and 38 | smaller than `2.0.0`. 39 | 40 | ### Peer Dependency 41 | 42 | Choose a peer dependency when any of its internal structure is exposed to the 43 | end-user. For example, if you depend on Fluture and return Future instances 44 | from public-facing functions, then you should add Fluture as a peer dependency. 45 | 46 | The version range of peer dependencies should be as wide as you can make it. 47 | For example, if you code works with Fluture version 1 as well as version 2, then 48 | your dependency range should be `>=1.0.0 <3.0.0`. Then whenever a new compatible 49 | version of Fluture is released, you bump the upper bound to include it. If you 50 | have to make a breaking change to support the new version of the peer dependency 51 | then you reset the lower bound. 52 | 53 | ### Package Lock 54 | 55 | We don't use a package lock file, because this is a library, not a tool. The 56 | reproducible builds provided by a package lock would benefit the developers of 57 | the library, but not its users. When users install this library, the 58 | `package.json` file is used to resolve the versions of sub-depdencies. This 59 | means that even if the developers of this library would have a working 60 | reproducible build, the library might be installing broken dependencies for its 61 | users. The trade-off we're making here is that we lose build reproducibility in 62 | development, but we gain an earlier insight in when a dependency is broken. 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fluture-sanctuary-types 2 | 3 | [Fluture][] type definitions for [Sanctuary][]. 4 | 5 | ## Usage 6 | 7 | ### Node 8 | 9 | ```console 10 | $ npm install --save fluture-sanctuary-types 11 | ``` 12 | 13 | Note that you also need [Fluture][] and [sanctuary-def][] installed. 14 | Sanctuary-def comes preinstalled with Sanctuary, so you could install 15 | either one. Fluture has to be installed separately. See `package.json` 16 | for compatible versions (defined in `peerDependencies`). 17 | 18 | On Node 12 and up, this module can be loaded directly with `import` or 19 | `require`. On Node versions below 12, `require` or the [esm][]-loader can 20 | be used. 21 | 22 | ```js 23 | import $ from 'sanctuary-def'; 24 | import sanctuary from 'sanctuary'; 25 | import {env, FutureType} from 'fluture-sanctuary-types/index.js'; 26 | import {resolve} from 'fluture/index.js'; 27 | 28 | const S = sanctuary.create ({ 29 | checkTypes: process.env.NODE_ENV !== 'production', 30 | env: sanctuary.env.concat (env) 31 | }); 32 | 33 | S.is (FutureType ($.String) ($.Number)) (resolve (42)); 34 | ``` 35 | 36 | ### Deno and Modern Browsers 37 | 38 | You can load the EcmaScript module from various content delivery networks: 39 | 40 | - [Skypack](https://cdn.skypack.dev/fluture-sanctuary-types@7.1.0) 41 | - [JSPM](https://jspm.dev/fluture-sanctuary-types@7.1.0) 42 | - [jsDelivr](https://cdn.jsdelivr.net/npm/fluture-sanctuary-types@7.1.0/+esm) 43 | 44 | ### Old Browsers and Code Pens 45 | 46 | There's a [UMD][] file included in the NPM package, also available via 47 | jsDelivr: https://cdn.jsdelivr.net/npm/fluture-sanctuary-types@7.1.0/dist/umd.js 48 | 49 | This file adds `flutureSanctuaryTypes` to the global scope, or use 50 | CommonJS/AMD when available. 51 | 52 | ```js 53 | const $ = require ('sanctuary-def'); 54 | const sanctuary = require ('sanctuary'); 55 | const {env, FutureType} = require ('fluture-sanctuary-types'); 56 | const {resolve} = require ('fluture'); 57 | 58 | const S = sanctuary.create ({ 59 | checkTypes: process.env.NODE_ENV !== 'production', 60 | env: sanctuary.env.concat (env) 61 | }); 62 | 63 | S.is (FutureType ($.String) ($.Number)) (resolve (42)); 64 | ``` 65 | 66 | #### `FutureType :: Type -⁠> Type -⁠> Type` 67 | 68 | The binary type constructor for members of Future. 69 | 70 | ```js 71 | > $.test (env) 72 | . (FutureType ($.String) ($.Number)) 73 | . (Future['fantasy-land/of'] (1)); 74 | true 75 | ``` 76 | 77 | #### `ConcurrentFutureType :: Type -⁠> Type -⁠> Type` 78 | 79 | The binary type constructor for members of ConcurrentFuture. 80 | 81 | ```js 82 | > $.test (env) 83 | . (ConcurrentFutureType ($.String) ($.Number)) 84 | . (Par['fantasy-land/of'] (1)); 85 | true 86 | ``` 87 | 88 | #### `env :: Array Type` 89 | 90 | An Array containing all types applied to [`$.Unknown`][Unknown] for 91 | direct use as a Sanctuary environment, as shown in [Usage](#usage). 92 | 93 | [Fluture]: https://github.com/fluture-js/Fluture 94 | [Sanctuary]: https://sanctuary.js.org/ 95 | [sanctuary-def]: https://github.com/sanctuary-js/sanctuary-def 96 | [Unknown]: https://github.com/sanctuary-js/sanctuary-def#Unknown 97 | [esm]: https://github.com/standard-things/esm 98 | [UMD]: https://github.com/umdjs/umd 99 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | //. # fluture-sanctuary-types 2 | //. 3 | //. [Fluture][] type definitions for [Sanctuary][]. 4 | //. 5 | //. ## Usage 6 | //. 7 | //. ### Node 8 | //. 9 | //. ```console 10 | //. $ npm install --save fluture-sanctuary-types 11 | //. ``` 12 | //. 13 | //. Note that you also need [Fluture][] and [sanctuary-def][] installed. 14 | //. Sanctuary-def comes preinstalled with Sanctuary, so you could install 15 | //. either one. Fluture has to be installed separately. See `package.json` 16 | //. for compatible versions (defined in `peerDependencies`). 17 | //. 18 | //. On Node 12 and up, this module can be loaded directly with `import` or 19 | //. `require`. On Node versions below 12, `require` or the [esm][]-loader can 20 | //. be used. 21 | //. 22 | //. ```js 23 | //. import $ from 'sanctuary-def'; 24 | //. import sanctuary from 'sanctuary'; 25 | //. import {env, FutureType} from 'fluture-sanctuary-types/index.js'; 26 | //. import {resolve} from 'fluture/index.js'; 27 | //. 28 | //. const S = sanctuary.create ({ 29 | //. checkTypes: process.env.NODE_ENV !== 'production', 30 | //. env: sanctuary.env.concat (env) 31 | //. }); 32 | //. 33 | //. S.is (FutureType ($.String) ($.Number)) (resolve (42)); 34 | //. ``` 35 | //. 36 | //. ### Deno and Modern Browsers 37 | //. 38 | //. You can load the EcmaScript module from various content delivery networks: 39 | //. 40 | //. - [Skypack](https://cdn.skypack.dev/fluture-sanctuary-types@7.1.0) 41 | //. - [JSPM](https://jspm.dev/fluture-sanctuary-types@7.1.0) 42 | //. - [jsDelivr](https://cdn.jsdelivr.net/npm/fluture-sanctuary-types@7.1.0/+esm) 43 | //. 44 | //. ### Old Browsers and Code Pens 45 | //. 46 | //. There's a [UMD][] file included in the NPM package, also available via 47 | //. jsDelivr: https://cdn.jsdelivr.net/npm/fluture-sanctuary-types@7.1.0/dist/umd.js 48 | //. 49 | //. This file adds `flutureSanctuaryTypes` to the global scope, or use 50 | //. CommonJS/AMD when available. 51 | //. 52 | //. ```js 53 | //. const $ = require ('sanctuary-def'); 54 | //. const sanctuary = require ('sanctuary'); 55 | //. const {env, FutureType} = require ('fluture-sanctuary-types'); 56 | //. const {resolve} = require ('fluture'); 57 | //. 58 | //. const S = sanctuary.create ({ 59 | //. checkTypes: process.env.NODE_ENV !== 'production', 60 | //. env: sanctuary.env.concat (env) 61 | //. }); 62 | //. 63 | //. S.is (FutureType ($.String) ($.Number)) (resolve (42)); 64 | //. ``` 65 | 66 | import $ from 'sanctuary-def'; 67 | import type from 'sanctuary-type-identifiers'; 68 | import { 69 | Future, 70 | isFuture, 71 | extractLeft, 72 | extractRight, 73 | Par, 74 | seq 75 | } from 'fluture/index.js'; 76 | 77 | // $$type :: String 78 | var $$type = '@@type'; 79 | 80 | //# FutureType :: Type -> Type -> Type 81 | //. 82 | //. The binary type constructor for members of Future. 83 | //. 84 | //. ```js 85 | //. > $.test (env) 86 | //. . (FutureType ($.String) ($.Number)) 87 | //. . (Future['fantasy-land/of'] (1)); 88 | //. true 89 | //. ``` 90 | export var FutureType = $.BinaryType 91 | (type.parse (Future[$$type]).name) 92 | ('https://github.com/fluture-js/Fluture#readme') 93 | ([]) 94 | (isFuture) 95 | (extractLeft) 96 | (extractRight); 97 | 98 | //# ConcurrentFutureType :: Type -> Type -> Type 99 | //. 100 | //. The binary type constructor for members of ConcurrentFuture. 101 | //. 102 | //. ```js 103 | //. > $.test (env) 104 | //. . (ConcurrentFutureType ($.String) ($.Number)) 105 | //. . (Par['fantasy-land/of'] (1)); 106 | //. true 107 | //. ``` 108 | export var ConcurrentFutureType = $.BinaryType 109 | (type.parse (Par[$$type]).name) 110 | ('https://github.com/fluture-js/Fluture#concurrentfuture') 111 | ([]) 112 | (function(x) { return type (x) === Par[$$type] && x !== Par; }) 113 | (function(f) { return (seq (f)).extractLeft (); }) 114 | (function(f) { return (seq (f)).extractRight (); }); 115 | 116 | //# env :: Array Type 117 | //. 118 | //. An Array containing all types applied to [`$.Unknown`][Unknown] for 119 | //. direct use as a Sanctuary environment, as shown in [Usage](#usage). 120 | export var env = [ 121 | FutureType ($.Unknown) ($.Unknown), 122 | ConcurrentFutureType ($.Unknown) ($.Unknown) 123 | ]; 124 | 125 | //. [Fluture]: https://github.com/fluture-js/Fluture 126 | //. [Sanctuary]: https://sanctuary.js.org/ 127 | //. [sanctuary-def]: https://github.com/sanctuary-js/sanctuary-def 128 | //. [Unknown]: https://github.com/sanctuary-js/sanctuary-def#Unknown 129 | //. [esm]: https://github.com/standard-things/esm 130 | //. [UMD]: https://github.com/umdjs/umd 131 | --------------------------------------------------------------------------------