@mapomodule/core 1.0.0-alpha.1 → 1.0.0-alpha.6

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 ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.6](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2021-12-26)
7
+
8
+
9
+ ### Features
10
+
11
+ * **core:** reject promise for crud methods if no endpoint was passed during configuration ([bb8d447](https://github.com/lotrekagency/mapo/commit/bb8d4474efe41af5d7f38dbcd47731133d6ba154))
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Lotrek 2021
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
package/api/crud.js CHANGED
@@ -1,4 +1,5 @@
1
- const trimslashes = (str) => str.replace(/^\/|\/$/g, '')
1
+ const trimslashes = (str) => (str || "").replace(/^\/|\/$/g, '')
2
+ const endpointError = "This crud is badly configured. No endpoint was passed"
2
3
 
3
4
  /**
4
5
  * This function generates a fully functional crud helper given the endpoint.
@@ -16,7 +17,8 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
16
17
  * @returns {Promise<external:AxiosResponse>}
17
18
  */
18
19
  list(config) {
19
- return $axios.$get(`/${trimslashes(endpoint)}/`, { ...higherConf, ...config })
20
+ const func = $axios.$get(`/${trimslashes(endpoint)}/`, { ...higherConf, ...config })
21
+ return endpoint !== null ? func : Promise.reject(endpointError)
20
22
  },
21
23
 
22
24
  /**
@@ -27,7 +29,8 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
27
29
  * @returns {Promise<external:AxiosResponse>}
28
30
  */
29
31
  create(payload, config) {
30
- return $axios.$post(`/${trimslashes(endpoint)}/`, payload, { ...higherConf, ...config })
32
+ const func = $axios.$post(`/${trimslashes(endpoint)}/`, payload, { ...higherConf, ...config })
33
+ return endpoint !== null ? func : Promise.reject(endpointError)
31
34
  },
32
35
 
33
36
  /**
@@ -38,7 +41,8 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
38
41
  * @returns {Promise<external:AxiosResponse>}
39
42
  */
40
43
  detail(id, config) {
41
- return $axios.$get(`/${trimslashes(endpoint)}/${id}/`, { ...higherConf, ...config })
44
+ const func = $axios.$get(`/${trimslashes(endpoint)}/${id}/`, { ...higherConf, ...config })
45
+ return endpoint !== null ? func : Promise.reject(endpointError)
42
46
  },
43
47
 
44
48
  /**
@@ -49,7 +53,8 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
49
53
  * @returns {Promise<external:AxiosResponse>}
50
54
  */
51
55
  updateOrCreate(payload, config) {
52
- return payload.id ? this.update(payload.id, payload, { ...higherConf, ...config }) : this.create(payload, { ...higherConf, ...config })
56
+ const func = payload.id ? this.update(payload.id, payload, { ...higherConf, ...config }) : this.create(payload, { ...higherConf, ...config })
57
+ return endpoint !== null ? func : Promise.reject(endpointError)
53
58
  },
54
59
 
55
60
  /**
@@ -61,7 +66,8 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
61
66
  * @returns {Promise<external:AxiosResponse>}
62
67
  */
63
68
  update(id, payload, config) {
64
- return $axios.$put(`/${trimslashes(endpoint)}/${id}/`, payload, { ...higherConf, ...config })
69
+ const func = $axios.$put(`/${trimslashes(endpoint)}/${id}/`, payload, { ...higherConf, ...config })
70
+ return endpoint !== null ? func : Promise.reject(endpointError)
65
71
  },
66
72
 
67
73
  /**
@@ -73,7 +79,8 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
73
79
  * @returns {Promise<external:AxiosResponse>}
74
80
  */
75
81
  partialUpdate(id, payload, config) {
76
- return $axios.$patch(`/${trimslashes(endpoint)}/${id}/`, payload, { ...higherConf, ...config })
82
+ const func = $axios.$patch(`/${trimslashes(endpoint)}/${id}/`, payload, { ...higherConf, ...config })
83
+ return endpoint !== null ? func : Promise.reject(endpointError)
77
84
  },
78
85
  /**
79
86
  * This makes a DELETE http call to the crud endpoint slash the given id. Returns as a promise the server response.
@@ -83,7 +90,8 @@ const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
83
90
  * @returns {Promise<external:AxiosResponse>}
84
91
  */
85
92
  delete(id, config) {
86
- return $axios.$delete(`/${trimslashes(endpoint)}/${id}/`, { ...higherConf, ...config })
93
+ const func = $axios.$delete(`/${trimslashes(endpoint)}/${id}/`, { ...higherConf, ...config })
94
+ return endpoint !== null ? func : Promise.reject(endpointError)
87
95
  }
88
96
  })
89
97
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/core",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "This is part of Mapo nuxt module. Injects the core mapo plugin helpers.",
5
5
  "author": "bnznamco <gabriele.baldi.01@gmail.com>",
6
6
  "keywords": [
@@ -18,5 +18,5 @@
18
18
  "publishConfig": {
19
19
  "access": "public"
20
20
  },
21
- "gitHead": "a480dac2e2e78e66e0b5b35bd2f03bc3e1575246"
21
+ "gitHead": "c30717d018606a1393f3a1f680276b1817d1d7a8"
22
22
  }