Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from data-provider/v1.4.0
Browse files Browse the repository at this point in the history
V1.4.0
  • Loading branch information
javierbrea authored Nov 23, 2019
2 parents b8e85c3 + e4764f2 commit 046d184
Show file tree
Hide file tree
Showing 39 changed files with 699 additions and 173 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ cache:

addons:
sonarcloud:
organization: "javierbrea"
token:
secure: "$SONAR_TOKEN"
organization: "data-provider"
branch:
name: "$TRAVIS_CURRENT_BRANCH"

Expand All @@ -21,11 +19,11 @@ script:
- npm run test:mocks
- npm run build
- npm run coveralls
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sonar-scanner; fi'
- 'if [ -n "$SONAR_TOKEN" ]; then sonar-scanner -Dsonar.login=${SONAR_TOKEN}; fi'

deploy:
provider: npm
email: "devops@xbyorange.com"
email: "javier.brea@gmail.com"
api_key: "$NPM_TOKEN"
on:
tags: true
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [TO BE DEPRECATED]
- apis "config" and "clean" methods. Mercury "sources" methods should be used instead.

## [1.4.0] - 2019-11-23
### Changed
- Project migration. Read NOTICE for further info. All previous releases in this CHANGELOG file correspond to @xbyorange/mercury-api package distribution.

## [1.3.0] - 2019-10-18
### Changed
Expand Down
13 changes: 1 addition & 12 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,5 @@

END OF TERMS AND CONDITIONS

Copyright 2019 Javier Brea
Copyright 2019 XbyOrange

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.
6 changes: 6 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data-provider axios
Copyright 2019 Javier Brea

