Skip to content

Commit

Permalink
Replace jquery-param with qs (#57)
Browse files Browse the repository at this point in the history
* replace jquery-param w/ qs
  • Loading branch information
jordanstephens authored Jun 26, 2020
1 parent ada7300 commit e377338
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 30 deletions.
18 changes: 16 additions & 2 deletions dist/mobx-async-store.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require('@babel/runtime/helpers/initializerWarningHelper');
var _typeof = _interopDefault(require('@babel/runtime/helpers/typeof'));
var mobx = require('mobx');
var uuidv1 = _interopDefault(require('uuid/v1'));
var jqueryParam = _interopDefault(require('jquery-param'));
var qs = _interopDefault(require('qs'));
var pluralize = _interopDefault(require('pluralize'));
var dig = _interopDefault(require('lodash/get'));
var flattenDeep = _interopDefault(require('lodash/flattenDeep'));
Expand All @@ -30,6 +30,19 @@ var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/ass
var _inherits = _interopDefault(require('@babel/runtime/helpers/inherits'));
var _wrapNativeSuper = _interopDefault(require('@babel/runtime/helpers/wrapNativeSuper'));

var QueryString = {
parse: function parse(str) {
return qs.parse(str, {
ignoreQueryPrefix: true
});
},
stringify: function stringify(str) {
return qs.stringify(str, {
arrayFormat: 'brackets'
});
}
};

var pending = {};
var counter = {};

Expand Down Expand Up @@ -76,7 +89,7 @@ function requestUrl(baseUrl, endpoint) {
var queryParamString = '';

if (Object.keys(queryParams).length > 0) {
queryParamString = "?".concat(jqueryParam(queryParams));
queryParamString = "?".concat(QueryString.stringify(queryParams));
}

var idForPath = '';
Expand Down Expand Up @@ -2672,6 +2685,7 @@ function (_Array) {

exports.Model = Model;
exports.ObjectPromiseProxy = ObjectPromiseProxy;
exports.QueryString = QueryString;
exports.Store = Store;
exports.attribute = attribute;
exports.relatedToMany = relatedToMany;
Expand Down
19 changes: 16 additions & 3 deletions dist/mobx-async-store.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '@babel/runtime/helpers/initializerWarningHelper';
import _typeof from '@babel/runtime/helpers/typeof';
import { transaction, set, observable, computed, extendObservable, reaction, toJS, action } from 'mobx';
import uuidv1 from 'uuid/v1';
import jqueryParam from 'jquery-param';
import qs from 'qs';
import pluralize from 'pluralize';
import dig from 'lodash/get';
import flattenDeep from 'lodash/flattenDeep';
Expand All @@ -24,6 +24,19 @@ import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized
import _inherits from '@babel/runtime/helpers/inherits';
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';

var QueryString = {
parse: function parse(str) {
return qs.parse(str, {
ignoreQueryPrefix: true
});
},
stringify: function stringify(str) {
return qs.stringify(str, {
arrayFormat: 'brackets'
});
}
};

var pending = {};
var counter = {};

Expand Down Expand Up @@ -70,7 +83,7 @@ function requestUrl(baseUrl, endpoint) {
var queryParamString = '';

if (Object.keys(queryParams).length > 0) {
queryParamString = "?".concat(jqueryParam(queryParams));
queryParamString = "?".concat(QueryString.stringify(queryParams));
}

var idForPath = '';
Expand Down Expand Up @@ -2664,4 +2677,4 @@ function (_Array) {
return RelatedRecordsArray;
}(_wrapNativeSuper(Array));

export { Model, ObjectPromiseProxy, Store, attribute, relatedToMany, relatedToOne, validates };
export { Model, ObjectPromiseProxy, QueryString, Store, attribute, relatedToMany, relatedToOne, validates };
2 changes: 1 addition & 1 deletion 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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
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: 1.1.0</em>
<em>API Docs for: 1.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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion 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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion 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": "1.1.0"
"version": "1.2.0"
},
"files": {
"src/decorators/attributes.js": {
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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
2 changes: 1 addition & 1 deletion 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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
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: 1.1.0</em>
<em>API Docs for: 1.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: 1.1.0</em>
<em>API Docs for: 1.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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
6 changes: 3 additions & 3 deletions 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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down Expand Up @@ -84,7 +84,7 @@ <h1 class="file-heading">File: src/utils.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
import uuidv1 from &#x27;uuid/v1&#x27;
import jqueryParam from &#x27;jquery-param&#x27;
import QueryString from &#x27;./QueryString&#x27;
import pluralize from &#x27;pluralize&#x27;
import dig from &#x27;lodash/get&#x27;
import flattenDeep from &#x27;lodash/flattenDeep&#x27;
Expand Down Expand Up @@ -129,7 +129,7 @@ <h1 class="file-heading">File: src/utils.js</h1>
export function requestUrl (baseUrl, endpoint, queryParams = {}, id) {
let queryParamString = &#x27;&#x27;
if (Object.keys(queryParams).length &gt; 0) {
queryParamString = &#x60;?${jqueryParam(queryParams)}&#x60;
queryParamString = &#x60;?${QueryString.stringify(queryParams)}&#x60;
}
let idForPath = &#x27;&#x27;
if (id) {
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: 1.1.0</em>
<em>API Docs for: 1.2.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@artemisag/mobx-async-store",
"version": "1.1.0",
"version": "1.2.0",
"module": "dist/mobx-async-store.esm.js",
"browser": "dist/mobx-async-store.cjs.js",
"main": "dist/mobx-async-store.cjs.js",
"dependencies": {
"jquery-param": "^1.0.1",
"jsonapi-serializer": "^3.6.4",
"lodash": "^4.17.15",
"mobx": "5.5.0",
"pluralize": "^8.0.0",
"qs": "^6.9.4",
"react-native-uuid": "^1.4.9",
"uuid": "^3.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default [
'@babel/runtime/helpers/possibleConstructorReturn',
'@babel/runtime/helpers/typeof',
'@babel/runtime/regenerator',
'jquery-param',
'query-string',
'jsonapi-serializer',
'mobx',
'moment',
Expand Down
22 changes: 22 additions & 0 deletions spec/QueryString.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import QueryString from '../src/QueryString'

describe('QueryString', () => {
const queryString = 'fields[articles][]=title&fields[articles][]=body&fields[people]=name'
const params = { fields: { articles: [ 'title', 'body' ], people: 'name' } }

describe('stringify', () => {
it('stringifies a deeply nested param object', () => {
expect(decodeURI(QueryString.stringify(params))).toBe(queryString)
})
})

describe('parse', () => {
it('parses a deeply nested query string', () => {
expect(QueryString.parse(queryString)).toEqual(params)
})

it('ignores leading ?', () => {
expect(QueryString.parse(`?${queryString}`)).toEqual(params)
})
})
})
8 changes: 8 additions & 0 deletions src/QueryString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import qs from 'qs'

const QueryString = {
parse: (str) => qs.parse(str, { ignoreQueryPrefix: true }),
stringify: (str) => qs.stringify(str, { arrayFormat: 'brackets' })
}

export default QueryString
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Model from './Model'
import Store from './Store'
import QueryString from './QueryString'
import { attribute, validates } from './decorators/attributes'
import { relatedToMany, relatedToOne } from './decorators/relationships'
import ObjectPromiseProxy from './ObjectPromiseProxy'
Expand All @@ -11,5 +12,6 @@ export {
relatedToMany,
relatedToOne,
validates,
ObjectPromiseProxy
ObjectPromiseProxy,
QueryString
}
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuidv1 from 'uuid/v1'
import jqueryParam from 'jquery-param'
import QueryString from './QueryString'
import pluralize from 'pluralize'
import dig from 'lodash/get'
import flattenDeep from 'lodash/flattenDeep'
Expand Down Expand Up @@ -44,7 +44,7 @@ export function singularizeType (recordType) {
export function requestUrl (baseUrl, endpoint, queryParams = {}, id) {
let queryParamString = ''
if (Object.keys(queryParams).length > 0) {
queryParamString = `?${jqueryParam(queryParams)}`
queryParamString = `?${QueryString.stringify(queryParams)}`
}
let idForPath = ''
if (id) {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3726,11 +3726,6 @@ jest@^24.7.1:
import-local "^2.0.0"
jest-cli "^24.9.0"

jquery-param@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/jquery-param/-/jquery-param-1.0.2.tgz#42ca2a9b244f133f55fa718fd2b62cf55bca0891"
integrity sha512-4DvI/PRdNbTLef+slsmsPW16tPaCUpInbwh6FfKw9S/Q/0xOrGIB4AsUHOeccICuiWtXwNiDCLszy7bavQlXrA==

js-tokens@^3.0.0, js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
Expand Down Expand Up @@ -4774,6 +4769,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==

qs@^6.9.4:
version "6.9.4"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687"
integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==

qs@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-1.0.2.tgz#50a93e2b5af6691c31bcea5dae78ee6ea1903768"
Expand Down

0 comments on commit e377338

Please sign in to comment.