@mapcreator/api 2.4.1 → 2.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapcreator/api",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "Mapcreator JavaScript API",
5
5
  "main": "dist/bundle.js",
6
6
  "repository": "https://gitlab.com/mapcreator/api-wrapper.git",
package/src/Mapcreator.js CHANGED
@@ -58,6 +58,7 @@ import {
58
58
  Layer,
59
59
  Mapstyle,
60
60
  MapstyleSet,
61
+ Message,
61
62
  Notification,
62
63
  Organisation,
63
64
  Permission,
@@ -559,6 +560,15 @@ export default class Mapcreator extends mix(EventEmitter, Injectable) {
559
560
  return this.static(Notification);
560
561
  }
561
562
 
563
+ /**
564
+ * Message accessor
565
+ * @see {@link Message}
566
+ * @returns {ResourceProxy} - A proxy for accessing the resource
567
+ */
568
+ get messages () {
569
+ return this.static(Message);
570
+ }
571
+
562
572
  /**
563
573
  * Organisation accessor
564
574
  * @see {@link Organisation}
@@ -0,0 +1,48 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2020, Mapcreator
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * Redistributions of source code must retain the above copyright notice, this
11
+ * list of conditions and the following disclaimer.
12
+ *
13
+ * Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ import CrudBase from './base/CrudBase';
34
+ import MessageVariant from './MessageVariant';
35
+
36
+ export default class Message extends CrudBase {
37
+ static get resourceName () {
38
+ return 'messages';
39
+ }
40
+
41
+ _guessType (name, value) {
42
+ if (name === 'variants') {
43
+ return Array.from(value).map(data => new MessageVariant(this.api, data));
44
+ }
45
+
46
+ return super._guessType(name, value);
47
+ }
48
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * BSD 3-Clause License
3
+ *
4
+ * Copyright (c) 2020, Mapcreator
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without
8
+ * modification, are permitted provided that the following conditions are met:
9
+ *
10
+ * Redistributions of source code must retain the above copyright notice, this
11
+ * list of conditions and the following disclaimer.
12
+ *
13
+ * Redistributions in binary form must reproduce the above copyright notice,
14
+ * this list of conditions and the following disclaimer in the documentation
15
+ * and/or other materials provided with the distribution.
16
+ *
17
+ * Neither the name of the copyright holder nor the names of its
18
+ * contributors may be used to endorse or promote products derived from
19
+ * this software without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+
34
+ import ResourceBase from './base/ResourceBase';
35
+
36
+ export default class MessageVariant extends ResourceBase {
37
+ }
@@ -46,6 +46,7 @@ import Language from './Language';
46
46
  import Layer from './Layer';
47
47
  import Mapstyle from './Mapstyle';
48
48
  import MapstyleSet from './MapstyleSet';
49
+ import Message from './Message';
49
50
  import Notification from './Notification';
50
51
  import Organisation from './Organisation';
51
52
  import Permission from './Permission';
@@ -101,6 +102,14 @@ export default class User extends CrudBase {
101
102
  return this._proxyResourceList(Notification);
102
103
  }
103
104
 
105
+ /**
106
+ * Get the list messagse linked to the user
107
+ * @returns {SimpleResourceProxy} - A proxy for accessing the resource
108
+ */
109
+ get messages () {
110
+ return this._proxyResourceList(Message);
111
+ }
112
+
104
113
  /**
105
114
  * Get the list mapstyle sets linked to the user
106
115
  * @returns {SimpleResourceProxy} - A proxy for accessing the resource
@@ -37,7 +37,7 @@ import SimpleResourceProxy from '../../proxy/SimpleResourceProxy';
37
37
  import Injectable from '../../traits/Injectable';
38
38
  import { fnv32b } from '../../utils/hash';
39
39
  import { isParentOf, mix } from '../../utils/reflection';
40
- import { makeCancelable } from '../../utils/helpers';
40
+ import { clone, makeCancelable } from '../../utils/helpers';
41
41
 
42
42
  function unique (input) {
43
43
  return input.filter((v, i) => input.findIndex(vv => vv === v) === i);
@@ -62,7 +62,7 @@ export default class ResourceBase extends mix(null, Injectable) {
62
62
  this.api = api;
63
63
 
64
64
  // De-reference
65
- data = { ...data };
65
+ data = clone(data);
66
66
 
67
67
  // Normalize keys to snake_case
68
68
  // Fix data types
@@ -75,7 +75,7 @@ export default class ResourceBase extends mix(null, Injectable) {
75
75
  continue;
76
76
  }
77
77
 
78
- data[newKey] = this.constructor._guessType(newKey, data[key]);
78
+ data[newKey] = this._guessType(newKey, data[key]);
79
79
 
80
80
  if (newKey !== key) {
81
81
  delete data[key];
@@ -295,7 +295,7 @@ export default class ResourceBase extends mix(null, Injectable) {
295
295
 
296
296
  if (!this.constructor.protectedFields.includes(key) && !this.constructor.readonly) {
297
297
  desc.set = val => {
298
- this._properties[key] = ResourceBase._guessType(key, val);
298
+ this._properties[key] = this._guessType(key, val);
299
299
  delete this._url; // Clears url cache
300
300
  };
301
301
  }
@@ -309,10 +309,10 @@ export default class ResourceBase extends mix(null, Injectable) {
309
309
  * Guess type based on property name
310
310
  * @param {string} name - Field name
311
311
  * @param {*} value - Field Value
312
- * @private
312
+ * @protected
313
313
  * @returns {*} - Original or converted value
314
314
  */
315
- static _guessType (name, value) {
315
+ _guessType (name, value) {
316
316
  if (name.endsWith('_at') || name.startsWith('date_')) {
317
317
  return typeof value === 'string' ? new Date(value.replace(' ', 'T')) : value;
318
318
  } else if (/(_|^)id$/.test(name) && value !== null) {
@@ -51,6 +51,7 @@ export Language from './Language';
51
51
  export Layer from './Layer';
52
52
  export Mapstyle from './Mapstyle';
53
53
  export MapstyleSet from './MapstyleSet';
54
+ export Message from './Message';
54
55
  export Notification from './Notification';
55
56
  export Organisation from './Organisation';
56
57
  export Permission from './Permission';
@@ -154,3 +154,25 @@ export function serializeUTCDate (date) {
154
154
 
155
155
  return out;
156
156
  }
157
+
158
+ export function clone (input, clonePrivate = true) {
159
+ const _clone = value => clone(value, clonePrivate);
160
+
161
+ if (typeof input !== 'object' || input === null) {
162
+ return input;
163
+ } else if (Array.isArray(input)) {
164
+ return input.map(_clone);
165
+ }
166
+
167
+ const output = {};
168
+
169
+ for (const key of Object.keys(input)) {
170
+ if (!clonePrivate && key.startsWith('_')) {
171
+ continue;
172
+ }
173
+
174
+ output[key] = _clone(input[key]);
175
+ }
176
+
177
+ return output;
178
+ }