@schukai/monster 3.5.0 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/source/constants.mjs +4 -9
- package/source/constraints/abstract.mjs +4 -6
- package/source/constraints/abstractoperator.mjs +6 -12
- package/source/constraints/andoperator.mjs +3 -6
- package/source/constraints/invalid.mjs +3 -6
- package/source/constraints/isarray.mjs +6 -9
- package/source/constraints/isobject.mjs +4 -7
- package/source/constraints/namespace.mjs +1 -3
- package/source/constraints/oroperator.mjs +26 -25
- package/source/constraints/valid.mjs +3 -6
- package/source/data/buildmap.mjs +20 -36
- package/source/data/buildtree.mjs +29 -29
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
- package/source/data/datasource/server/restapi.mjs +51 -65
- package/source/data/datasource/server/webconnect.mjs +26 -35
- package/source/data/datasource/server.mjs +16 -20
- package/source/data/datasource/storage/localstorage.mjs +8 -11
- package/source/data/datasource/storage/sessionstorage.mjs +8 -10
- package/source/data/datasource/storage.mjs +18 -22
- package/source/data/datasource.mjs +27 -43
- package/source/data/diff.mjs +20 -32
- package/source/data/extend.mjs +20 -14
- package/source/data/namespace.mjs +1 -3
- package/source/data/pathfinder.mjs +40 -67
- package/source/data/pipe.mjs +6 -10
- package/source/data/transformer.mjs +141 -157
- package/source/dom/assembler.mjs +6 -9
- package/source/dom/attributes.mjs +36 -48
- package/source/dom/constants.mjs +55 -71
- package/source/dom/customcontrol.mjs +16 -21
- package/source/dom/customelement.mjs +140 -164
- package/source/dom/events.mjs +17 -24
- package/source/dom/focusmanager.mjs +30 -48
- package/source/dom/locale.mjs +16 -19
- package/source/dom/namespace.mjs +1 -1
- package/source/dom/ready.mjs +7 -10
- package/source/dom/resource/data.mjs +38 -46
- package/source/dom/resource/link/namespace.mjs +1 -3
- package/source/dom/resource/link/stylesheet.mjs +7 -11
- package/source/dom/resource/link.mjs +36 -17
- package/source/dom/resource/namespace.mjs +1 -1
- package/source/dom/resource/script.mjs +23 -13
- package/source/dom/resource.mjs +47 -60
- package/source/dom/resourcemanager.mjs +36 -43
- package/source/dom/template.mjs +17 -24
- package/source/dom/theme.mjs +8 -12
- package/source/dom/updater.mjs +150 -196
- package/source/dom/util.mjs +11 -12
- package/source/dom/worker/factory.mjs +21 -25
- package/source/dom/worker/namespace.mjs +1 -1
- package/source/i18n/formatter.mjs +20 -24
- package/source/i18n/locale.mjs +40 -42
- package/source/i18n/namespace.mjs +1 -1
- package/source/i18n/provider.mjs +4 -7
- package/source/i18n/providers/embed.mjs +16 -26
- package/source/i18n/providers/fetch.mjs +30 -36
- package/source/i18n/translations.mjs +15 -22
- package/source/logging/handler/console.mjs +6 -10
- package/source/logging/handler.mjs +15 -18
- package/source/logging/logentry.mjs +8 -9
- package/source/logging/logger.mjs +73 -55
- package/source/logging/namespace.mjs +1 -1
- package/source/math/namespace.mjs +1 -1
- package/source/math/random.mjs +13 -14
- package/source/monster.mjs +132 -100
- package/source/net/namespace.mjs +1 -3
- package/source/net/webconnect/message.mjs +6 -8
- package/source/net/webconnect/namespace.mjs +1 -3
- package/source/net/webconnect.mjs +28 -39
- package/source/text/formatter.mjs +44 -55
- package/source/types/base.mjs +16 -26
- package/source/types/basewithoptions.mjs +8 -14
- package/source/types/binary.mjs +4 -5
- package/source/types/dataurl.mjs +19 -27
- package/source/types/global.mjs +14 -26
- package/source/types/id.mjs +4 -6
- package/source/types/is.mjs +11 -16
- package/source/types/mediatype.mjs +29 -44
- package/source/types/namespace.mjs +0 -1
- package/source/types/node.mjs +16 -22
- package/source/types/nodelist.mjs +10 -14
- package/source/types/noderecursiveiterator.mjs +11 -14
- package/source/types/observablequeue.mjs +13 -16
- package/source/types/observer.mjs +16 -23
- package/source/types/observerlist.mjs +18 -21
- package/source/types/proxyobserver.mjs +24 -37
- package/source/types/queue.mjs +8 -13
- package/source/types/randomid.mjs +10 -10
- package/source/types/regex.mjs +3 -5
- package/source/types/stack.mjs +4 -8
- package/source/types/tokenlist.mjs +24 -31
- package/source/types/typeof.mjs +5 -7
- package/source/types/uniquequeue.mjs +8 -13
- package/source/types/uuid.mjs +18 -25
- package/source/types/validate.mjs +26 -27
- package/source/types/version.mjs +17 -25
- package/source/util/clone.mjs +23 -32
- package/source/util/comparator.mjs +7 -15
- package/source/util/deadmansswitch.mjs +16 -23
- package/source/util/freeze.mjs +5 -7
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +33 -39
- package/source/util/trimspaces.mjs +17 -24
- package/test/cases/monster.mjs +1 -1
package/source/math/random.mjs
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {getGlobal} from
|
8
|
+
import { getGlobal } from "../types/global.mjs";
|
9
9
|
|
10
|
-
export {random}
|
10
|
+
export { random };
|
11
11
|
|
12
12
|
/**
|
13
13
|
* this function uses crypt and returns a random number.
|
@@ -24,8 +24,7 @@ export {random}
|
|
24
24
|
* @since 1.0.0
|
25
25
|
* @copyright schukai GmbH
|
26
26
|
*/
|
27
|
-
|
28
|
-
|
27
|
+
function random(min, max) {
|
29
28
|
if (min === undefined) {
|
30
29
|
min = 0;
|
31
30
|
}
|
@@ -38,7 +37,6 @@ export {random}
|
|
38
37
|
}
|
39
38
|
|
40
39
|
return Math.round(create(min, max));
|
41
|
-
|
42
40
|
}
|
43
41
|
|
44
42
|
/**
|
@@ -47,9 +45,11 @@ export {random}
|
|
47
45
|
*/
|
48
46
|
var MAX = 1000000000;
|
49
47
|
|
50
|
-
Math.log2 =
|
51
|
-
|
52
|
-
|
48
|
+
Math.log2 =
|
49
|
+
Math.log2 ||
|
50
|
+
function (n) {
|
51
|
+
return Math.log(n) / Math.log(2);
|
52
|
+
};
|
53
53
|
|
54
54
|
/**
|
55
55
|
*
|
@@ -65,21 +65,21 @@ function create(min, max) {
|
|
65
65
|
let crypt;
|
66
66
|
let globalReference = getGlobal();
|
67
67
|
|
68
|
-
crypt = globalReference?.[
|
68
|
+
crypt = globalReference?.["crypto"] || globalReference?.["msCrypto"] || globalReference?.["crypto"] || undefined;
|
69
69
|
|
70
70
|
if (typeof crypt === "undefined") {
|
71
|
-
throw new Error("missing crypt")
|
71
|
+
throw new Error("missing crypt");
|
72
72
|
}
|
73
73
|
|
74
74
|
let rval = 0;
|
75
75
|
const range = max - min;
|
76
76
|
if (range < 2) {
|
77
|
-
throw
|
77
|
+
throw new Error("the distance is too small to create a random number.");
|
78
78
|
}
|
79
79
|
|
80
80
|
const bitsNeeded = Math.ceil(Math.log2(range));
|
81
81
|
if (bitsNeeded > 53) {
|
82
|
-
throw
|
82
|
+
throw new Error("we cannot generate numbers larger than 53 bits.");
|
83
83
|
}
|
84
84
|
const bytesNeeded = Math.ceil(bitsNeeded / 8);
|
85
85
|
const mask = Math.pow(2, bitsNeeded) - 1;
|
@@ -102,7 +102,6 @@ function create(min, max) {
|
|
102
102
|
if (rval < min) {
|
103
103
|
rval += min;
|
104
104
|
}
|
105
|
-
|
106
|
-
return rval;
|
107
105
|
|
106
|
+
return rval;
|
108
107
|
}
|
package/source/monster.mjs
CHANGED
@@ -14,30 +14,49 @@
|
|
14
14
|
*/
|
15
15
|
|
16
16
|
// development/script/grep-exports.cjs
|
17
|
-
export {IsObject} from "./constraints/isobject.mjs"
|
18
|
-
export {Invalid} from "./constraints/invalid.mjs"
|
19
|
-
export {AndOperator} from "./constraints/andoperator.mjs"
|
20
|
-
export {OrOperator} from "./constraints/oroperator.mjs"
|
21
|
-
export {AbstractConstraint} from "./constraints/abstract.mjs"
|
22
|
-
export {IsArray} from "./constraints/isarray.mjs"
|
23
|
-
export {AbstractOperator} from "./constraints/abstractoperator.mjs"
|
24
|
-
export {Valid} from "./constraints/valid.mjs"
|
25
|
-
export {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
export {
|
37
|
-
export {
|
38
|
-
export {
|
39
|
-
export {
|
40
|
-
export {
|
17
|
+
export { IsObject } from "./constraints/isobject.mjs";
|
18
|
+
export { Invalid } from "./constraints/invalid.mjs";
|
19
|
+
export { AndOperator } from "./constraints/andoperator.mjs";
|
20
|
+
export { OrOperator } from "./constraints/oroperator.mjs";
|
21
|
+
export { AbstractConstraint } from "./constraints/abstract.mjs";
|
22
|
+
export { IsArray } from "./constraints/isarray.mjs";
|
23
|
+
export { AbstractOperator } from "./constraints/abstractoperator.mjs";
|
24
|
+
export { Valid } from "./constraints/valid.mjs";
|
25
|
+
export {
|
26
|
+
Logger,
|
27
|
+
ALL,
|
28
|
+
TRACE,
|
29
|
+
DEBUG,
|
30
|
+
INFO,
|
31
|
+
WARN,
|
32
|
+
ERROR,
|
33
|
+
FATAL,
|
34
|
+
OFF,
|
35
|
+
} from "./logging/logger.mjs";
|
36
|
+
export { LogEntry } from "./logging/logentry.mjs";
|
37
|
+
export { ConsoleHandler } from "./logging/handler/console.mjs";
|
38
|
+
export { Handler } from "./logging/handler.mjs";
|
39
|
+
export { Formatter } from "./text/formatter.mjs";
|
40
|
+
export { Stylesheet } from "./dom/resource/link/stylesheet.mjs";
|
41
|
+
export { Data } from "./dom/resource/data.mjs";
|
42
|
+
export { Link } from "./dom/resource/link.mjs";
|
43
|
+
export { Script } from "./dom/resource/script.mjs";
|
44
|
+
export { Updater, addObjectWithUpdaterToElement } from "./dom/updater.mjs";
|
45
|
+
export { CustomControl } from "./dom/customcontrol.mjs";
|
46
|
+
export { getLocaleOfDocument } from "./dom/locale.mjs";
|
47
|
+
export { Theme, getDocumentTheme } from "./dom/theme.mjs";
|
48
|
+
export {
|
49
|
+
Resource,
|
50
|
+
KEY_DOCUMENT,
|
51
|
+
KEY_QUERY,
|
52
|
+
referenceSymbol,
|
53
|
+
} from "./dom/resource.mjs";
|
54
|
+
export { ResourceManager } from "./dom/resourcemanager.mjs";
|
55
|
+
export {
|
56
|
+
getDocument,
|
57
|
+
getWindow,
|
58
|
+
getDocumentFragmentFromString,
|
59
|
+
} from "./dom/util.mjs";
|
41
60
|
export {
|
42
61
|
DEFAULT_THEME,
|
43
62
|
ATTRIBUTE_PREFIX,
|
@@ -91,17 +110,16 @@ export {
|
|
91
110
|
ATTRIBUTE_EXPORTPARTS,
|
92
111
|
ATTRIBUTE_HIDDEN,
|
93
112
|
objectUpdaterLinkSymbol,
|
94
|
-
customElementUpdaterLinkSymbol
|
95
|
-
|
96
|
-
} from "./dom/constants.mjs"
|
113
|
+
customElementUpdaterLinkSymbol,
|
114
|
+
} from "./dom/constants.mjs";
|
97
115
|
export {
|
98
116
|
CustomElement,
|
99
117
|
initMethodSymbol,
|
100
118
|
assembleMethodSymbol,
|
101
119
|
attributeObserverSymbol,
|
102
120
|
registerCustomElement,
|
103
|
-
getSlottedElements
|
104
|
-
} from "./dom/customelement.mjs"
|
121
|
+
getSlottedElements,
|
122
|
+
} from "./dom/customelement.mjs";
|
105
123
|
export {
|
106
124
|
findClosestObjectLink,
|
107
125
|
addToObjectLink,
|
@@ -115,46 +133,54 @@ export {
|
|
115
133
|
replaceAttributeToken,
|
116
134
|
clearAttributeTokens,
|
117
135
|
findClosestByAttribute,
|
118
|
-
findClosestByClass
|
119
|
-
} from "./dom/attributes.mjs"
|
120
|
-
export {
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
export {
|
126
|
-
export {
|
127
|
-
export {
|
128
|
-
export {
|
129
|
-
export {
|
130
|
-
export {
|
131
|
-
export {
|
132
|
-
export {
|
136
|
+
findClosestByClass,
|
137
|
+
} from "./dom/attributes.mjs";
|
138
|
+
export {
|
139
|
+
fireEvent,
|
140
|
+
fireCustomEvent,
|
141
|
+
findTargetElementFromEvent,
|
142
|
+
} from "./dom/events.mjs";
|
143
|
+
export { Factory } from "./dom/worker/factory.mjs";
|
144
|
+
export { Template } from "./dom/template.mjs";
|
145
|
+
export { domReady, windowReady } from "./dom/ready.mjs";
|
146
|
+
export { FocusManager } from "./dom/focusmanager.mjs";
|
147
|
+
export { ATTRIBUTEPREFIX, Assembler } from "./dom/assembler.mjs";
|
148
|
+
export { Translations } from "./i18n/translations.mjs";
|
149
|
+
export { Locale, parseLocale } from "./i18n/locale.mjs";
|
150
|
+
export { Formatter as I18nFormatter } from "./i18n/formatter.mjs";
|
151
|
+
export { Fetch } from "./i18n/providers/fetch.mjs";
|
152
|
+
export { Provider } from "./i18n/provider.mjs";
|
153
|
+
export { Message } from "./net/webconnect/message.mjs";
|
154
|
+
export { WebConnect as NetWebConnect } from "./net/webconnect.mjs";
|
133
155
|
export {
|
134
156
|
internalSymbol,
|
135
157
|
internalStateSymbol,
|
136
|
-
instanceSymbol
|
137
|
-
} from "./constants.mjs"
|
138
|
-
export {MediaType, parseMediaType} from "./types/mediatype.mjs"
|
139
|
-
export {typeOf} from "./types/typeof.mjs"
|
140
|
-
export {ObserverList} from "./types/observerlist.mjs"
|
141
|
-
export {RandomID} from "./types/randomid.mjs"
|
142
|
-
export {ObservableQueue} from "./types/observablequeue.mjs"
|
143
|
-
export {UUID} from "./types/uuid.mjs"
|
144
|
-
export {Observer} from "./types/observer.mjs"
|
145
|
-
export {TokenList} from "./types/tokenlist.mjs"
|
146
|
-
export {Queue} from "./types/queue.mjs"
|
147
|
-
export {Stack} from "./types/stack.mjs"
|
148
|
-
export {toBinary, fromBinary} from "./types/binary.mjs"
|
149
|
-
export {BaseWithOptions} from "./types/basewithoptions.mjs"
|
150
|
-
export {escapeString} from "./types/regex.mjs"
|
151
|
-
export {ProxyObserver} from "./types/proxyobserver.mjs"
|
152
|
-
export {NodeList} from "./types/nodelist.mjs"
|
153
|
-
export {Version, getMonsterVersion} from "./types/version.mjs"
|
154
|
-
export {Node} from "./types/node.mjs"
|
155
|
-
export {NodeRecursiveIterator} from "./types/noderecursiveiterator.mjs"
|
156
|
-
export {
|
157
|
-
|
158
|
+
instanceSymbol,
|
159
|
+
} from "./constants.mjs";
|
160
|
+
export { MediaType, parseMediaType } from "./types/mediatype.mjs";
|
161
|
+
export { typeOf } from "./types/typeof.mjs";
|
162
|
+
export { ObserverList } from "./types/observerlist.mjs";
|
163
|
+
export { RandomID } from "./types/randomid.mjs";
|
164
|
+
export { ObservableQueue } from "./types/observablequeue.mjs";
|
165
|
+
export { UUID } from "./types/uuid.mjs";
|
166
|
+
export { Observer } from "./types/observer.mjs";
|
167
|
+
export { TokenList } from "./types/tokenlist.mjs";
|
168
|
+
export { Queue } from "./types/queue.mjs";
|
169
|
+
export { Stack } from "./types/stack.mjs";
|
170
|
+
export { toBinary, fromBinary } from "./types/binary.mjs";
|
171
|
+
export { BaseWithOptions } from "./types/basewithoptions.mjs";
|
172
|
+
export { escapeString } from "./types/regex.mjs";
|
173
|
+
export { ProxyObserver } from "./types/proxyobserver.mjs";
|
174
|
+
export { NodeList } from "./types/nodelist.mjs";
|
175
|
+
export { Version, getMonsterVersion } from "./types/version.mjs";
|
176
|
+
export { Node } from "./types/node.mjs";
|
177
|
+
export { NodeRecursiveIterator } from "./types/noderecursiveiterator.mjs";
|
178
|
+
export {
|
179
|
+
getGlobal,
|
180
|
+
getGlobalObject,
|
181
|
+
getGlobalFunction,
|
182
|
+
} from "./types/global.mjs";
|
183
|
+
export { DataUrl, parseDataURL } from "./types/dataurl.mjs";
|
158
184
|
export {
|
159
185
|
validateIterable,
|
160
186
|
validatePrimitive,
|
@@ -165,39 +191,47 @@ export {
|
|
165
191
|
validateArray,
|
166
192
|
validateSymbol,
|
167
193
|
validateFunction,
|
168
|
-
validateInteger
|
169
|
-
} from "./types/validate.mjs"
|
170
|
-
export {UniqueQueue} from "./types/uniquequeue.mjs"
|
171
|
-
export {Base} from "./types/base.mjs"
|
194
|
+
validateInteger,
|
195
|
+
} from "./types/validate.mjs";
|
196
|
+
export { UniqueQueue } from "./types/uniquequeue.mjs";
|
197
|
+
export { Base } from "./types/base.mjs";
|
172
198
|
export {
|
173
|
-
isIterable,
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
export {
|
185
|
-
export {
|
186
|
-
export {
|
187
|
-
export {
|
188
|
-
export {
|
189
|
-
export {
|
190
|
-
export {
|
191
|
-
export {
|
192
|
-
export {
|
193
|
-
export {
|
194
|
-
export {
|
195
|
-
export {
|
196
|
-
export {
|
197
|
-
export {
|
199
|
+
isIterable,
|
200
|
+
isPrimitive,
|
201
|
+
isSymbol,
|
202
|
+
isBoolean,
|
203
|
+
isString,
|
204
|
+
isObject,
|
205
|
+
isInstance,
|
206
|
+
isArray,
|
207
|
+
isFunction,
|
208
|
+
isInteger,
|
209
|
+
} from "./types/is.mjs";
|
210
|
+
export { ID } from "./types/id.mjs";
|
211
|
+
export { trimSpaces } from "./util/trimspaces.mjs";
|
212
|
+
export { DeadMansSwitch } from "./util/deadmansswitch.mjs";
|
213
|
+
export { deepFreeze } from "./util/freeze.mjs";
|
214
|
+
export { Comparator } from "./util/comparator.mjs";
|
215
|
+
export { clone } from "./util/clone.mjs";
|
216
|
+
export { Processing } from "./util/processing.mjs";
|
217
|
+
export { extend } from "./data/extend.mjs";
|
218
|
+
export { Pipe } from "./data/pipe.mjs";
|
219
|
+
export { buildMap, PARENT, assembleParts } from "./data/buildmap.mjs";
|
220
|
+
export { Datasource } from "./data/datasource.mjs";
|
221
|
+
export { buildTree } from "./data/buildtree.mjs";
|
222
|
+
export { Transformer } from "./data/transformer.mjs";
|
223
|
+
export { Pathfinder, DELIMITER, WILDCARD } from "./data/pathfinder.mjs";
|
224
|
+
export { diff } from "./data/diff.mjs";
|
225
|
+
export { Server } from "./data/datasource/server.mjs";
|
226
|
+
export { SessionStorage } from "./data/datasource/storage/sessionstorage.mjs";
|
227
|
+
export { LocalStorage } from "./data/datasource/storage/localstorage.mjs";
|
228
|
+
export { RestAPI } from "./data/datasource/server/restapi.mjs";
|
229
|
+
export { WebConnect } from "./data/datasource/server/webconnect.mjs";
|
230
|
+
export { WriteError } from "./data/datasource/server/restapi/writeerror.mjs";
|
231
|
+
export { Storage, storageObjectSymbol } from "./data/datasource/storage.mjs";
|
232
|
+
export { random } from "./math/random.mjs";
|
198
233
|
|
199
|
-
|
200
|
-
export {Monster}
|
234
|
+
export { Monster };
|
201
235
|
|
202
236
|
/**
|
203
237
|
* This class has no other purpose than to exist.
|
@@ -207,6 +241,4 @@ export {Monster}
|
|
207
241
|
* @copyright schukai GmbH
|
208
242
|
* @memberOf Monster
|
209
243
|
*/
|
210
|
-
class Monster {
|
211
|
-
|
212
|
-
}
|
244
|
+
class Monster {}
|
package/source/net/namespace.mjs
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {Base} from "../../types/base.mjs";
|
9
|
-
import {validateObject, validateString} from "../../types/validate.mjs";
|
8
|
+
import { Base } from "../../types/base.mjs";
|
9
|
+
import { validateObject, validateString } from "../../types/validate.mjs";
|
10
10
|
|
11
|
-
export {Message}
|
11
|
+
export { Message };
|
12
12
|
|
13
13
|
const dataSymbol = Symbol("@@data");
|
14
14
|
|
@@ -22,7 +22,6 @@ const dataSymbol = Symbol("@@data");
|
|
22
22
|
* @summary The Message class encapsulates a WebSocket message.
|
23
23
|
*/
|
24
24
|
class Message extends Base {
|
25
|
-
|
26
25
|
/**
|
27
26
|
* @param {Object} data
|
28
27
|
* @throws {TypeError} value is not a object
|
@@ -31,10 +30,10 @@ class Message extends Base {
|
|
31
30
|
super();
|
32
31
|
this[dataSymbol] = validateObject(data);
|
33
32
|
}
|
34
|
-
|
33
|
+
|
35
34
|
/**
|
36
35
|
* Returns the raw message.
|
37
|
-
*
|
36
|
+
*
|
38
37
|
* @returns {object}
|
39
38
|
*/
|
40
39
|
getData() {
|
@@ -57,5 +56,4 @@ class Message extends Base {
|
|
57
56
|
validateString(json);
|
58
57
|
return new Message(JSON.parse(json));
|
59
58
|
}
|
60
|
-
|
61
|
-
}
|
59
|
+
}
|
@@ -5,14 +5,13 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {instanceSymbol} from "../constants.mjs";
|
9
|
-
import {isInteger, isString, isObject} from "../types/is.mjs";
|
10
|
-
import {BaseWithOptions} from "../types/basewithoptions.mjs";
|
11
|
-
import {ObservableQueue} from "../types/observablequeue.mjs";
|
12
|
-
import {Message} from "./webconnect/message.mjs";
|
8
|
+
import { instanceSymbol } from "../constants.mjs";
|
9
|
+
import { isInteger, isString, isObject } from "../types/is.mjs";
|
10
|
+
import { BaseWithOptions } from "../types/basewithoptions.mjs";
|
11
|
+
import { ObservableQueue } from "../types/observablequeue.mjs";
|
12
|
+
import { Message } from "./webconnect/message.mjs";
|
13
13
|
|
14
|
-
|
15
|
-
export {WebConnect}
|
14
|
+
export { WebConnect };
|
16
15
|
|
17
16
|
/**
|
18
17
|
* @private
|
@@ -57,7 +56,7 @@ const connectionStatusCode = {
|
|
57
56
|
1009: "Message too big",
|
58
57
|
1010: "Mandatory extension",
|
59
58
|
1011: "Internal server error",
|
60
|
-
1015: "TLS handshake"
|
59
|
+
1015: "TLS handshake",
|
61
60
|
};
|
62
61
|
|
63
62
|
/**
|
@@ -68,15 +67,15 @@ const connectionStatusCode = {
|
|
68
67
|
function connectServer(resolve, reject) {
|
69
68
|
const self = this;
|
70
69
|
|
71
|
-
const url = self.getOption(
|
70
|
+
const url = self.getOption("url");
|
72
71
|
if (!url) {
|
73
|
-
reject(
|
72
|
+
reject("No url defined for webconnect.");
|
74
73
|
return;
|
75
74
|
}
|
76
75
|
|
77
76
|
let promiseAllredyResolved = false;
|
78
77
|
|
79
|
-
let connectionTimeout = self.getOption(
|
78
|
+
let connectionTimeout = self.getOption("connection.timeout");
|
80
79
|
if (!isInteger(connectionTimeout) || connectionTimeout < 100) {
|
81
80
|
connectionTimeout = 5000;
|
82
81
|
}
|
@@ -88,11 +87,11 @@ function connectServer(resolve, reject) {
|
|
88
87
|
reject(new Error("Connection timeout"));
|
89
88
|
}, connectionTimeout);
|
90
89
|
|
91
|
-
let reconnectTimeout = self.getOption(
|
90
|
+
let reconnectTimeout = self.getOption("connection.reconnect.timeout");
|
92
91
|
if (!isInteger(reconnectTimeout) || reconnectTimeout < 1000) reconnectTimeout = 1000;
|
93
|
-
let reconnectAttempts = self.getOption(
|
92
|
+
let reconnectAttempts = self.getOption("connection.reconnect.attempts");
|
94
93
|
if (!isInteger(reconnectAttempts) || reconnectAttempts < 1) reconnectAttempts = 1;
|
95
|
-
let reconnectEnabled = self.getOption(
|
94
|
+
let reconnectEnabled = self.getOption("connection.reconnect.enabled");
|
96
95
|
if (reconnectEnabled !== true) reconnectEnabled = false;
|
97
96
|
|
98
97
|
self[manualCloseSymbol] = false;
|
@@ -108,7 +107,7 @@ function connectServer(resolve, reject) {
|
|
108
107
|
if (event.data instanceof Blob) {
|
109
108
|
const reader = new FileReader();
|
110
109
|
reader.addEventListener("loadend", function () {
|
111
|
-
self[receiveQueueSymbol].add(new Message(reader.result))
|
110
|
+
self[receiveQueueSymbol].add(new Message(reader.result));
|
112
111
|
});
|
113
112
|
reader.readAsText(new Message(event.data));
|
114
113
|
} else {
|
@@ -118,14 +117,13 @@ function connectServer(resolve, reject) {
|
|
118
117
|
|
119
118
|
self[connectionSymbol].socket.onopen = function () {
|
120
119
|
self[connectionSymbol].reconnectCounter = 0;
|
121
|
-
if (typeof resolve ===
|
120
|
+
if (typeof resolve === "function" && !promiseAllredyResolved) {
|
122
121
|
promiseAllredyResolved = true;
|
123
122
|
resolve();
|
124
123
|
}
|
125
124
|
};
|
126
125
|
|
127
126
|
self[connectionSymbol].socket.close = function (event) {
|
128
|
-
|
129
127
|
if (self[manualCloseSymbol]) {
|
130
128
|
self[manualCloseSymbol] = false;
|
131
129
|
return;
|
@@ -136,22 +134,19 @@ function connectServer(resolve, reject) {
|
|
136
134
|
self.connect();
|
137
135
|
}, reconnectTimeout * this[connectionSymbol].reconnectCounter);
|
138
136
|
}
|
139
|
-
|
140
137
|
};
|
141
138
|
|
142
139
|
self[connectionSymbol].socket.onerror = (error) => {
|
143
|
-
|
144
140
|
if (reconnectEnabled && self[connectionSymbol].reconnectCounter < reconnectAttempts) {
|
145
141
|
setTimeout(() => {
|
146
142
|
self.connect();
|
147
143
|
}, reconnectTimeout * this[connectionSymbol].reconnectCounter);
|
148
144
|
} else {
|
149
|
-
if (typeof reject ===
|
145
|
+
if (typeof reject === "function" && !promiseAllredyResolved) {
|
150
146
|
promiseAllredyResolved = true;
|
151
147
|
reject(error);
|
152
148
|
}
|
153
149
|
}
|
154
|
-
|
155
150
|
};
|
156
151
|
}
|
157
152
|
|
@@ -166,17 +161,15 @@ function connectServer(resolve, reject) {
|
|
166
161
|
* @summary The LocalStorage class encapsulates the access to data objects.
|
167
162
|
*/
|
168
163
|
class WebConnect extends BaseWithOptions {
|
169
|
-
|
170
164
|
/**
|
171
165
|
*
|
172
166
|
* @param {Object} [options] options contains definitions for the webconnect.
|
173
167
|
*/
|
174
168
|
constructor(options) {
|
175
|
-
|
176
169
|
if (isString(options)) {
|
177
|
-
options = {url: options};
|
170
|
+
options = { url: options };
|
178
171
|
}
|
179
|
-
|
172
|
+
|
180
173
|
super(options);
|
181
174
|
|
182
175
|
this[receiveQueueSymbol] = new ObservableQueue();
|
@@ -232,8 +225,8 @@ class WebConnect extends BaseWithOptions {
|
|
232
225
|
timeout: 1000,
|
233
226
|
attempts: 1,
|
234
227
|
enabled: false,
|
235
|
-
}
|
236
|
-
}
|
228
|
+
},
|
229
|
+
},
|
237
230
|
});
|
238
231
|
}
|
239
232
|
|
@@ -245,12 +238,12 @@ class WebConnect extends BaseWithOptions {
|
|
245
238
|
* @returns {Promise}
|
246
239
|
* @see https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1
|
247
240
|
*/
|
248
|
-
close(statusCode, reason
|
241
|
+
close(statusCode, reason) {
|
249
242
|
if (!isInteger(statusCode) || statusCode < 1000 || statusCode > 4999) {
|
250
243
|
statusCode = 1000;
|
251
244
|
}
|
252
245
|
if (!isString(reason)) {
|
253
|
-
reason =
|
246
|
+
reason = "";
|
254
247
|
}
|
255
248
|
|
256
249
|
return new Promise((resolve, reject) => {
|
@@ -264,12 +257,11 @@ class WebConnect extends BaseWithOptions {
|
|
264
257
|
}
|
265
258
|
resolve();
|
266
259
|
});
|
267
|
-
|
268
260
|
}
|
269
261
|
|
270
262
|
/**
|
271
263
|
* Polls the receive queue for new messages.
|
272
|
-
*
|
264
|
+
*
|
273
265
|
* @returns {Message}
|
274
266
|
*/
|
275
267
|
poll() {
|
@@ -277,8 +269,8 @@ class WebConnect extends BaseWithOptions {
|
|
277
269
|
}
|
278
270
|
|
279
271
|
/**
|
280
|
-
* Are there any messages in the receive queue?
|
281
|
-
*
|
272
|
+
* Are there any messages in the receive queue?
|
273
|
+
*
|
282
274
|
* @returns {boolean}
|
283
275
|
*/
|
284
276
|
dataReceived() {
|
@@ -287,7 +279,7 @@ class WebConnect extends BaseWithOptions {
|
|
287
279
|
|
288
280
|
/**
|
289
281
|
* Get Message from the receive queue, but do not remove it.
|
290
|
-
*
|
282
|
+
*
|
291
283
|
* @returns {Object}
|
292
284
|
*/
|
293
285
|
peek() {
|
@@ -332,15 +324,12 @@ class WebConnect extends BaseWithOptions {
|
|
332
324
|
const self = this;
|
333
325
|
|
334
326
|
return new Promise((resolve, reject) => {
|
335
|
-
|
336
327
|
if (self[connectionSymbol].socket.readyState !== 1) {
|
337
|
-
reject(
|
328
|
+
reject("the socket is not ready");
|
338
329
|
}
|
339
330
|
|
340
|
-
self[connectionSymbol].socket.send(JSON.stringify(message))
|
331
|
+
self[connectionSymbol].socket.send(JSON.stringify(message));
|
341
332
|
resolve();
|
342
333
|
});
|
343
334
|
}
|
344
|
-
|
345
335
|
}
|
346
|
-
|