jsf.js_next_gen 4.0.1-beta.6 → 4.0.1-beta.8
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/dist/docs/assets/style.css +4 -5
- package/dist/window/faces-development.js +43 -54
- package/dist/window/faces-development.js.br +0 -0
- package/dist/window/faces-development.js.gz +0 -0
- package/dist/window/faces-development.js.map +1 -1
- package/dist/window/faces.js +1 -1
- package/dist/window/faces.js.br +0 -0
- package/dist/window/faces.js.gz +0 -0
- package/dist/window/faces.js.map +1 -1
- package/dist/window/jsf-development.js +43 -54
- package/dist/window/jsf-development.js.br +0 -0
- package/dist/window/jsf-development.js.gz +0 -0
- package/dist/window/jsf-development.js.map +1 -1
- package/dist/window/jsf.js +1 -1
- package/dist/window/jsf.js.br +0 -0
- package/dist/window/jsf.js.gz +0 -0
- package/dist/window/jsf.js.map +1 -1
- package/package.json +10 -10
- package/src/main/typescript/impl/AjaxImpl.ts +5 -5
- package/src/main/typescript/impl/util/ExtDomQuery.ts +17 -22
- package/src/main/typescript/impl/xhrCore/RequestDataResolver.ts +2 -2
- package/src/main/typescript/impl/xhrCore/XhrRequest.ts +1 -1
- package/src/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.ts +1 -1
- package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +86 -0
- package/src/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.ts +53 -0
- package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/css/bootstrap-icons.css +15 -0
- package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/css/tobago.css +15 -0
- package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/js/tobago.js +15 -0
- package/src/main/typescript/test/xhrCore/ErrorChainTest.spec.ts +23 -0
- package/src/main/typescript/test/xhrCore/RequestParamsTest.spec.ts +1 -1
- package/src/main/typescript/test/xhrCore/ResponseTest23.spec.ts +19 -0
- package/target/AssocArray.js +281 -0
- package/target/AssocArray.js.map +1 -0
- package/target/Config.js +235 -0
- package/target/Config.js.map +1 -0
- package/target/CryptoExtensions.js +112 -0
- package/target/CryptoExtensions.js.map +1 -0
- package/target/DomQuery.js +1963 -0
- package/target/DomQuery.js.map +1 -0
- package/target/Es2019Array.js +117 -0
- package/target/Es2019Array.js.map +1 -0
- package/target/Global.js +38 -0
- package/target/Global.js.map +1 -0
- package/target/IDomQuery.js +3 -0
- package/target/IDomQuery.js.map +1 -0
- package/target/Lang.js +183 -0
- package/target/Lang.js.map +1 -0
- package/target/Messaging.js +645 -0
- package/target/Messaging.js.map +1 -0
- package/target/Monad.js +330 -0
- package/target/Monad.js.map +1 -0
- package/target/Promise.js +296 -0
- package/target/Promise.js.map +1 -0
- package/target/PromiseShim.js +30 -0
- package/target/PromiseShim.js.map +1 -0
- package/target/SourcesCollectors.js +444 -0
- package/target/SourcesCollectors.js.map +1 -0
- package/target/Stream.js +562 -0
- package/target/Stream.js.map +1 -0
- package/target/TagBuilder.js +178 -0
- package/target/TagBuilder.js.map +1 -0
- package/target/XmlQuery.js +84 -0
- package/target/XmlQuery.js.map +1 -0
- package/target/impl/AjaxImpl.js +4 -4
- package/target/impl/AjaxImpl.js.map +1 -1
- package/target/impl/util/ExtDomQuery.js +13 -19
- package/target/impl/util/ExtDomQuery.js.map +1 -1
- package/target/impl/xhrCore/RequestDataResolver.js +1 -1
- package/target/impl/xhrCore/RequestDataResolver.js.map +1 -1
- package/target/index.js +80 -0
- package/target/index.js.map +1 -0
- package/target/index_core.js +76 -0
- package/target/index_core.js.map +1 -0
- package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js +1 -1
- package/target/test/frameworkBase/_ext/shared/StandardInits.js +85 -0
- package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
- package/target/test/frameworkBase/_ext/shared/XmlResponses.js +53 -1
- package/target/test/frameworkBase/_ext/shared/XmlResponses.js.map +1 -1
- package/target/test/xhrCore/ErrorChainTest.spec.js +21 -0
- package/target/test/xhrCore/ErrorChainTest.spec.js.map +1 -1
- package/target/test/xhrCore/RequestParamsTest.spec.js.map +1 -1
- package/target/test/xhrCore/ResponseTest23.spec.js +14 -0
- package/target/test/xhrCore/ResponseTest23.spec.js.map +1 -1
- package/target/types/main/typescript/AssocArray.d.ts +86 -0
- package/target/types/main/typescript/Config.d.ts +94 -0
- package/target/types/main/typescript/CryptoExtensions.d.ts +87 -0
- package/target/types/main/typescript/DomQuery.d.ts +587 -0
- package/target/types/main/typescript/Es2019Array.d.ts +30 -0
- package/target/types/main/typescript/Global.d.ts +23 -0
- package/target/types/main/typescript/IDomQuery.d.ts +480 -0
- package/target/types/main/typescript/Lang.d.ts +97 -0
- package/target/types/main/typescript/Messaging.d.ts +285 -0
- package/target/types/main/typescript/Monad.d.ts +161 -0
- package/target/types/main/typescript/Promise.d.ts +58 -0
- package/target/types/main/typescript/PromiseShim.d.ts +22 -0
- package/target/types/main/typescript/SourcesCollectors.d.ts +280 -0
- package/target/types/main/typescript/Stream.d.ts +284 -0
- package/target/types/main/typescript/TagBuilder.d.ts +50 -0
- package/target/types/main/typescript/XmlQuery.d.ts +31 -0
- package/target/types/main/typescript/api/_api.d.ts +182 -0
- package/target/types/main/typescript/api/faces.d.ts +17 -0
- package/target/types/main/typescript/api/jsf.d.ts +17 -0
- package/target/types/main/typescript/impl/AjaxImpl.d.ts +164 -0
- package/target/types/main/typescript/impl/PushImpl.d.ts +38 -0
- package/target/types/main/typescript/impl/core/Const.d.ts +138 -0
- package/target/types/main/typescript/impl/core/ImplTypes.d.ts +16 -0
- package/target/types/main/typescript/impl/i18n/Messages.d.ts +102 -0
- package/target/types/main/typescript/impl/util/Assertions.d.ts +46 -0
- package/target/types/main/typescript/impl/util/AsyncRunnable.d.ts +112 -0
- package/target/types/main/typescript/impl/util/ExtDomQuery.d.ts +100 -0
- package/target/types/main/typescript/impl/util/FileUtils.d.ts +25 -0
- package/target/types/main/typescript/impl/util/HiddenInputBuilder.d.ts +37 -0
- package/target/types/main/typescript/impl/util/IListener.d.ts +18 -0
- package/target/types/main/typescript/impl/util/Lang.d.ts +138 -0
- package/target/types/main/typescript/impl/util/XhrQueueController.d.ts +51 -0
- package/target/types/main/typescript/impl/xhrCore/ErrorData.d.ts +37 -0
- package/target/types/main/typescript/impl/xhrCore/EventData.d.ts +25 -0
- package/target/types/main/typescript/impl/xhrCore/IResponseProcessor.d.ts +136 -0
- package/target/types/main/typescript/impl/xhrCore/RequestDataResolver.d.ts +84 -0
- package/target/types/main/typescript/impl/xhrCore/ResonseDataResolver.d.ts +60 -0
- package/target/types/main/typescript/impl/xhrCore/Response.d.ts +29 -0
- package/target/types/main/typescript/impl/xhrCore/ResponseProcessor.d.ts +208 -0
- package/target/types/main/typescript/impl/xhrCore/XhrFormData.d.ts +83 -0
- package/target/types/main/typescript/impl/xhrCore/XhrRequest.d.ts +102 -0
- package/target/types/main/typescript/index.d.ts +34 -0
- package/target/types/main/typescript/index_core.d.ts +29 -0
- package/target/types/main/typescript/myfaces/OamSubmit.d.ts +53 -0
- package/target/types/main/typescript/test/frameworkBase/LangTest.spec.d.ts +1 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.d.ts +1 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/LangTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/MappingProbes.d.ts +39 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/MappingTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/MonadTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/XmlQueryTest.spec.d.ts +0 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-with-header.d.ts +1 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-without-header.d.ts +1 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/shared/StandardInits.d.ts +63 -0
- package/target/types/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.d.ts +23 -0
- package/target/types/main/typescript/test/impl/ImplTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/impl/ImplTest_23.spec.d.ts +16 -0
- package/target/types/main/typescript/test/impl/SeparatorCharsTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/myfaces/OamSubmit.spec.d.ts +16 -0
- package/target/types/main/typescript/test/myfaces/OnLoad.spec.d.ts +16 -0
- package/target/types/main/typescript/test/queue/AsynchronousProbe.d.ts +38 -0
- package/target/types/main/typescript/test/queue/AsynchronousQueueTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/ClientWindow.spec.d.ts +1 -0
- package/target/types/main/typescript/test/xhrCore/ErrorChainTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/EventTests.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/FakeWebsocket.d.ts +24 -0
- package/target/types/main/typescript/test/xhrCore/FileUploadTest.spec.d.ts +1 -0
- package/target/types/main/typescript/test/xhrCore/NamespacesRequestTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/OamSubmitTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/RequestParamsTest.spec.d.ts +1 -0
- package/target/types/main/typescript/test/xhrCore/RequestTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/RequestTest_23.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/ResponseTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/ResponseTest23.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/ShadowDomTest.spec.d.ts +16 -0
- package/target/types/main/typescript/test/xhrCore/TobagoFileUploadTest.spec.d.ts +1 -0
- package/target/types/main/typescript/test/xhrCore/WebsocketTest.d.ts +1 -0
- package/target/types/main/typescript/test/xhrCore/XhrFormDataTest.spec.d.ts +16 -0
- package/target/types/test/typescript/AssocArrayTest.spec.d.ts +1 -0
- package/target/types/test/typescript/DomQueryTest.spec.d.ts +1 -0
- package/target/types/test/typescript/ExtendedArrayTest.spec.d.ts +1 -0
- package/target/types/test/typescript/LangTest.spec.d.ts +1 -0
- package/target/types/test/typescript/MappingProbes.d.ts +24 -0
- package/target/types/test/typescript/MappingTest.spec.d.ts +1 -0
- package/target/types/test/typescript/MessagingTest.spec.d.ts +1 -0
- package/target/types/test/typescript/MonadTest.spec.d.ts +16 -0
- package/target/types/test/typescript/PromiseTest.spec.d.ts +1 -0
- package/target/types/test/typescript/StreamTest.spec.d.ts +1 -0
- package/target/types/test/typescript/XmlQueryTest.spec.d.ts +1 -0
- package/target/types/test/typescript/markups/tobago-with-header.d.ts +1 -0
- package/target/types/test/typescript/markups/tobago-without-header.d.ts +1 -0
- package/webpack.config.js +1 -1
- package/webpack.config.js.map +1 -1
- package/.nyc_output/09ca9ebc-2305-4357-8db9-48ddfc7dfde2.json +0 -1
- package/.nyc_output/7c496a14-166e-4aa5-85b9-47b22b055ad8.json +0 -1
- package/.nyc_output/processinfo/09ca9ebc-2305-4357-8db9-48ddfc7dfde2.json +0 -1
- package/.nyc_output/processinfo/7c496a14-166e-4aa5-85b9-47b22b055ad8.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/src/test.html +0 -75
- package/src/tmp/test.html +0 -16
- package/tmp.xml +0 -36
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
4
|
+
* contributor license agreements. See the NOTICE file distributed with
|
|
5
|
+
* this work for additional information regarding copyright ownership.
|
|
6
|
+
* The ASF licenses this file to you under the Apache License, Version 2.0
|
|
7
|
+
* (the "License"); you may not use this file except in compliance with
|
|
8
|
+
* the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.shallowMerge = exports.simpleShallowMerge = exports.deepCopy = exports.buildPath = exports.resolve = exports.appendIf = exports.assignIf = exports.append = exports.assign = void 0;
|
|
20
|
+
const Es2019Array_1 = require("./Es2019Array");
|
|
21
|
+
/**
|
|
22
|
+
* A nop as assign functionality (aka ignore assign)
|
|
23
|
+
*/
|
|
24
|
+
class IgnoreAssign {
|
|
25
|
+
constructor(parent) {
|
|
26
|
+
this.parent = parent;
|
|
27
|
+
}
|
|
28
|
+
set value(value) {
|
|
29
|
+
}
|
|
30
|
+
get value() {
|
|
31
|
+
return this.parent;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
;
|
|
35
|
+
/**
|
|
36
|
+
* uses the known pattern from config
|
|
37
|
+
* assign(target, key1, key2, key3).value = value;
|
|
38
|
+
* @param target
|
|
39
|
+
* @param keys
|
|
40
|
+
*/
|
|
41
|
+
function assign(target, ...accessPath) {
|
|
42
|
+
if (accessPath.length < 1) {
|
|
43
|
+
return new IgnoreAssign(target);
|
|
44
|
+
}
|
|
45
|
+
const lastPathItem = buildPath(target, ...accessPath);
|
|
46
|
+
let assigner = new (class {
|
|
47
|
+
set value(value) {
|
|
48
|
+
lastPathItem.target[lastPathItem.key] = value;
|
|
49
|
+
}
|
|
50
|
+
get value() {
|
|
51
|
+
return lastPathItem.target[lastPathItem.key];
|
|
52
|
+
}
|
|
53
|
+
})();
|
|
54
|
+
return assigner;
|
|
55
|
+
}
|
|
56
|
+
exports.assign = assign;
|
|
57
|
+
function append(target, ...accessPath) {
|
|
58
|
+
if (accessPath.length < 1) {
|
|
59
|
+
return new IgnoreAssign(target);
|
|
60
|
+
}
|
|
61
|
+
const lastPathItem = buildPath(target, ...accessPath);
|
|
62
|
+
let appender = new (class {
|
|
63
|
+
set value(value) {
|
|
64
|
+
if (!Array.isArray(value)) {
|
|
65
|
+
value = [value];
|
|
66
|
+
}
|
|
67
|
+
if (!lastPathItem.target[lastPathItem.key]) {
|
|
68
|
+
lastPathItem.target[lastPathItem.key] = value;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (!Array.isArray(lastPathItem.target[lastPathItem.key])) {
|
|
72
|
+
lastPathItem.target[lastPathItem.key] = [lastPathItem.target[lastPathItem.key]];
|
|
73
|
+
}
|
|
74
|
+
lastPathItem.target[lastPathItem.key].push(...value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
return appender;
|
|
79
|
+
}
|
|
80
|
+
exports.append = append;
|
|
81
|
+
/**
|
|
82
|
+
* uses the known pattern from config
|
|
83
|
+
* assign(target, key1, key2, key3).value = value;
|
|
84
|
+
* @param target
|
|
85
|
+
* @param keys
|
|
86
|
+
*/
|
|
87
|
+
function assignIf(condition, target, ...accessPath) {
|
|
88
|
+
if ((!condition) || accessPath.length < 1) {
|
|
89
|
+
return new IgnoreAssign(target);
|
|
90
|
+
}
|
|
91
|
+
return assign(target, ...accessPath);
|
|
92
|
+
}
|
|
93
|
+
exports.assignIf = assignIf;
|
|
94
|
+
/**
|
|
95
|
+
* uses the known pattern from config
|
|
96
|
+
* assign(target, key1, key2, key3).value = value;
|
|
97
|
+
* @param target
|
|
98
|
+
* @param keys
|
|
99
|
+
*/
|
|
100
|
+
function appendIf(condition, target, ...accessPath) {
|
|
101
|
+
if ((!condition) || accessPath.length < 1) {
|
|
102
|
+
return new IgnoreAssign(target);
|
|
103
|
+
}
|
|
104
|
+
return append(target, ...accessPath);
|
|
105
|
+
}
|
|
106
|
+
exports.appendIf = appendIf;
|
|
107
|
+
function resolve(target, ...accessPath) {
|
|
108
|
+
let ret = null;
|
|
109
|
+
accessPath = flattenAccessPath(accessPath);
|
|
110
|
+
let currPtr = target;
|
|
111
|
+
for (let cnt = 0; cnt < accessPath.length; cnt++) {
|
|
112
|
+
let accessKeyIndex = accessPath[cnt];
|
|
113
|
+
accessKeyIndex = arrayIndex(accessKeyIndex) != -1 ? arrayIndex(accessKeyIndex) : accessKeyIndex;
|
|
114
|
+
currPtr = currPtr === null || currPtr === void 0 ? void 0 : currPtr[accessKeyIndex];
|
|
115
|
+
if ('undefined' == typeof currPtr) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
ret = currPtr;
|
|
119
|
+
}
|
|
120
|
+
return currPtr;
|
|
121
|
+
}
|
|
122
|
+
exports.resolve = resolve;
|
|
123
|
+
function keyVal(key) {
|
|
124
|
+
let start = key.indexOf("[");
|
|
125
|
+
if (start >= 0) {
|
|
126
|
+
return key.substring(0, start);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return key;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function arrayIndex(key) {
|
|
133
|
+
let start = key.indexOf("[");
|
|
134
|
+
let end = key.indexOf("]");
|
|
135
|
+
if (start >= 0 && end > 0 && start < end) {
|
|
136
|
+
return parseInt(key.substring(start + 1, end));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return -1;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function isArrayPos(currKey, arrPos) {
|
|
143
|
+
return currKey === "" && arrPos >= 0;
|
|
144
|
+
}
|
|
145
|
+
function isNoArray(arrPos) {
|
|
146
|
+
return arrPos == -1;
|
|
147
|
+
}
|
|
148
|
+
function alloc(arr, length, defaultVal = {}) {
|
|
149
|
+
let toAdd = [];
|
|
150
|
+
toAdd.length = length;
|
|
151
|
+
toAdd[length - 1] = defaultVal;
|
|
152
|
+
arr.push(...toAdd);
|
|
153
|
+
}
|
|
154
|
+
function flattenAccessPath(accessPath) {
|
|
155
|
+
return new Es2019Array_1.Es2019Array(...accessPath).flatMap(path => path.split("["))
|
|
156
|
+
.map(path => path.indexOf("]") != -1 ? "[" + path : path)
|
|
157
|
+
.filter(path => path != "");
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* builds up a path, only done if no data is present!
|
|
161
|
+
* @param target
|
|
162
|
+
* @param accessPath
|
|
163
|
+
* @returns the last assignable entry
|
|
164
|
+
*/
|
|
165
|
+
function buildPath(target, ...accessPath) {
|
|
166
|
+
accessPath = flattenAccessPath(accessPath);
|
|
167
|
+
//we now have a pattern of having the array accessors always in separate items
|
|
168
|
+
let parentPtr = target;
|
|
169
|
+
let parKeyArrPos = null;
|
|
170
|
+
let currKey = null;
|
|
171
|
+
let arrPos = -1;
|
|
172
|
+
for (let cnt = 0; cnt < accessPath.length; cnt++) {
|
|
173
|
+
currKey = keyVal(accessPath[cnt]);
|
|
174
|
+
arrPos = arrayIndex(accessPath[cnt]);
|
|
175
|
+
//it now is either key or arrPos
|
|
176
|
+
if (arrPos != -1) {
|
|
177
|
+
//case root(array)[5] -> root must be array and allocate 5 elements
|
|
178
|
+
//case root.item[5] root.item must be array and of 5 elements
|
|
179
|
+
if (!Array.isArray(parentPtr)) {
|
|
180
|
+
throw Error("Associative array referenced as index array in path reference");
|
|
181
|
+
}
|
|
182
|
+
//we need to look ahead for proper allocation
|
|
183
|
+
//not end reached
|
|
184
|
+
let nextArrPos = -1;
|
|
185
|
+
if (cnt < accessPath.length - 1) {
|
|
186
|
+
nextArrPos = arrayIndex(accessPath[cnt + 1]);
|
|
187
|
+
}
|
|
188
|
+
let dataPresent = 'undefined' != typeof (parentPtr === null || parentPtr === void 0 ? void 0 : parentPtr[arrPos]);
|
|
189
|
+
//no data present check here is needed, because alloc only reserves if not present
|
|
190
|
+
alloc(parentPtr, arrPos + 1, nextArrPos != -1 ? [] : {});
|
|
191
|
+
parKeyArrPos = arrPos;
|
|
192
|
+
//we now go to the reserved element
|
|
193
|
+
if (cnt == accessPath.length - 1) {
|
|
194
|
+
parentPtr[arrPos] = (dataPresent) ? parentPtr[arrPos] : null;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
parentPtr = parentPtr[arrPos];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
if (Array.isArray(parentPtr)) {
|
|
202
|
+
throw Error("Index array referenced as associative array in path reference");
|
|
203
|
+
}
|
|
204
|
+
//again look ahead whether the next value is an array or assoc array
|
|
205
|
+
let nextArrPos = -1;
|
|
206
|
+
if (cnt < accessPath.length - 1) {
|
|
207
|
+
nextArrPos = arrayIndex(accessPath[cnt + 1]);
|
|
208
|
+
}
|
|
209
|
+
parKeyArrPos = currKey;
|
|
210
|
+
let dataPresent = 'undefined' != typeof (parentPtr === null || parentPtr === void 0 ? void 0 : parentPtr[currKey]);
|
|
211
|
+
if (cnt == accessPath.length - 1) {
|
|
212
|
+
if (!dataPresent) {
|
|
213
|
+
parentPtr[currKey] = null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
if (!dataPresent) {
|
|
218
|
+
parentPtr[currKey] = nextArrPos == -1 ? {} : [];
|
|
219
|
+
}
|
|
220
|
+
parentPtr = parentPtr[currKey];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return { target: parentPtr, key: parKeyArrPos };
|
|
225
|
+
}
|
|
226
|
+
exports.buildPath = buildPath;
|
|
227
|
+
function deepCopy(fromAssoc) {
|
|
228
|
+
return JSON.parse(JSON.stringify(fromAssoc));
|
|
229
|
+
}
|
|
230
|
+
exports.deepCopy = deepCopy;
|
|
231
|
+
/**
|
|
232
|
+
* simple left to right merge
|
|
233
|
+
*
|
|
234
|
+
* @param assocArrays
|
|
235
|
+
*/
|
|
236
|
+
function simpleShallowMerge(...assocArrays) {
|
|
237
|
+
return shallowMerge(true, false, ...assocArrays);
|
|
238
|
+
}
|
|
239
|
+
exports.simpleShallowMerge = simpleShallowMerge;
|
|
240
|
+
/**
|
|
241
|
+
* Shallow merge as in config, but on raw associative arrays
|
|
242
|
+
*
|
|
243
|
+
* @param overwrite
|
|
244
|
+
* @param withAppend
|
|
245
|
+
* @param assocArrays
|
|
246
|
+
*/
|
|
247
|
+
function shallowMerge(overwrite = true, withAppend = false, ...assocArrays) {
|
|
248
|
+
let target = {};
|
|
249
|
+
new Es2019Array_1.Es2019Array(...assocArrays).map(arr => {
|
|
250
|
+
return { arr, keys: Object.keys(arr) };
|
|
251
|
+
}).forEach(({ arr, keys }) => {
|
|
252
|
+
keys.forEach(key => {
|
|
253
|
+
let toAssign = arr[key];
|
|
254
|
+
if (!Array.isArray(toAssign) && withAppend) {
|
|
255
|
+
toAssign = new Es2019Array_1.Es2019Array(...[toAssign]);
|
|
256
|
+
}
|
|
257
|
+
if (overwrite || !(target === null || target === void 0 ? void 0 : target[key])) {
|
|
258
|
+
if (!withAppend) {
|
|
259
|
+
target[key] = arr[key];
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
if ('undefined' == typeof (target === null || target === void 0 ? void 0 : target[key])) {
|
|
263
|
+
target[key] = toAssign;
|
|
264
|
+
}
|
|
265
|
+
else if (!Array.isArray(target[key])) {
|
|
266
|
+
let oldVal = target[key];
|
|
267
|
+
target[key] = new Es2019Array_1.Es2019Array(...[]);
|
|
268
|
+
target[key].push(oldVal);
|
|
269
|
+
target[key].push(...toAssign);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
target[key].push(...toAssign);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
return target;
|
|
279
|
+
}
|
|
280
|
+
exports.shallowMerge = shallowMerge;
|
|
281
|
+
//# sourceMappingURL=AssocArray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssocArray.js","sourceRoot":"","sources":["../src/main/typescript/AssocArray.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAQH,+CAA0C;AAE1C;;GAEG;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,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;qBACjC;yBAAM;wBACH,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;qBACjC;iBACR;aACJ;QACL,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAClB,CAAC;AA7BD,oCA6BC"}
|
package/target/Config.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Config = exports.CONFIG_ANY = exports.CONFIG_VALUE = void 0;
|
|
4
|
+
const Es2019Array_1 = require("./Es2019Array");
|
|
5
|
+
const Monad_1 = require("./Monad");
|
|
6
|
+
const Lang_1 = require("./Lang");
|
|
7
|
+
var objAssign = Lang_1.Lang.objAssign;
|
|
8
|
+
const AssocArray_1 = require("./AssocArray");
|
|
9
|
+
/**
|
|
10
|
+
* specialized value embedder
|
|
11
|
+
* for our Configuration
|
|
12
|
+
*/
|
|
13
|
+
class ConfigEntry extends Monad_1.ValueEmbedder {
|
|
14
|
+
constructor(rootElem, key, arrPos) {
|
|
15
|
+
super(rootElem, key);
|
|
16
|
+
this.arrPos = arrPos !== null && arrPos !== void 0 ? arrPos : -1;
|
|
17
|
+
}
|
|
18
|
+
get value() {
|
|
19
|
+
if (this.key == "" && this.arrPos >= 0) {
|
|
20
|
+
return this._value[this.arrPos];
|
|
21
|
+
}
|
|
22
|
+
else if (this.key && this.arrPos >= 0) {
|
|
23
|
+
return this._value[this.key][this.arrPos];
|
|
24
|
+
}
|
|
25
|
+
return this._value[this.key];
|
|
26
|
+
}
|
|
27
|
+
set value(val) {
|
|
28
|
+
if (this.key == "" && this.arrPos >= 0) {
|
|
29
|
+
this._value[this.arrPos] = val;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
else if (this.key && this.arrPos >= 0) {
|
|
33
|
+
this._value[this.key][this.arrPos] = val;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this._value[this.key] = val;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/*default value for absent*/
|
|
40
|
+
ConfigEntry.absent = ConfigEntry.fromNullable(null);
|
|
41
|
+
exports.CONFIG_VALUE = "__END_POINT__";
|
|
42
|
+
exports.CONFIG_ANY = "__ANY_POINT__";
|
|
43
|
+
/**
|
|
44
|
+
* Config, basically an optional wrapper for a json structure
|
|
45
|
+
* (not Side - effect free, since we can alter the internal config state
|
|
46
|
+
* without generating a new config), not sure if we should make it side - effect free
|
|
47
|
+
* since this would swallow a lot of performance and ram
|
|
48
|
+
*/
|
|
49
|
+
class Config extends Monad_1.Optional {
|
|
50
|
+
constructor(root, configDef) {
|
|
51
|
+
super(root);
|
|
52
|
+
this.configDef = configDef;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* shallow copy getter, copies only the first level, references the deeper nodes
|
|
56
|
+
* in a shared manner
|
|
57
|
+
*/
|
|
58
|
+
get shallowCopy() {
|
|
59
|
+
return this.shallowCopy$();
|
|
60
|
+
}
|
|
61
|
+
shallowCopy$() {
|
|
62
|
+
let ret = new Config({});
|
|
63
|
+
ret.shallowMerge(this.value);
|
|
64
|
+
return ret;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* deep copy, copies all config nodes
|
|
68
|
+
*/
|
|
69
|
+
get deepCopy() {
|
|
70
|
+
return this.deepCopy$();
|
|
71
|
+
}
|
|
72
|
+
deepCopy$() {
|
|
73
|
+
return new Config(objAssign({}, this.value));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* creates a config from an initial value or null
|
|
77
|
+
* @param value
|
|
78
|
+
*/
|
|
79
|
+
static fromNullable(value) {
|
|
80
|
+
return new Config(value);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* simple merge for the root configs
|
|
84
|
+
*/
|
|
85
|
+
shallowMerge(other, overwrite = true, withAppend = false) {
|
|
86
|
+
//shallow merge must be mutable so we have to remap
|
|
87
|
+
let newThis = (0, AssocArray_1.shallowMerge)(overwrite, withAppend, this.value, other.value);
|
|
88
|
+
if (Array.isArray(this._value)) {
|
|
89
|
+
this._value.length = 0;
|
|
90
|
+
this._value.push(...newThis);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
Object.getOwnPropertyNames(this._value).forEach(key => delete this._value[key]);
|
|
94
|
+
Object.getOwnPropertyNames(newThis).forEach(key => this._value[key] = newThis[key]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* assigns a single value as array, or appends it
|
|
99
|
+
* to an existing value mapping a single value to array
|
|
100
|
+
*
|
|
101
|
+
*
|
|
102
|
+
* usage myConfig.append("foobaz").value = "newValue"
|
|
103
|
+
* myConfig.append("foobaz").value = "newValue2"
|
|
104
|
+
*
|
|
105
|
+
* resulting in myConfig.foobaz == ["newValue, newValue2"]
|
|
106
|
+
*
|
|
107
|
+
* @param {string[]} accessPath
|
|
108
|
+
*/
|
|
109
|
+
append(...accessPath) {
|
|
110
|
+
return (0, AssocArray_1.append)(this._value, ...accessPath);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* appends to an existing entry (or extends into an array and appends)
|
|
114
|
+
* if the condition is met
|
|
115
|
+
* @param {boolean} condition
|
|
116
|
+
* @param {string[]} accessPath
|
|
117
|
+
*/
|
|
118
|
+
appendIf(condition, ...accessPath) {
|
|
119
|
+
return (0, AssocArray_1.appendIf)(condition, this._value, ...accessPath);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* assigns a new value on the given access path
|
|
123
|
+
* @param accessPath
|
|
124
|
+
*/
|
|
125
|
+
assign(...accessPath) {
|
|
126
|
+
return (0, AssocArray_1.assign)(this.value, ...accessPath);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* assign a value if the condition is set to true, otherwise skip it
|
|
130
|
+
*
|
|
131
|
+
* @param condition the condition, the access accessPath into the config
|
|
132
|
+
* @param accessPath
|
|
133
|
+
*/
|
|
134
|
+
assignIf(condition, ...accessPath) {
|
|
135
|
+
return (0, AssocArray_1.assignIf)(condition, this._value, ...accessPath);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* get if the access path is present (get is reserved as getter with a default, on the current path)
|
|
139
|
+
* TODO will be renamed to something more meaningful and deprecated, the name is ambiguous
|
|
140
|
+
* @param accessPath the access path
|
|
141
|
+
*/
|
|
142
|
+
getIf(...accessPath) {
|
|
143
|
+
this.assertAccessPath(...accessPath);
|
|
144
|
+
return this.getClass().fromNullable((0, AssocArray_1.resolve)(this.value, ...accessPath));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* gets the current node and if none is present returns a config with a default value
|
|
148
|
+
* @param defaultVal
|
|
149
|
+
*/
|
|
150
|
+
get(defaultVal) {
|
|
151
|
+
return this.getClass().fromNullable(super.get(defaultVal).value);
|
|
152
|
+
}
|
|
153
|
+
//empties the current config entry
|
|
154
|
+
delete(key) {
|
|
155
|
+
if (key in this.value) {
|
|
156
|
+
delete this.value[key];
|
|
157
|
+
}
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* converts the entire config into a json object
|
|
162
|
+
*/
|
|
163
|
+
toJson() {
|
|
164
|
+
return JSON.stringify(this.value);
|
|
165
|
+
}
|
|
166
|
+
getClass() {
|
|
167
|
+
return Config;
|
|
168
|
+
}
|
|
169
|
+
setVal(val) {
|
|
170
|
+
this._value = val;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* asserts the access path for a semi typed access
|
|
174
|
+
* @param accessPath
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
assertAccessPath(...accessPath) {
|
|
178
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
179
|
+
accessPath = this.preprocessKeys(...accessPath);
|
|
180
|
+
if (!this.configDef) {
|
|
181
|
+
//untyped
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const ERR_ACCESS_PATH = "Access Path to config invalid";
|
|
185
|
+
let currAccessPos = Monad_1.Optional.fromNullable(Object.keys(this.configDef).map(key => {
|
|
186
|
+
let ret = {};
|
|
187
|
+
ret[key] = this.configDef[key];
|
|
188
|
+
return ret;
|
|
189
|
+
}));
|
|
190
|
+
for (let cnt = 0; cnt < accessPath.length; cnt++) {
|
|
191
|
+
let currKey = this.keyVal(accessPath[cnt]);
|
|
192
|
+
let arrPos = this.arrayIndex(accessPath[cnt]);
|
|
193
|
+
//key index
|
|
194
|
+
if (this.isArray(arrPos)) {
|
|
195
|
+
if (currKey != "") {
|
|
196
|
+
currAccessPos = Array.isArray(currAccessPos.value) ?
|
|
197
|
+
Monad_1.Optional.fromNullable((_b = (_a = new Es2019Array_1.Es2019Array(...currAccessPos.value)
|
|
198
|
+
.find(item => {
|
|
199
|
+
var _a;
|
|
200
|
+
return !!((_a = item === null || item === void 0 ? void 0 : item[currKey]) !== null && _a !== void 0 ? _a : false);
|
|
201
|
+
})) === null || _a === void 0 ? void 0 : _a[currKey]) === null || _b === void 0 ? void 0 : _b[arrPos]) :
|
|
202
|
+
Monad_1.Optional.fromNullable((_e = (_d = (_c = currAccessPos.value) === null || _c === void 0 ? void 0 : _c[currKey]) === null || _d === void 0 ? void 0 : _d[arrPos]) !== null && _e !== void 0 ? _e : null);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
currAccessPos = (Array.isArray(currAccessPos.value)) ?
|
|
206
|
+
Monad_1.Optional.fromNullable((_f = currAccessPos.value) === null || _f === void 0 ? void 0 : _f[arrPos]) : Monad_1.Optional.absent;
|
|
207
|
+
}
|
|
208
|
+
//we noe store either the current array or the filtered look ahead to go further
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
//we now have an array and go further with a singular key
|
|
212
|
+
currAccessPos = (Array.isArray(currAccessPos.value)) ? Monad_1.Optional.fromNullable((_g = new Es2019Array_1.Es2019Array(...currAccessPos.value)
|
|
213
|
+
.find(item => {
|
|
214
|
+
var _a;
|
|
215
|
+
return !!((_a = item === null || item === void 0 ? void 0 : item[currKey]) !== null && _a !== void 0 ? _a : false);
|
|
216
|
+
})) === null || _g === void 0 ? void 0 : _g[currKey]) :
|
|
217
|
+
Monad_1.Optional.fromNullable((_j = (_h = currAccessPos.value) === null || _h === void 0 ? void 0 : _h[currKey]) !== null && _j !== void 0 ? _j : null);
|
|
218
|
+
}
|
|
219
|
+
if (!currAccessPos.isPresent()) {
|
|
220
|
+
throw Error(ERR_ACCESS_PATH);
|
|
221
|
+
}
|
|
222
|
+
if (currAccessPos.value == exports.CONFIG_ANY) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
isNoArray(arrPos) {
|
|
228
|
+
return arrPos == -1;
|
|
229
|
+
}
|
|
230
|
+
isArray(arrPos) {
|
|
231
|
+
return !this.isNoArray(arrPos);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.Config = Config;
|
|
235
|
+
//# sourceMappingURL=Config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../src/main/typescript/Config.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAC1C,mCAA8D;AAC9D,iCAA4B;AAC5B,IAAO,SAAS,GAAG,WAAI,CAAC,SAAS,CAAC;AAClC,6CAAuF;AAEvF;;;GAGG;AACH,MAAM,WAAe,SAAQ,qBAAgB;IAUzC,YAAY,QAAa,EAAE,GAAQ,EAAE,MAAe;QAChD,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAErB,IAAI,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK;QACL,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,IAAI,IAAI,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5B,MAAM,KAAK,CAAC,eAAe,CAAC,CAAA;aAC/B;YACD,IAAI,aAAa,CAAC,KAAK,IAAI,kBAAU,EAAE;gBACnC,OAAO;aACV;SACJ;IACL,CAAC;IAEO,SAAS,CAAC,MAAc;QAC5B,OAAO,MAAM,IAAI,CAAC,CAAC,CAAC;IACxB,CAAC;IAEO,OAAO,CAAC,MAAc;QAC1B,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;CAEJ;AA7MD,wBA6MC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExpiringCrypto = exports.JSONCrypto = void 0;
|
|
4
|
+
const SourcesCollectors_1 = require("./SourcesCollectors");
|
|
5
|
+
const Stream_1 = require("./Stream");
|
|
6
|
+
/*
|
|
7
|
+
* Some crypto implementations which might come in handy
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* basic json stringify encryption impl
|
|
11
|
+
* this does not really full encryption except for a standard json stringyfywith an encapsulation json
|
|
12
|
+
*
|
|
13
|
+
* the return value resembles:
|
|
14
|
+
* <pre>
|
|
15
|
+
* {
|
|
16
|
+
* encryptedData: <data as string>
|
|
17
|
+
* }
|
|
18
|
+
* </pre>
|
|
19
|
+
*/
|
|
20
|
+
class JSONCrypto {
|
|
21
|
+
decode(data) {
|
|
22
|
+
if (data === null || data === void 0 ? void 0 : data.encryptedData) {
|
|
23
|
+
return JSON.parse(data.encryptedData);
|
|
24
|
+
}
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
encode(data) {
|
|
28
|
+
return {
|
|
29
|
+
encryptedData: JSON.stringify(data)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.JSONCrypto = JSONCrypto;
|
|
34
|
+
/**
|
|
35
|
+
* a class with timeout functionality which blocks decodes after a certain period of time
|
|
36
|
+
* if the message is not decoded by then
|
|
37
|
+
* We use hash as identifier generation after encryption to make sure
|
|
38
|
+
* a trace was possible
|
|
39
|
+
*
|
|
40
|
+
* The idea behind this is to have a generic wrapper which allows messages with dynamic encryption
|
|
41
|
+
* where keys/salts only exist for a certain period of time before expiring!
|
|
42
|
+
* That way someone who implements such a scheme does not have to take care about the bookeeping mechanisms!
|
|
43
|
+
* Or you can use crypto mechanisms which do not have expiring keys and still expire them automatically
|
|
44
|
+
*
|
|
45
|
+
* I will leave it up to the system integrator to provide a rotating crypto class, because this is highly
|
|
46
|
+
* implementation dependent. But it helps to have a wrapper!
|
|
47
|
+
*/
|
|
48
|
+
class ExpiringCrypto {
|
|
49
|
+
/**
|
|
50
|
+
* @param timeout timeout in miliseconds until a message is expired
|
|
51
|
+
* @param parentCrypto the embedded decorated crypto algorithm
|
|
52
|
+
* @param hashSum hashshum implementation to generate a hash
|
|
53
|
+
*/
|
|
54
|
+
constructor(timeout, parentCrypto, hashSum) {
|
|
55
|
+
this.timeout = timeout;
|
|
56
|
+
this.parentCrypto = parentCrypto;
|
|
57
|
+
this.hashSum = hashSum;
|
|
58
|
+
this.gcCycleCnt = 0;
|
|
59
|
+
this.storedMessages = {};
|
|
60
|
+
this.lastCall = 0;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* decode implementation with a timeout hook install
|
|
64
|
+
* @param data
|
|
65
|
+
*/
|
|
66
|
+
decode(data) {
|
|
67
|
+
//if ((this.gcCycleCnt++ % ExpiringCrypto.MAX_GC_CYCLES) === 0) {
|
|
68
|
+
var _a;
|
|
69
|
+
const currTime = new Date().getTime();
|
|
70
|
+
if (this.gcLimitReached(currTime)) {
|
|
71
|
+
this.storedMessages = Stream_1.LazyStream
|
|
72
|
+
.ofAssoc(this.storedMessages)
|
|
73
|
+
.filter(data => data[1] >= currTime)
|
|
74
|
+
.collect(new SourcesCollectors_1.AssocArrayCollector());
|
|
75
|
+
}
|
|
76
|
+
this.lastCall = currTime;
|
|
77
|
+
let rotatingEncoded = this.hashSum.encode(data);
|
|
78
|
+
if (!((_a = this.storedMessages) === null || _a === void 0 ? void 0 : _a[rotatingEncoded.toString()])) {
|
|
79
|
+
throw Error("An item was tried to be decryted which either was expired or invalid");
|
|
80
|
+
}
|
|
81
|
+
return this.parentCrypto.decode(data);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* trigger function to determine whether the gc needs to cycle again, this is either time or call based
|
|
85
|
+
* the gc itself collects only on expiration dates
|
|
86
|
+
* The idea is to run this operation only occasionally because it is costly
|
|
87
|
+
* We also could have used timeouts etc.. but those would need shutdown/destroy cleanups
|
|
88
|
+
*
|
|
89
|
+
* @param currTime
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
gcLimitReached(currTime) {
|
|
93
|
+
return (this.lastCall + this.timeout) < currTime || ((++this.gcCycleCnt) % ExpiringCrypto.MAX_GC_CYCLES == 0);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* encode with a timeout hook installed
|
|
97
|
+
* calls the encode of the delegated object
|
|
98
|
+
*
|
|
99
|
+
* @param data
|
|
100
|
+
*/
|
|
101
|
+
encode(data) {
|
|
102
|
+
let encoded = this.parentCrypto.encode(data);
|
|
103
|
+
//ok use the hashsum really only to store expirations, theoretically there could be a second message which does not invalidate the first one
|
|
104
|
+
//but this is very unlikely unless a message is sent over and over again, in this case we have a timeout extension anyway!
|
|
105
|
+
let rotatingEncoded = this.hashSum.encode(encoded);
|
|
106
|
+
this.storedMessages[rotatingEncoded.toString()] = (new Date().getTime()) + this.timeout;
|
|
107
|
+
return encoded;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.ExpiringCrypto = ExpiringCrypto;
|
|
111
|
+
ExpiringCrypto.MAX_GC_CYCLES = 10;
|
|
112
|
+
//# sourceMappingURL=CryptoExtensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoExtensions.js","sourceRoot":"","sources":["../src/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