Skip to content

Commit

Permalink
Merge pull request #1 from magda-io/esm-release
Browse files Browse the repository at this point in the history
Esm release
  • Loading branch information
t83714 authored Dec 21, 2023
2 parents 5bcdb39 + f70ff77 commit 5e67a6c
Show file tree
Hide file tree
Showing 23 changed files with 1,458 additions and 2,041 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Main CI Workflow

on: push

jobs:
build-test:
name: Build, Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- run: yarn install
- run: yarn test
30 changes: 30 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
release:
types: [published]

env:
REPO_NAME: magda-auth-oidc

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- run: yarn install
- run: yarn build
- run: yarn test

- name: publish NPM package
run: |
npm config set @magda:registry https://registry.npmjs.org/
npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
npm publish --access public
45 changes: 45 additions & 0 deletions .github/workflows/set-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: set-version

run-name: Set version ${{ inputs.version }} on ${{ github.ref_name }}

on:
workflow_dispatch:
inputs:
version:
description: "Please input the new version number. e.g. `v2.0.0-alpha.0` with leading `v`"
required: true
type: string

jobs:
log-the-inputs:
runs-on: ubuntu-latest
steps:
- name: Version validation
env:
SELECTED_VERSION: ${{ inputs.version }}
run: |
SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
[[ "${SELECTED_VERSION}" =~ $SEMVER_REGEX ]] || { echo "Invalid version number '$SELECTED_VERSION'. Should be e.g. 'v2.0.0-alpha.0' with leading 'v'." ; exit 1; }
- uses: actions/checkout@v3

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Utilities
run: yarn install

- name: Setup Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Set version
env:
SELECTED_VERSION: ${{ inputs.version }}
run: |
VERSION_NUM=$(echo ${SELECTED_VERSION} | cut -b 2-)
yarn version --new-version ${VERSION_NUM}
git push
7 changes: 3 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Gruntfile.js
tsd.json
typings/
test/
src
dist/test
tsconfig.json
82 changes: 38 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
{
"name": "tsmonad",
"version": "0.8.0",
"description": "TsMonad - fun-size monads library for TypeScript",
"main": "./dist/tsmonad.js",
"typings": "./lib/src/index",
"files": [
"dist",
"lib/src/*.d.ts",
"LICENSE-MIT",
"README.md"
],
"directories": {},
"scripts": {
"clean": "rm -rf dist lib",
"prebuild": "npm run test",
"build": "webpack lib/src/index.js dist/tsmonad.js -p --devtool source-map --output-library-target umd",
"pretest": "npm run clean && tsc",
"prepublish": "npm run build",
"test": "mocha lib/test"
},
"repository": {
"type": "git",
"url": "https://github.com/cbowdon/TsMonad.git"
},
"keywords": [
"typescript",
"monad",
"functional"
],
"author": {
"name": "Chris Bowdon",
"url": "https://github.com/cbowdon"
},
"license": "MIT",
"devDependencies": {
"@types/mocha": "^2.2.40",
"@types/node": "^7.0.12",
"@types/underscore": "^1.8.0",
"assert": "^1.4.1",
"mocha": "^2.5.3",
"typescript": "2.2.2",
"underscore": "^1.8.3",
"webpack": "^1.13.1"
}
"name": "@magda/tsmonad",
"version": "0.9.0",
"description": "TsMonad - fun-size monads library for TypeScript",
"type": "module",
"exports": {
"import": "./dist/index.js"
},
"typings": "./dist/index.d.ts",
"directories": {},
"scripts": {
"clean": "rm -rf dist",
"build": "yarn clean && tsc -b",
"pretest": "yarn build",
"test": "mocha dist/test"
},
"repository": {
"type": "git",
"url": "https://github.com/magda-io/TsMonad.git"
},
"keywords": [
"typescript",
"monad",
"functional"
],
"author": {
"name": "Chris Bowdon",
"url": "https://github.com/cbowdon"
},
"license": "MIT",
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/node": "^18.11.9",
"@types/underscore": "^1.8.0",
"assert": "^2.1.0",
"mocha": "^10.2.0",
"typescript": "5.3.3",
"underscore": "^1.13.6"
}
}
67 changes: 32 additions & 35 deletions src/either.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Monad, Functor, Eq, eq } from './monad'
import { Monad, Functor, Eq, eq } from "./monad.js";

/**
* @name EitherType
* @description Enumerate the different types contained by an Either object.
*/
export enum EitherType { Left, Right }
export enum EitherType {
Left,
Right,
}