Portions of this software were developed at XbyOrange company.
Forked from XByOrange Mercury Api v1.3.0, distributed under The Apache Software License, Version 2.0.
Github repository "xbyorange/mercury-api" (https://github.com/XbyOrange/mercury-api), branch master, commit b8e85c3be116fb3e727ef5337d455a0f95177d8d. The original project files were wrongly licensed because an error of the main maintainer, Javier Brea, who received instructions from the XbyOrange company about licensing it as Apache2.0, but didn't include the appropiate license header in all repository files by error. The error has been fixed and XbyOrange license headers have been added to all original files, as it was the real intention of the XbyOrange company.
70 changes: 34 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@

[![NPM downloads][npm-downloads-image]][npm-downloads-url] [![License][license-image]][license-url]

# ![Mercury Logo](assets/logos/mercury_wings_orange_100.png) Mercury Api

## Overview

This package provides a Mercury Api origin.
This package provides an Api [Data Provider][data-provider-url] using Axios.

* __Mercury queries__ based on query strings and url parameters.
* __Data Provider queries__ based on query strings and url parameters.
* __Built-in cache__. Different caches are provided for different queryStrings and url parameters.
* __Reactivity__ to CRUD actions. When a "create", "update" or "delete" method is called over an instance, the instance cache is cleaned.

## Api

`import { Api } from "@xbyorange/mercury-api"`
`import { Api } from "@data-provider/axios"`

`new Api(url, options)`
* Arguments
* url - _`<String>`_. Api url. Parameters can be defined using ":parameterName". Please refer to the [path-to-regexp][path-to-regex-url] package for further info.
* options - _`<Object>`_ Containing options:
* tags - _`<String or Array of Strings>`_ - The api instance is added to correspondant groups using these tags. Afterwards, configuration, headers, etc. can be changed for certain groups using the [`sources` object methods described in the mercury docs][mercury-sources-docs-url], or the `api` object methods described below. The "api" tag is added automatically to all Api instances.
* tags - _`<String or Array of Strings>`_ - The api instance is added to correspondant groups using these tags. Afterwards, configuration, headers, etc. can be changed for certain groups using the [`sources` object methods described in the Data Provider docs][data-provider-sources-docs-url], or the `api` object methods described below. The "api" tag is added automatically to all Api instances.
* baseUrl - _`<String>`_ - Added as prefix to all requests.
* createMethod - _`<String>`_ - HTTP method to be used in axios requests for `create` method.
* readMethod - _`<String>`_ - HTTP method to be used in axios requests for `read` method.
Expand Down Expand Up @@ -121,14 +119,14 @@ If no tags are provided when invoking methods, they will be applied to all api i

> An [example of multiple configuration](docs/apis-config.md) is available in the docs.
`import { apis } from "@xbyorange/mercury-api"`
`import { apis } from "@data-provider/axios"`

### clean cache

Use the ["mercury" `sources` method][mercury-sources-docs-url] for cleaning many instances at a time. Use the "api" tag to clean all "mercury-api" instances:
Use the ["Data Provider" `sources` method][data-provider-sources-docs-url] for cleaning many instances at a time. Use the "api" tag to clean all "@data-provider/axios" instances:

```js
import { sources } from "@xbyorange/mercury";
import { sources } from "@data-provider/core";

sources.getByTag("api").clean();
```
Expand Down Expand Up @@ -161,10 +159,10 @@ apis.addHeaders({ Authorization: `Bearer ${token}` }, ["need-auth"]);

### config

Use the ["mercury" `sources` method][mercury-sources-docs-url] for configuring many instances at a time. Use the "api" tag to configure all "mercury-api" instances:
Use the ["Data Provider" `sources` method][data-provider-sources-docs-url] for configuring many instances at a time. Use the "api" tag to configure all "@data-provider/axios" instances:

```js
import { sources } from "@xbyorange/mercury";
import { sources } from "@data-provider/core";

sources.getByTag("api").config({
retries: 0
Expand All @@ -173,11 +171,11 @@ sources.getByTag("api").config({

## Examples

Next example will be easier to understand if you are already familiarized with the [mercury][mercury-url] syntax.
Next example will be easier to understand if you are already familiarized with the [Data Provider][data-provider-url] syntax.

```js
import { Selector } from "@xbyorange/mercury";
import { Api } from "@xbyorange/mercury-api";
import { Selector } from "@data-provider/core";
import { Api } from "@data-provider/axios";

const booksCollection = new Api("http://api.library.com/books");
const authorsCollection = new Api("http://api.library.com/authors");
Expand Down Expand Up @@ -225,7 +223,7 @@ await booksWithAuthors.query("George Orwell");

### More examples

The [mercury][mercury-url] library uses this origin in his examples, so you can refer to the [library documentation][mercury-url] to found more examples.
The [Data Provider][data-provider-url] library uses this origin in his examples, so you can refer to the [library documentation][data-provider-url] to found more examples.

Specific api origin examples:

Expand All @@ -237,34 +235,34 @@ Specific api origin examples:

### React

Please refer to the [react-mercury][react-mercury-url] documentation to see how simple is the data-binding between React Components and mercury-api.
Please refer to the [@data-provider/connector-react][data-provider-connector-react-url] documentation to see how simple is the data-binding between React Components and @data-provider/axios.

Connect a source to all components that need it. Mercury will fetch data only when needed, and will avoid making it more than once, no matter how many components need the data.
Connect a source to all components that need it. Data Provider will fetch data only when needed, and will avoid making it more than once, no matter how many components need the data.

## Contributing

Contributors are welcome.
Please read the [contributing guidelines](.github/CONTRIBUTING.md) and [code of conduct](.github/CODE_OF_CONDUCT.md).

[mercury-url]: https://github.com/xbyorange/mercury
[react-mercury-url]: https://github.com/xbyorange/react-mercury
[mercury-sources-docs-url]: https://github.com/XbyOrange/mercury/blob/master/docs/sources/api.md
[data-provider-url]: https://github.com/data-provider/core
[data-provider-connector-react-url]: https://github.com/data-provider/connector-react
[data-provider-sources-docs-url]: https://github.com/data-provider/core/blob/master/docs/sources/api.md
[path-to-regex-url]: https://www.npmjs.com/package/path-to-regexp

[coveralls-image]: https://coveralls.io/repos/github/XbyOrange/mercury-api/badge.svg
[coveralls-url]: https://coveralls.io/github/XbyOrange/mercury-api
[travisci-image]: https://travis-ci.com/xbyorange/mercury-api.svg?branch=master
[travisci-url]: https://travis-ci.com/xbyorange/mercury-api
[last-commit-image]: https://img.shields.io/github/last-commit/xbyorange/mercury-api.svg
[last-commit-url]: https://github.com/xbyorange/mercury-api/commits
[license-image]: https://img.shields.io/npm/l/@xbyorange/mercury-api.svg
[license-url]: https://github.com/xbyorange/mercury-api/blob/master/LICENSE
[npm-downloads-image]: https://img.shields.io/npm/dm/@xbyorange/mercury-api.svg
[npm-downloads-url]: https://www.npmjs.com/package/@xbyorange/mercury-api
[npm-dependencies-image]: https://img.shields.io/david/xbyorange/mercury-api.svg
[npm-dependencies-url]: https://david-dm.org/xbyorange/mercury-api
[quality-gate-image]: https://sonarcloud.io/api/project_badges/measure?project=xbyorange-mercury-api&metric=alert_status
[quality-gate-url]: https://sonarcloud.io/dashboard?id=xbyorange-mercury-api
[release-image]: https://img.shields.io/github/release-date/xbyorange/mercury-api.svg
[release-url]: https://github.com/xbyorange/mercury-api/releases
[coveralls-image]: https://coveralls.io/repos/github/data-provider/axios/badge.svg
[coveralls-url]: https://coveralls.io/github/data-provider/axios
[travisci-image]: https://travis-ci.com/data-provider/axios.svg?branch=master
[travisci-url]: https://travis-ci.com/data-provider/axios
[last-commit-image]: https://img.shields.io/github/last-commit/data-provider/axios.svg
[last-commit-url]: https://github.com/data-provider/axios/commits
[license-image]: https://img.shields.io/npm/l/@data-provider/axios.svg
[license-url]: https://github.com/data-provider/axios/blob/master/LICENSE
[npm-downloads-image]: https://img.shields.io/npm/dm/@data-provider/axios.svg
[npm-downloads-url]: https://www.npmjs.com/package/@data-provider/axios
[npm-dependencies-image]: https://img.shields.io/david/data-provider/axios.svg
[npm-dependencies-url]: https://david-dm.org/data-provider/axios
[quality-gate-image]: https://sonarcloud.io/api/project_badges/measure?project=data-provider-axios&metric=alert_status
[quality-gate-url]: https://sonarcloud.io/dashboard?id=data-provider-axios
[release-image]: https://img.shields.io/github/release-date/data-provider/axios.svg
[release-url]: https://github.com/data-provider/axios/releases

Binary file removed assets/logos/mercury_wings_orange_100.png
Binary file not shown.
14 changes: 7 additions & 7 deletions docs/apis-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Use the `tags` option to categorize your api instances:

```js
import { Api } from "@xbyorange/mercury-api";
import { Api } from "@data-provider/axios";

const booksCollection = new Api("/books", {
tags: ["library"]
Expand All @@ -18,10 +18,10 @@ const usersCollection = new Api("/users", {
});
```

Now, you can use the [`sources` method of the "mercury" library][mercury-sources-docs-url] to configure your api instances depending of their tags:
Now, you can use the [`sources` method of the "Data Provider" library][data-provider-sources-docs-url] to configure your api instances depending of their tags:

```js
import { sources } from "@xbyorange/mercury";
import { sources } from "@data-provider/core";

sources.getByTag("api").config({ retries: 5 }); // will apply this config to all apis

Expand All @@ -35,7 +35,7 @@ You can use the `apis` method of this library to add or set headers to your api
> Use the `setHeaders` method to define headers only for certain tagged apis:
```js
import { apis } from "@xbyorange/mercury-api";
import { apis } from "@data-provider/axios";

// Redefine all headers
apis.setHeaders({ "x-application": "foo" });
Expand All @@ -49,8 +49,8 @@ apis.addHeaders({ Authentication: "Bearer foo-token" }, ["library-auth"]);
Take into account that, when invoking to the `config` method, the api instance configuration is extended with the provided one. The same principle is applied when configuring apis based on their tags. As many tags can be defined for a single api, the order of that tags is relevant when there are different values for the same option in different tags. The last provided tag has priority in case of conflict:

```js
import { sources } from "@xbyorange/mercury";
import { Api } from "@xbyorange/mercury-api";
import { sources } from "@data-provider/core";
import { Api } from "@data-provider/axios";

sources.getByTag("foo-tag-1").config({ retries: 5 });
sources.getByTag("foo-tag-2").config({ retries: 4 });
Expand All @@ -64,5 +64,5 @@ const fooApi2 = new Api("/foo-url-2", {
});
```

[mercury-sources-docs-url]: https://github.com/XbyOrange/mercury/blob/master/docs/sources/api.md
[data-provider-sources-docs-url]: https://github.com/data-provider/core/blob/master/docs/sources/api.md

2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
As first argument, the api url should be provided. Base url can be defined afterwards using config method.

```js
import { Api } from "@xbyorange/mercury-api";
import { Api } from "@data-provider/axios";

const booksCollection = new Api("/books");
```
Expand Down
10 changes: 10 additions & 0 deletions jest.testSequencer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
Copyright 2019 XbyOrange
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.
*/

const Sequencer = require("@jest/test-sequencer").default;

class CustomSequencer extends Sequencer {
Expand Down
13 changes: 12 additions & 1 deletion mocks/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
const { Feature } = require("@xbyorange/mocks-server");
/*
Copyright 2019 Javier Brea
Copyright 2019 XbyOrange
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.
*/

const { Feature } = require("@mocks-server/main");

const {
getBooksSuccess,
Expand Down
10 changes: 10 additions & 0 deletions mocks/fixtures/books/get.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
Copyright 2019 XbyOrange
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.
*/

const {
addBooksServerError,
addBooksNotFoundError,
Expand Down
10 changes: 10 additions & 0 deletions mocks/fixtures/stats/get.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
Copyright 2019 XbyOrange
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.
*/

const { getAll } = require("./storage");

const getStats = {
Expand Down
10 changes: 10 additions & 0 deletions mocks/fixtures/stats/post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
Copyright 2019 XbyOrange
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.
*/

const { reset } = require("./storage");

const resetStats = {
Expand Down
10 changes: 10 additions & 0 deletions mocks/fixtures/stats/storage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
Copyright 2019 XbyOrange
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.
*/

const INITIAL_STATS = {
books: {
notFoundError: 0,
Expand Down
Loading

0 comments on commit 046d184

Please sign in to comment.