@schukai/monster 3.12.1 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.12.1",
3
+ "version": "3.13.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Copyright schukai GmbH and contributors 2022. All Rights Reserved.
3
+ * Node module: @schukai/monster
4
+ * This file is licensed under the AGPLv3 License.
5
+ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
+ */
7
+
8
+ import { instanceSymbol } from "../../constants.mjs";
9
+ import { isObject } from "../../types/is.mjs";
10
+ import { Datasource } from "../datasource.mjs";
11
+
12
+ export {DomStorage};
13
+
14
+
15
+ /**
16
+ * The DomStorage is a class that stores data in memory.
17
+ *
18
+ * @license AGPLv3
19
+ * @copyright schukai GmbH
20
+ * @memberOf Monster.Data.Datasource
21
+ */
22
+ class DomStorage extends Datasource {
23
+ /**
24
+ * @param {Object} [options] options contains definitions for the datasource.
25
+ */
26
+ constructor(options) {
27
+ super();
28
+
29
+ if (isObject(options)) {
30
+ this.setOptions(options);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * This method is called by the `instanceof` operator.
36
+ * @returns {symbol}
37
+ */
38
+ static get [instanceSymbol]() {
39
+ return Symbol.for("@schukai/monster/data/datasource/storage/dom-storage");
40
+ }
41
+
42
+ /**
43
+ * @property {Object} defaults
44
+ * @property {Object} defaults.read
45
+ * @property {string} defaults.read.selector
46
+ * @property {Object} defaults.write
47
+ * @property {string} defaults.write.selector
48
+ */
49
+ get defaults() {
50
+ return Object.assign({}, super.defaults, {
51
+ read: {
52
+ selector: undefined,
53
+ },
54
+ write: {
55
+ selector: undefined,
56
+ }
57
+ });
58
+ }
59
+
60
+ /**
61
+ * @return {Promise}
62
+ * @throws {Error} The read selector is not defined
63
+ * @throws {Error} There are no storage element
64
+ */
65
+ read() {
66
+ const self = this;
67
+
68
+ let selector = self.getOption("read.selector", undefined);
69
+ if (!selector) {
70
+ throw new Error("The read selector is not defined");
71
+ }
72
+
73
+ let storage = document.querySelector(selector);
74
+ if (!storage) {
75
+ throw new Error("There are no storage element");
76
+ }
77
+
78
+ return new Promise((resolve, reject) => {
79
+ try {
80
+ let data = JSON.parse(storage.innerHTML);
81
+ self.set(data)
82
+ resolve(data);
83
+ } catch (e) {
84
+ reject(e);
85
+ }
86
+ ;
87
+ })
88
+ }
89
+
90
+ /**
91
+ * @return {Promise}
92
+ * @throws {Error} The write selector is not defined
93
+ * @throws {Error} There are no storage element
94
+ */
95
+ write() {
96
+
97
+ const self = this;
98
+
99
+ let selector = self.getOption("write.selector");
100
+ if (!selector) {
101
+ throw new Error("The write selector is not defined");
102
+ }
103
+
104
+ let storage = document.querySelector(selector);
105
+ if (!storage) {
106
+ throw new Error("There are no storage element");
107
+ }
108
+
109
+ return new Promise((resolve, reject) => {
110
+ try {
111
+ storage.innerHTML = JSON.stringify(self.get());
112
+ resolve(storage);
113
+ } catch (e) {
114
+ reject(e);
115
+ }
116
+ })
117
+
118
+
119
+ }
120
+
121
+ }
122
+
@@ -12,8 +12,6 @@ import { WriteError } from "./restapi/writeerror.mjs";
12
12
 
13
13
  export { RestAPI };
14
14
 
15
-
16
-
17
15
  /**
18
16
  * @type {symbol}
19
17
  * @memberOf Monster
@@ -133,7 +131,7 @@ class RestAPI extends Server {
133
131
  self.set(self.transformServerPayload.call(self, obj));
134
132
  };
135
133
 
136
- return fetchData.call(this, "read", callback);
134
+ return fetchData.call(this, init,"read", callback);
137
135
  }
138
136
 
139
137
  /**
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.12.1");
145
+ monsterVersion = new Version("3.13.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -0,0 +1,18 @@
1
+ import {expect} from "chai"
2
+ import {DomStorage} from "../../../../../application/source/data/datasource/dom.mjs";
3
+
4
+
5
+ describe('ServeDomr', function () {
6
+
7
+ it('should init', function () {
8
+
9
+ const dom = new DomStorage({
10
+
11
+ })
12
+
13
+ expect(dom).to.be.not.null
14
+
15
+
16
+ })
17
+
18
+ });
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.12.1")
10
+ monsterVersion = new Version("3.13.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13