Skip to content

Commit

Permalink
started unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fed135 committed May 3, 2018
1 parent 012e3b6 commit 8cdf508
Show file tree
Hide file tree
Showing 18 changed files with 760 additions and 313 deletions.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/src/app/system/console/colors.package.js~
/package.json~
/docs/RULES.md~
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Compiled api docs
api_docs
/log.txt
/bin
/stacks.out
/out
yarn-error.log
NTH

docs
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests
README.md
.travis.yml
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "10"
- "8"
- "6"
install:
- npm ci
script:
- npm test
- npm run bench
sudo: false
73 changes: 73 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Contribute

Please contribute! Here are some things that would be great:
- Open an issue!
- Open a pull request!
- Say hi! :wave:

Please abide by the [code of conduct](CODE_OF_CONDUCT.md).
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2018 Frederic Charette

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
101 changes: 96 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
# REST-store
<h1 align="center">
<a title="The resource Manager" href="http://kalm.js.org">
<img alt="Kalm" width="320px" src="http://res.cloudinary.com/kalm/image/upload/v1487202241/kalm_header.png" />
<br/><br/>
</a>
REST-store
</h1>
<h3 align="center">
The resource Manager
<br/><br/><br/>
</h3>
<br/>

[![rest-store](https://img.shields.io/npm/v/rest-store.svg)](https://www.npmjs.com/package/rest-store)
[![Node](https://img.shields.io/badge/node->%3D8.0-blue.svg)](https://nodejs.org)
[![Build Status](https://travis-ci.org/fed135/rest-store.svg?branch=master)](https://travis-ci.org/fed135/rest-store.js)
[![Dependencies Status](https://david-dm.org/fed135/rest-store.js.svg)](https://david-dm.org/fed135/rest-store.js)

---

## How it works

Want to make your app faster and don't want to spend on extra infrastructure ?

**REST-store** is:

An in-memory, self-adjustting cache:
An in-memory, self-adjustting microcache:

- Helps reduce the number of requests for 'hot' information
- No noticeable footprint
- No need for extra caching architecture (redis/memcache)

With request dedupping, batching, retrying and circuit-breaking:
Adds request dedupping, batching, retrying and circuit-breaking:

- Process-wide request profiling and mapping
- Greatly reduces the number of requests
Expand All @@ -30,15 +50,86 @@ With request dedupping, batching, retrying and circuit-breaking:

## Usage

**Data-Access layer**

```node
function getItems(ids, params) {
// Some compute-heavy async function or external request to a DB / service
}
```

**Store**
```node
const store = require('rest-store');
const itemStore = store({ getter: { method: getItems }});
```

**Model**
```node
function getItemById(id, params) {
itemStore.one(id, params)
.then(item => /* The item you requested */);
}
```

## Options

Name | Required | Default | Description
--- | --- | --- |
getter | true | - | The method to wrap, and how to interpret the returned data. Uses the format `<object>{ method: <function(ids, params)>, responseParser: <function(response, requestedIds)>`
uniqueOptions | false | `[]` | The list of parameters that, when passed, alter the results of the items requested. Ex: 'language', 'view', 'fields', 'country'. These will generate different combinaisons of cache keys.
cache | false | ```{
enabled: true,
step: 1000,
ttl: 10000,
}``` | Caching options for the data
batch | false | ```{
enabled: false,
tick: 40,
limit: 100,
}``` | Batching options for the requests
retry | false | ```{
enabled: true,
max: 3,
scale: {
mult: 2.5,
base: 5,
}
}``` | Retry options for the requests


## Monitoring and events

REST-store emits events to track cache hits, miss and outbound requests.

Event | Description
--- | ---
cacheHit | When the requested item is present in the microcache, or is already being fetched. Prevents another request from being created.
cacheMiss | When the requested item is not present in the microcache and is not currently being fetched. A new request will be made.
batch | When a batch of requests is about to be sent.
batchFailed | Indicates that the batch has failed. Retry policy will dictate if it should be re-attempted.
batchCancelled | Indicates that the batch has reached the allowed number of retries and is now abandonning.
batchSuccess | Indicates that the batch request was successful.
bumpCache | When a call for an item fully loaded in the microcache succeeds, it's ttl gets extended.
clearCache | When an item in the microcache has reached it's ttl and is now being evicted.

## Testing

`npm test`

## Contributing
## References

[White paper - Microcaching]()

## Contribute

Please do! This is an open source project - if you see something that you want, [open an issue](//github.com/kalm/kalm.js/issues/new) or file a pull request.

If you have a major change, it would be better to open an issue first so that we can talk about it.

I am always looking for more maintainers, as well. Get involved.

## License

## License
[Apache 2.0](LICENSE) (c) 2017 Frederic Charette

Loading

0 comments on commit 8cdf508

Please sign in to comment.