Skip to content

Commit

Permalink
extensions instead of customExtensions (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Delmont authored Dec 14, 2020
1 parent f4aee5c commit c1a488b
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 41 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ yarn install
* `dist/mobx-async-store.umd.js`
a UMD build, suitable for use in any environment (including the browser, as a `<script>` tag), that includes the external dependency. This corresponds to the `"browser"` field in package.json

`yarn run yuidoc` updates the documentation, located in `docs`.

## Installation

```
Expand Down
9 changes: 6 additions & 3 deletions dist/mobx-async-store.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ var Model = (_class = (_temp = /*#__PURE__*/function () {
* todo.title = 'Buy Cheese'
* todo.dirtyAttributes
* => ['title']
* todo.note = note1
* todo.dirtyAttributes
* => ['title', 'relationships.note']
* ```
* @method dirtyAttributes
* @return {Array} dirty attribute paths
Expand Down Expand Up @@ -1448,7 +1451,7 @@ var Store = (_class$1 = (_temp$1 = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(type, records) {
var options,
queryParams,
customExtensions,
extensions,
url,
recordAttributes,
body,
Expand All @@ -1460,7 +1463,7 @@ var Store = (_class$1 = (_temp$1 = /*#__PURE__*/function () {
switch (_context.prev = _context.next) {
case 0:
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
queryParams = options.queryParams, customExtensions = options.customExtensions; // get url for record type
queryParams = options.queryParams, extensions = options.extensions; // get url for record type

url = _this.fetchUrl(type, queryParams, null); // convert records to an appropriate jsonapi attribute/relationship format

Expand All @@ -1472,7 +1475,7 @@ var Store = (_class$1 = (_temp$1 = /*#__PURE__*/function () {
data: recordAttributes
}); // build the json api extension string

extensionStr = customExtensions !== null && customExtensions !== void 0 && customExtensions.length ? "ext=\"bulk,".concat(customExtensions.join(), "\"") : 'ext="bulk"'; // send request
extensionStr = extensions !== null && extensions !== void 0 && extensions.length ? "ext=\"bulk,".concat(extensions.join(), "\"") : 'ext="bulk"'; // send request

response = _this.fetch(url, {
headers: _objectSpread$2(_objectSpread$2({}, _this.defaultFetchOptions.headers), {}, {
Expand Down
9 changes: 6 additions & 3 deletions dist/mobx-async-store.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,9 @@ var Model = (_class = (_temp = /*#__PURE__*/function () {
* todo.title = 'Buy Cheese'
* todo.dirtyAttributes
* => ['title']
* todo.note = note1
* todo.dirtyAttributes
* => ['title', 'relationships.note']
* ```
* @method dirtyAttributes
* @return {Array} dirty attribute paths
Expand Down Expand Up @@ -1442,7 +1445,7 @@ var Store = (_class$1 = (_temp$1 = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(type, records) {
var options,
queryParams,
customExtensions,
extensions,
url,
recordAttributes,
body,
Expand All @@ -1454,7 +1457,7 @@ var Store = (_class$1 = (_temp$1 = /*#__PURE__*/function () {
switch (_context.prev = _context.next) {
case 0:
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
queryParams = options.queryParams, customExtensions = options.customExtensions; // get url for record type
queryParams = options.queryParams, extensions = options.extensions; // get url for record type

url = _this.fetchUrl(type, queryParams, null); // convert records to an appropriate jsonapi attribute/relationship format

Expand All @@ -1466,7 +1469,7 @@ var Store = (_class$1 = (_temp$1 = /*#__PURE__*/function () {
data: recordAttributes
}); // build the json api extension string

extensionStr = customExtensions !== null && customExtensions !== void 0 && customExtensions.length ? "ext=\"bulk,".concat(customExtensions.join(), "\"") : 'ext="bulk"'; // send request
extensionStr = extensions !== null && extensions !== void 0 && extensions.length ? "ext=\"bulk,".concat(extensions.join(), "\"") : 'ext="bulk"'; // send request

response = _this.fetch(url, {
headers: _objectSpread$2(_objectSpread$2({}, _this.defaultFetchOptions.headers), {}, {
Expand Down
10 changes: 5 additions & 5 deletions docs/classes/Model.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down Expand Up @@ -1065,15 +1065,15 @@ <h3 class="name"><code>previousSnapshot</code></h3>
<div class="meta">
<p>
Defined in
<a href="../files/src_Model.js.html#l491"><code>src&#x2F;Model.js:491</code></a>
<a href="../files/src_Model.js.html#l502"><code>src&#x2F;Model.js:502</code></a>
</p>



</div>

<div class="description">
<p>the latest snapshot</p>
<p>the latest persisted snapshot or the first snapshot if the model was never persisted</p>

</div>

Expand All @@ -1096,15 +1096,15 @@ <h3 class="name"><code>previousSnapshot</code></h3>
<div class="meta">
<p>
Defined in
<a href="../files/src_Model.js.html#l502"><code>src&#x2F;Model.js:502</code></a>
<a href="../files/src_Model.js.html#l491"><code>src&#x2F;Model.js:491</code></a>
</p>



</div>

<div class="description">
<p>the latest persisted snapshot or the first snapshot if the model was never persisted</p>
<p>the latest snapshot</p>

</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/classes/RelatedRecordsArray.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/Schema.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
8 changes: 4 additions & 4 deletions docs/classes/Store.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down Expand Up @@ -708,7 +708,7 @@ <h4>Parameters:</h4>


<div class="param-description">
<p>{queryParams, customExtensions}</p>
<p>{queryParams, extensions}</p>

</div>

Expand Down Expand Up @@ -2666,7 +2666,7 @@ <h3 class="name"><code>initializeNetworkConfiguration</code></h3>
<div class="meta">
<p>
Defined in
<a href="../files/src_Store.js.html#l470"><code>src&#x2F;Store.js:470</code></a>
<a href="../files/src_Store.js.html#l481"><code>src&#x2F;Store.js:481</code></a>
</p>


Expand Down Expand Up @@ -2720,7 +2720,7 @@ <h3 class="name"><code>initializeNetworkConfiguration</code></h3>
<div class="meta">
<p>
Defined in
<a href="../files/src_Store.js.html#l481"><code>src&#x2F;Store.js:481</code></a>
<a href="../files/src_Store.js.html#l470"><code>src&#x2F;Store.js:470</code></a>
</p>


Expand Down
4 changes: 2 additions & 2 deletions docs/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "mobx-async-store",
"description": "Asyc Data Store for mobx",
"url": "https://github.com/artemis-ag/mobx-async-store",
"version": "3.1.1"
"version": "3.2.0"
},
"files": {
"src/decorators/attributes.js": {
Expand Down Expand Up @@ -890,7 +890,7 @@
},
{
"name": "options",
"description": "{queryParams, customExtensions}",
"description": "{queryParams, extensions}",
"type": "Object"
}
],
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_Model.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
10 changes: 5 additions & 5 deletions docs/files/src_Store.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down Expand Up @@ -190,10 +190,10 @@ <h1 class="file-heading">File: src/Store.js</h1>
* @method bulkSave
* @param {String} type
* @param {Array} records
* @param {Object} options {queryParams, customExtensions}
* @param {Object} options {queryParams, extensions}
*/
bulkSave = async (type, records, options = {}) =&gt; {
const { queryParams, customExtensions } = options
const { queryParams, extensions } = options

// get url for record type
const url = this.fetchUrl(type, queryParams, null)
Expand All @@ -205,8 +205,8 @@ <h1 class="file-heading">File: src/Store.js</h1>
const body = JSON.stringify({ data: recordAttributes })

// build the json api extension string
const extensionStr = customExtensions?.length
? &#x60;ext=&quot;bulk,${customExtensions.join()}&quot;&#x60;
const extensionStr = extensions?.length
? &#x60;ext=&quot;bulk,${extensions.join()}&quot;&#x60;
: &#x27;ext=&quot;bulk&quot;&#x27;

// send request
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_decorators_attributes.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_decorators_relationships.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_schema.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/files/src_utils.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="./assets/css/logo.png" title="mobx-async-store" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 3.1.1</em>
<em>API Docs for: 3.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@artemisag/mobx-async-store",
"version": "3.1.1",
"version": "3.2.0",
"module": "dist/mobx-async-store.esm.js",
"browser": "dist/mobx-async-store.cjs.js",
"main": "dist/mobx-async-store.cjs.js",
Expand Down
12 changes: 6 additions & 6 deletions spec/Store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ describe('Store', () => {
.toEqual('application/vnd.api+json; ext="bulk"')
})

it('adds the customExtensions to the request header', async () => {
it('adds the extensions to the request header', async () => {
const todo1 = store.add('todos', { title: 'Pet Dog' })
const customExtensions = ['artemis/group', 'artemis/extendDaThings']
const extensions = ['artemis/group', 'artemis/extendDaThings']
const mockTodosData = {
data: [
{
Expand All @@ -312,15 +312,15 @@ describe('Store', () => {
const mockTodosResponse = JSON.stringify(mockTodosData)
fetch.mockResponse(mockTodosResponse)

await store.bulkSave('todos', [todo1], {customExtensions})
await store.bulkSave('todos', [todo1], {extensions})

expect(fetch.mock.calls[0][1].headers['Content-Type'])
.toEqual('application/vnd.api+json; ext="bulk,artemis/group,artemis/extendDaThings"')
})

it('ignores empty customExtensions in the request header', async () => {
it('ignores empty extensions in the request header', async () => {
const todo1 = store.add('todos', { title: 'Pet Dog' })
const customExtensions = []
const extensions = []
const mockTodosData = {
data: [
{
Expand All @@ -334,7 +334,7 @@ describe('Store', () => {
const mockTodosResponse = JSON.stringify(mockTodosData)
fetch.mockResponse(mockTodosResponse)

await store.bulkSave('todos', [todo1], {customExtensions})
await store.bulkSave('todos', [todo1], {extensions})

expect(fetch.mock.calls[0][1].headers['Content-Type'])
.toEqual('application/vnd.api+json; ext="bulk"')
Expand Down
8 changes: 4 additions & 4 deletions src/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class Store {
* @method bulkSave
* @param {String} type
* @param {Array} records
* @param {Object} options {queryParams, customExtensions}
* @param {Object} options {queryParams, extensions}
*/
bulkSave = async (type, records, options = {}) => {
const { queryParams, customExtensions } = options
const { queryParams, extensions } = options

// get url for record type
const url = this.fetchUrl(type, queryParams, null)
Expand All @@ -120,8 +120,8 @@ class Store {
const body = JSON.stringify({ data: recordAttributes })

// build the json api extension string
const extensionStr = customExtensions?.length
? `ext="bulk,${customExtensions.join()}"`
const extensionStr = extensions?.length
? `ext="bulk,${extensions.join()}"`
: 'ext="bulk"'

// send request
Expand Down

0 comments on commit c1a488b

Please sign in to comment.