@weapnl/js-junction 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/index.js +1895 -1873
- package/index.d.ts +3 -2
- package/package.json +1 -1
- package/src/connection.js +6 -1
- package/src/index.js +1 -1
- package/src/mixins/filterMixin.js +24 -4
- package/src/request.js +16 -4
package/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ declare class Mixins {
|
|
|
53
53
|
scope(name: string, ...params: any[]): this;
|
|
54
54
|
scopes(...params: any[]): this;
|
|
55
55
|
search(value: any, columns?: any[]): this;
|
|
56
|
-
where(column: string, operator: string, value
|
|
56
|
+
where(column: string, operator: string, value?: any): this;
|
|
57
57
|
wheres(...params: any[]): this;
|
|
58
58
|
whereIn(column: string, values: any[]): this;
|
|
59
59
|
whereIns(...params: any[]): this;
|
|
@@ -84,7 +84,8 @@ declare class Request extends Mixins {
|
|
|
84
84
|
onUnauthorized(callback?: (response: Response) => void): this;
|
|
85
85
|
onForbidden(callback?: (response: Response) => void): this;
|
|
86
86
|
triggerResponseEvents(response: Response, successResponse?: any): Promise<void>;
|
|
87
|
-
customParameters(parameters?:
|
|
87
|
+
customParameters(parameters?: object): this;
|
|
88
|
+
setApi(api: Api): this;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
export class Model extends Request {
|
package/package.json
CHANGED
package/src/connection.js
CHANGED
|
@@ -6,6 +6,7 @@ export default class Connection {
|
|
|
6
6
|
this._abortController = null;
|
|
7
7
|
|
|
8
8
|
this._config = {};
|
|
9
|
+
this._api = null;
|
|
9
10
|
|
|
10
11
|
this.running = false;
|
|
11
12
|
this.canceled = false;
|
|
@@ -24,6 +25,10 @@ export default class Connection {
|
|
|
24
25
|
this._config = config;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
setApi (api) {
|
|
29
|
+
this._api = api;
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
async get (query, params) {
|
|
28
33
|
return this._execute(query, 'get', params);
|
|
29
34
|
}
|
|
@@ -48,7 +53,7 @@ export default class Connection {
|
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
const config = {
|
|
51
|
-
url: api.baseUrl + url,
|
|
56
|
+
url: (this._api ? this._api.baseUrl : api.baseUrl) + url,
|
|
52
57
|
method,
|
|
53
58
|
...({
|
|
54
59
|
[method === 'get' ? 'params' : 'data']: data,
|
package/src/index.js
CHANGED
|
@@ -56,6 +56,18 @@ const filterMixin = {
|
|
|
56
56
|
return this;
|
|
57
57
|
},
|
|
58
58
|
|
|
59
|
+
scopes (input) {
|
|
60
|
+
input.forEach(scope => {
|
|
61
|
+
if (Array.isArray(scope)) {
|
|
62
|
+
this.scope(...scope);
|
|
63
|
+
} else {
|
|
64
|
+
this.scope(scope);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return this;
|
|
69
|
+
},
|
|
70
|
+
|
|
59
71
|
search (value, columns = []) {
|
|
60
72
|
if (! Array.isArray(columns)) columns = [columns];
|
|
61
73
|
|
|
@@ -76,8 +88,12 @@ const filterMixin = {
|
|
|
76
88
|
return this;
|
|
77
89
|
},
|
|
78
90
|
|
|
79
|
-
wheres (
|
|
80
|
-
|
|
91
|
+
wheres (input) {
|
|
92
|
+
input.forEach(where => {
|
|
93
|
+
this.where(...where);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return this;
|
|
81
97
|
},
|
|
82
98
|
|
|
83
99
|
whereIn (column, values) {
|
|
@@ -88,8 +104,12 @@ const filterMixin = {
|
|
|
88
104
|
return this;
|
|
89
105
|
},
|
|
90
106
|
|
|
91
|
-
whereIns (
|
|
92
|
-
|
|
107
|
+
whereIns (input) {
|
|
108
|
+
input.forEach(whereIn => {
|
|
109
|
+
this.whereIn(...whereIn);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return this;
|
|
93
113
|
},
|
|
94
114
|
|
|
95
115
|
pluck (fields) {
|
package/src/request.js
CHANGED
|
@@ -8,6 +8,7 @@ import actionMixin from './mixins/actionMixin';
|
|
|
8
8
|
import filterMixin from './mixins/filterMixin';
|
|
9
9
|
import modifierMixin from './mixins/modifierMixin';
|
|
10
10
|
import paginationMixin from './mixins/paginationMixin';
|
|
11
|
+
import Api from './api';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @mixes actionMixin
|
|
@@ -163,7 +164,7 @@ export default class Request {
|
|
|
163
164
|
this._modifiers.toObject(),
|
|
164
165
|
this._pagination.toObject(),
|
|
165
166
|
this._action.toObject(),
|
|
166
|
-
...this._customParameters,
|
|
167
|
+
_.merge(...this._customParameters),
|
|
167
168
|
]));
|
|
168
169
|
}
|
|
169
170
|
|
|
@@ -261,12 +262,12 @@ export default class Request {
|
|
|
261
262
|
/**
|
|
262
263
|
* Add custom parameters to the request.
|
|
263
264
|
*
|
|
264
|
-
* @param {
|
|
265
|
+
* @param {Object} parameters
|
|
265
266
|
*
|
|
266
267
|
* @returns {this} The current instance.
|
|
267
268
|
*/
|
|
268
|
-
customParameters (parameters =
|
|
269
|
-
this._customParameters.push(
|
|
269
|
+
customParameters (parameters = {}) {
|
|
270
|
+
this._customParameters.push(parameters);
|
|
270
271
|
|
|
271
272
|
return this;
|
|
272
273
|
}
|
|
@@ -309,6 +310,17 @@ export default class Request {
|
|
|
309
310
|
|
|
310
311
|
return formData;
|
|
311
312
|
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @param {Api} api
|
|
316
|
+
*
|
|
317
|
+
* @returns {this} The current instance.
|
|
318
|
+
*/
|
|
319
|
+
setApi (api) {
|
|
320
|
+
this._connection.setApi(api);
|
|
321
|
+
|
|
322
|
+
return this;
|
|
323
|
+
}
|
|
312
324
|
}
|
|
313
325
|
|
|
314
326
|
Object.assign(Request.prototype, actionMixin);
|