@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/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: any): this;
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?: any[]): this;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapnl/js-junction",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "This project allows you to easily consume API's built with Junction.",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
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
@@ -7,6 +7,6 @@ window._ = _;
7
7
  const api = new Api();
8
8
  window.api = api;
9
9
 
10
- export { Model };
10
+ export { Model, Api };
11
11
 
12
12
  export default api;
@@ -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 (...params) {
80
- return this.where(...params);
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 (...params) {
92
- return this.whereIn(...params);
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 {Array} parameters
265
+ * @param {Object} parameters
265
266
  *
266
267
  * @returns {this} The current instance.
267
268
  */
268
- customParameters (parameters = []) {
269
- this._customParameters.push(...parameters);
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);