Skip to content

Commit 480f170

Browse files
committed
chore: ⚡ bump v1.1.2
1 parent e059ee4 commit 480f170

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

nuxt/templates/plugin.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import Vue from 'vue'
2-
import VueApiQueries, { Validator, BaseProxy } from 'vue-api-queries'
2+
import VueApiQueries, { Validator } from 'vue-api-queries'
33

4-
const errorProperty = '<%= options.errorProperty %>'
4+
const options = <%= serialize(options) %> || {}
5+
const { errorProperty, parsedQs } = options
56

67
export default function (ctx) {
7-
Vue.use(VueApiQueries)
8+
Vue.use(VueApiQueries, { errorProperty, axios: ctx.$axios, parsedQs })
89
ctx.$errors = Validator
9-
BaseProxy.$http = ctx.$axios
10-
BaseProxy.$errorProperty = errorProperty || 'errors'
11-
// inject('queries', BaseProxy)
1210
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-api-queries",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Elegant and simple way to build requests for REST API",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/__tests__/base-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ValidatorType } from '../core/Validator'
66
import Validator from '../core/Validator'
77
import BaseTransformer from '../core/BaseTransformer'
88
import PaginationTransformer from '../core/PaginationTransformer'
9-
import { merge } from '../util/objects'
9+
import { merge } from '../util'
1010

1111
let proxy: PostProxy
1212
let mockAdapter: MockAdapter

src/core/BaseProxy.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
import type { Errors } from '..'
99
import Validator from './Validator'
1010
import { hasFiles, objectToFormData, removeDoubleSlash } from '../util'
11-
import qs, { ParsedQs } from 'qs'
11+
import qs, { IParseOptions } from 'qs'
12+
import merge from 'lodash.merge'
1213

1314
const validator = Validator
1415
const UNPROCESSABLE_ENTITY = 422
@@ -21,8 +22,13 @@ class BaseProxy {
2122
public errors: Errors
2223
public parameters: any | any[]
2324
public readonly endpoint: string
24-
public static $http: AxiosInstance | undefined
25+
public static $http?: AxiosInstance
2526
public static $errorProperty = 'errors'
27+
public static $parsedQs: IParseOptions = {
28+
comma: true,
29+
allowDots: true,
30+
ignoreQueryPrefix: true,
31+
}
2632

2733
constructor(endpoint: string, parameters?: ParametersType) {
2834
this.endpoint = endpoint
@@ -38,6 +44,10 @@ class BaseProxy {
3844
return BaseProxy.$errorProperty
3945
}
4046

47+
get $parsedQs() {
48+
return BaseProxy.$parsedQs
49+
}
50+
4151
/**
4252
* Get all or by pagination
4353
*/
@@ -228,7 +238,7 @@ class BaseProxy {
228238
}
229239

230240
private static __validateRequestType(requestType: Method): string {
231-
const requestTypes: Array<string> = [
241+
const requestTypes: string[] = [
232242
'get',
233243
'delete',
234244
'head',
@@ -263,12 +273,12 @@ class BaseProxy {
263273
*/
264274
setParameter(parameter: string, value?: any): this {
265275
if (!value) {
266-
const options = {
276+
const options: IParseOptions = merge(this.$parsedQs, {
267277
comma: true,
268278
allowDots: true,
269279
ignoreQueryPrefix: true,
270-
}
271-
const params: ParsedQs = qs.parse(parameter, options)
280+
})
281+
const params = qs.parse(parameter, options)
272282
return this.setParameters(params)
273283
}
274284
this.parameters[parameter] = value
@@ -283,9 +293,9 @@ class BaseProxy {
283293
if (!parameters.length) {
284294
this.parameters = []
285295
} else {
286-
parameters.forEach((parameter) => {
296+
for (const parameter of parameters) {
287297
delete this.parameters[parameter]
288-
})
298+
}
289299
}
290300
return this
291301
}

src/core/BaseTransformer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import snakeCaseKeys from 'snakecase-keys'
22
import camelcaseKeys from 'camelcase-keys'
33

44
class BaseTransformer {
5-
static fetchCollection<T>(items: T[], camelKey?: boolean): T[] {
5+
static fetchCollection<T>(
6+
items: T[],
7+
camelKey?: boolean,
8+
): (Record<string, any> | T)[] {
69
return items.map((item: T) => this.fetch(item, camelKey))
710
}
811

@@ -13,10 +16,7 @@ class BaseTransformer {
1316
return items.map((item: T) => this.send(item, snakeKey))
1417
}
1518

16-
static fetch<T extends Record<string, any>>(
17-
item: T,
18-
camelKey?: boolean,
19-
): T | any {
19+
static fetch<T>(item: T, camelKey?: boolean): T | Record<string, any> {
2020
return camelKey ? camelcaseKeys(item, { deep: true }) : item
2121
}
2222

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import BaseProxy from './core/BaseProxy'
33
import Validator from './core/Validator'
44
import BaseTransformer from './core/BaseTransformer'
55
import PaginationTransformer from './core/PaginationTransformer'
6+
import merge from 'lodash.merge'
67

78
// augment typings of Vue.js
89
import './vue'
@@ -11,7 +12,22 @@ export type Errors = ValidatorType
1112
export type { ValidatorType }
1213

1314
class VueApiQueries {
14-
install(Vue: any) {
15+
installed = false
16+
install(Vue: any, options: any = {}) {
17+
if (this.installed) return
18+
this.installed = true
19+
const defaultOption = merge(options, {
20+
parsedQs: {
21+
comma: true,
22+
allowDots: true,
23+
ignoreQueryPrefix: true,
24+
},
25+
errorProperty: 'errors',
26+
})
27+
const { axios, errorProperty, parsedQs } = defaultOption
28+
BaseProxy.$http = axios
29+
BaseProxy.$errorProperty = errorProperty || 'errors'
30+
BaseProxy.$parsedQs = parsedQs
1531
Vue.mixin({
1632
beforeCreate() {
1733
this.$options.$errors = {}

0 commit comments

Comments
 (0)