Skip to content

Commit

Permalink
Implement memoize (#2)
Browse files Browse the repository at this point in the history
* implement memoize

* prettier fix

* update readme with better example

* addressing pr comments

- change copyright to 2023
- adjust read me description
- add run tests back into ci workflows
- import memoize from index.ts for test file

* change npm run ci:test to npm test in publish.yml

* change node engine to >=18

* remove Check Digit specific comments and fix example in read me

+ update workflows
  • Loading branch information
greg-w101 authored Jun 22, 2023
1 parent 17c6c0d commit 9366f80
Show file tree
Hide file tree
Showing 20 changed files with 2,978 additions and 1,550 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/check-pr-reviews.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check Pull Request Reviews

on:
pull_request_review:
types: [submitted]

jobs:
checkPrReviews:
runs-on: ubuntu-latest
name: Check PR Reviews
strategy:
matrix:
node-version: [18.x]
steps:
- name: Perform Check of PR Reviews
uses: checkdigit/github-actions/check-pr-reviews@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -24,7 +24,7 @@ jobs:
cache: 'npm'
- name: Check Imports
uses: checkdigit/github-actions/check-imports@main
- name: Install Dependencies
- name: Install dependencies
run: npm ci --ignore-scripts
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand All @@ -46,7 +46,7 @@ jobs:
name: Branch Build
strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -58,7 +58,7 @@ jobs:
cache: 'npm'
- name: Check Imports
uses: checkdigit/github-actions/check-imports@main
- name: Install Dependencies
- name: Install dependencies
run: npm ci --ignore-scripts
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'CodeQL'

on:
push:
branches: ['main']
pull_request:
branches: ['main']
schedule:
- cron: '56 08 * * 1'

jobs:
analyze:
name: CodeQL analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ['javascript']
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
10 changes: 3 additions & 7 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ env:
CI: true

jobs:
branchBuild:
coverage:
runs-on: ubuntu-latest
name: Branch Build
name: Coverage
strategy:
matrix:
node-version: [18.x]
Expand All @@ -24,10 +24,8 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install Dependencies
- name: Install dependencies
run: npm ci --ignore-scripts
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Calculate Code Coverage
run: npm run ci:coverage
- name: Create Coverage Report for base branch
Expand All @@ -36,8 +34,6 @@ jobs:
git fetch
git checkout origin/${{ github.event.pull_request.base.ref }}
npm ci --ignore-scripts && npm run ci:coverage
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Post Coverage Report
uses: checkdigit/github-actions/coverage-reporter@main
with:
Expand Down
30 changes: 19 additions & 11 deletions .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ on:
- 'main'

jobs:
comment:
publishBeta:
runs-on: ubuntu-latest
name: Publish Beta
strategy:
matrix:
node-version: [18.x]
Expand All @@ -19,16 +20,23 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install Dependencies
run: npm ci
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
CI: true
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Audit Signatures
run: npm audit signatures
- name: Run Test
run: npm run ci:test
- name: Publish Beta Package
uses: checkdigit/github-actions/publish-beta@main
- name: Prepare Beta
id: prepare-beta
uses: checkdigit/github-actions/prepare-beta@main
- name: Publish Beta
run: npm publish --tag beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }}
- name: Comment npm publish result
uses: checkdigit/github-actions/comment-npm-publish@main
with:
betaPackage: ${{ steps.prepare-beta.outputs.betaPackage }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish

on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
name: Publish to NPM
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Audit Signatures
run: npm audit signatures
- name: Run Test
run: npm run ci:test
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ coverage
# Build directory
build

# Dist directories
dist-*

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
Expand Down
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

8 changes: 0 additions & 8 deletions LICENSE

This file was deleted.

22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License

Copyright (c) 2023 Check Digit, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
38 changes: 15 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
# Check Digit < Insert name > Library
# Memoize

The Check Digit < Insert Name > library is a library for Check Digit services to deal with [ short description about what the library does]
Copyright (c) 2023 [Check Digit, LLC](https://checkdigit.com)

Features:
Memoize is a small async function for memoizing promises with cache eviction on reject.
The promise being cached guarantees the underlying function is called at most once for a given set of arguments, unless
the promise is rejected. If the promise is rejected, it will be removed from the memoize cache.
This allows the function to be retried.

- Feature 1
- Feature 2
- Feature3
- (...)

### Installing

`npm install @checkdigit/< Insert name >`

### Use

It could be. i.e.
### Install

```
import * as insertName from '@checkdigit/< Insert name >';
$ npm install @checkdigit/memoize
```

const someVariable = insertName();
### Use

```
import memoize from '@checkdigit/memoize';
Or if it can be called as a script. i.e.
const promise = memoize((_param: _paramType) => _asyncFunction(_param));
```
insert-name -b src/package.json
const value = await promise(_paramValue);
```

### Links
## License

- Company website: [your.website.url]
- Npm: [npm.url]
MIT
13 changes: 13 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Security Policy

## Supported Versions

These versions of @checkdigit/memoize are currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| > 1.x | :white_check_mark: |

## Reporting a Vulnerability

Please create an issue at https://github.com/checkdigit/memoize/issues
Loading

0 comments on commit 9366f80

Please sign in to comment.