/**
* @name EitherPatterns
* @description Define a contract to unwrap Either object using callbacks
* for Left and Right.
* @see Either#
*/
export interface EitherPatterns<L,R,T> {
export interface EitherPatterns<L, R, T> {
/**
* @name left
* @description Function to handle the Left.
Expand All @@ -29,7 +32,7 @@ export interface EitherPatterns<L,R,T> {
}

// ditto, but optional
export type OptionalEitherPatterns<L,R,T> = Partial<EitherPatterns<L,R,T>>
export type OptionalEitherPatterns<L, R, T> = Partial<EitherPatterns<L, R, T>>;

function exists<T>(t: T) {
return t !== null && t !== undefined;
Expand All @@ -46,18 +49,18 @@ function exists<T>(t: T) {
* parameter.
* @see Either#
*/
export function either<L,R>(l?: L, r?: R) {
export function either<L, R>(l?: L, r?: R) {
if (exists(l) && exists(r)) {
throw new TypeError('Cannot construct an Either with both a left and a right');
throw new TypeError("Cannot construct an Either with both a left and a right");
}
if (!exists(l) && !exists(r)) {
throw new TypeError('Cannot construct an Either with neither a left nor a right');
throw new TypeError("Cannot construct an Either with neither a left nor a right");
}
if (exists(l) && !exists(r)) {
return Either.left<L,R>(l);
return Either.left<L, R>(l);
}
if (!exists(l) && exists(r)) {
return Either.right<L,R>(r);
return Either.right<L, R>(r);
}
}

Expand All @@ -69,8 +72,7 @@ export function either<L,R>(l?: L, r?: R) {
* convention, the Left constructor is used to hold an error value and
* the Right constructor is used to hold a correct value.
*/
export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {

export class Either<L, R> implements Monad<R>, Functor<R>, Eq<Either<L, R>> {
/**
* @description Build an Either object. For internal use only.
* @constructor
Expand All @@ -79,9 +81,7 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* @param {L} l The Left value (optional).
* @param {R} l The Right value (optional).
*/
constructor(private type: EitherType,
private l?: L,
private r?: R) {}
constructor(private type: EitherType, private l?: L, private r?: R) {}

/**
* @name left
Expand All @@ -91,20 +91,20 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* @param {L} l The Left value.
* @returns {Either<L, R>} Either object containing a Left.
*/
static left<L,R>(l: L) {
return new Either<L,R>(EitherType.Left, l);
static left<L, R>(l: L) {
return new Either<L, R>(EitherType.Left, l);
}

/**
/**
* @name right
* @description Helper function to build an Either with a Right.
* @methodOf Either#
* @static
* @param {R} r The Right value.
* @returns {Either<L, R>} Either object containing a Right.
*/
static right<L,R>(r: R) {
return new Either<L,R>(EitherType.Right, null, r);
static right<L, R>(r: R) {
return new Either<L, R>(EitherType.Right, null, r);
}

/**
Expand All @@ -118,7 +118,7 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* a left.
*/
isLeft() {
return this.caseOf({left: () => true, right: () => false});
return this.caseOf({ left: () => true, right: () => false });
}

/**
Expand All @@ -132,7 +132,7 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* a right.
*/
isRight() {
return this.caseOf({left: () => false, right: () => true});
return this.caseOf({ left: () => false, right: () => true });
}

/**
Expand All @@ -145,7 +145,7 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* @see Monad#unit
*/
unit<T>(t: T) {
return Either.right<L,T>(t);
return Either.right<L, T>(t);
}

/**
Expand All @@ -158,10 +158,8 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* an Either object.
* @see Monad#bind
*/
bind<T>(f: (r: R) => Either<L,T>) {
return this.type === EitherType.Right ?
f(this.r) :
Either.left<L,T>(this.l);
bind<T>(f: (r: R) => Either<L, T>) {
return this.type === EitherType.Right ? f(this.r) : Either.left<L, T>(this.l);
}

/**
Expand Down Expand Up @@ -195,7 +193,7 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* @see Functor#fmap
*/
fmap<T>(f: (r: R) => T) {
return this.bind(v => this.unit<T>(f(v)));
return this.bind((v) => this.unit<T>(f(v)));
}

/**
Expand Down Expand Up @@ -230,10 +228,8 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* EitherPatterns interface.
* @see EitherPatterns#
*/
caseOf<T>(pattern: EitherPatterns<L,R,T>) {
return this.type === EitherType.Right ?
pattern.right(this.r) :
pattern.left(this.l);
caseOf<T>(pattern: EitherPatterns<L, R, T>) {
return this.type === EitherType.Right ? pattern.right(this.r) : pattern.left(this.l);
}

/**
Expand All @@ -247,10 +243,12 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
* false otherwise.
* @see Eq#equals
*/
equals(other: Either<L,R>) {
return other.type === this.type &&
equals(other: Either<L, R>) {
return (
other.type === this.type &&
((this.type === EitherType.Left && eq(other.l, this.l)) ||
(this.type === EitherType.Right && eq(other.r, this.r)));
(this.type === EitherType.Right && eq(other.r, this.r)))
);
}

/**
Expand All @@ -274,4 +272,3 @@ export class Either<L,R> implements Monad<R>, Functor<R>, Eq<Either<L,R>> {
return this;
}
}

8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @namespace Hold functionalities related to TsMonad library.
*/

export * from './either'
export * from './maybe'
export * from './monad'
export * from './writer'
export * from "./either.js";
export * from "./maybe.js";
export * from "./monad.js";
export * from "./writer.js";
Loading

0 comments on commit 5e67a6c

Please sign in to comment.