@blazedpath/commons 0.0.4
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/README.md +3 -0
- package/blz-base/health/index.js +215 -0
- package/blz-base/index.js +1466 -0
- package/blz-cache/LruCache.js +44 -0
- package/blz-cache/index.js +29 -0
- package/blz-config/index.js +434 -0
- package/blz-core/index.js +364 -0
- package/blz-cryptography/index.js +54 -0
- package/blz-datetimes/index.js +356 -0
- package/blz-file/example.dat +2545 -0
- package/blz-file/fileService.js +205 -0
- package/blz-file/index.js +94 -0
- package/blz-file/index.test.js +31 -0
- package/blz-file/lab.js +33 -0
- package/blz-hazelcast/index.js +189 -0
- package/blz-hazelcast/lib/credentials.js +25 -0
- package/blz-hazelcast/lib/credentialsFactory.js +12 -0
- package/blz-hazelcast/lib/hazelcastCache.js +234 -0
- package/blz-iterable/index.js +446 -0
- package/blz-json-schema/index.js +11 -0
- package/blz-jwt/index.js +121 -0
- package/blz-kafka/index.js +522 -0
- package/blz-math/index.js +131 -0
- package/blz-mongodb/index.js +326 -0
- package/blz-rds/__test__/scape.test.js +58 -0
- package/blz-rds/blz-rds-executor.js +578 -0
- package/blz-rds/blz-rds-helper.js +310 -0
- package/blz-rds/commands/core/add.js +13 -0
- package/blz-rds/commands/core/and.js +18 -0
- package/blz-rds/commands/core/asc.js +10 -0
- package/blz-rds/commands/core/avg.js +10 -0
- package/blz-rds/commands/core/column-ref.js +8 -0
- package/blz-rds/commands/core/count-distinct.js +10 -0
- package/blz-rds/commands/core/count.js +10 -0
- package/blz-rds/commands/core/decimal.js +8 -0
- package/blz-rds/commands/core/desc.js +10 -0
- package/blz-rds/commands/core/distinct.js +10 -0
- package/blz-rds/commands/core/divide.js +11 -0
- package/blz-rds/commands/core/embedded-exists.js +17 -0
- package/blz-rds/commands/core/embedded-select.js +17 -0
- package/blz-rds/commands/core/equals.js +9 -0
- package/blz-rds/commands/core/false.js +8 -0
- package/blz-rds/commands/core/greater-or-equal.js +9 -0
- package/blz-rds/commands/core/greater.js +9 -0
- package/blz-rds/commands/core/in.js +9 -0
- package/blz-rds/commands/core/integer.js +8 -0
- package/blz-rds/commands/core/is-not-null.js +11 -0
- package/blz-rds/commands/core/is-null-or-value.js +10 -0
- package/blz-rds/commands/core/is-null.js +11 -0
- package/blz-rds/commands/core/less-or-equal.js +9 -0
- package/blz-rds/commands/core/less-unary.js +12 -0
- package/blz-rds/commands/core/less.js +9 -0
- package/blz-rds/commands/core/like.js +12 -0
- package/blz-rds/commands/core/max.js +10 -0
- package/blz-rds/commands/core/min.js +10 -0
- package/blz-rds/commands/core/multiply.js +13 -0
- package/blz-rds/commands/core/not-equals.js +9 -0
- package/blz-rds/commands/core/not-in.js +9 -0
- package/blz-rds/commands/core/not.js +13 -0
- package/blz-rds/commands/core/null.js +8 -0
- package/blz-rds/commands/core/nvl.js +11 -0
- package/blz-rds/commands/core/or.js +13 -0
- package/blz-rds/commands/core/parameter.js +34 -0
- package/blz-rds/commands/core/remainder.js +16 -0
- package/blz-rds/commands/core/string.js +8 -0
- package/blz-rds/commands/core/subtract.js +13 -0
- package/blz-rds/commands/core/sum.js +10 -0
- package/blz-rds/commands/core/true.js +8 -0
- package/blz-rds/commands/core/tuple.js +13 -0
- package/blz-rds/commands/datetimes/add-days.js +11 -0
- package/blz-rds/commands/datetimes/add-hours.js +11 -0
- package/blz-rds/commands/datetimes/add-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/add-minutes.js +11 -0
- package/blz-rds/commands/datetimes/add-months.js +11 -0
- package/blz-rds/commands/datetimes/add-seconds.js +11 -0
- package/blz-rds/commands/datetimes/add-years.js +11 -0
- package/blz-rds/commands/datetimes/date-diff.js +11 -0
- package/blz-rds/commands/datetimes/date.js +12 -0
- package/blz-rds/commands/datetimes/datetime-diff.js +11 -0
- package/blz-rds/commands/datetimes/datetime.js +15 -0
- package/blz-rds/commands/datetimes/day.js +10 -0
- package/blz-rds/commands/datetimes/hour.js +10 -0
- package/blz-rds/commands/datetimes/millisecond.js +10 -0
- package/blz-rds/commands/datetimes/minute.js +10 -0
- package/blz-rds/commands/datetimes/month-text.js +10 -0
- package/blz-rds/commands/datetimes/month.js +10 -0
- package/blz-rds/commands/datetimes/now.js +9 -0
- package/blz-rds/commands/datetimes/second.js +10 -0
- package/blz-rds/commands/datetimes/subtract-days.js +11 -0
- package/blz-rds/commands/datetimes/subtract-hours.js +11 -0
- package/blz-rds/commands/datetimes/subtract-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/subtract-minutes.js +11 -0
- package/blz-rds/commands/datetimes/subtract-seconds.js +11 -0
- package/blz-rds/commands/datetimes/time-diff.js +11 -0
- package/blz-rds/commands/datetimes/time.js +13 -0
- package/blz-rds/commands/datetimes/today.js +9 -0
- package/blz-rds/commands/datetimes/week-day-text.js +10 -0
- package/blz-rds/commands/datetimes/week-day.js +10 -0
- package/blz-rds/commands/datetimes/week.js +10 -0
- package/blz-rds/commands/datetimes/year.js +10 -0
- package/blz-rds/commands/math/abs.js +10 -0
- package/blz-rds/commands/math/acos.js +10 -0
- package/blz-rds/commands/math/asin.js +10 -0
- package/blz-rds/commands/math/atan.js +10 -0
- package/blz-rds/commands/math/atan2.js +11 -0
- package/blz-rds/commands/math/ceil.js +10 -0
- package/blz-rds/commands/math/cos.js +10 -0
- package/blz-rds/commands/math/cosh.js +10 -0
- package/blz-rds/commands/math/exp.js +10 -0
- package/blz-rds/commands/math/floor.js +10 -0
- package/blz-rds/commands/math/log.js +18 -0
- package/blz-rds/commands/math/log10.js +10 -0
- package/blz-rds/commands/math/pow.js +11 -0
- package/blz-rds/commands/math/random.js +9 -0
- package/blz-rds/commands/math/round.js +18 -0
- package/blz-rds/commands/math/sign.js +10 -0
- package/blz-rds/commands/math/sin.js +10 -0
- package/blz-rds/commands/math/sinh.js +10 -0
- package/blz-rds/commands/math/sqrt.js +10 -0
- package/blz-rds/commands/math/tan.js +10 -0
- package/blz-rds/commands/math/tanh.js +10 -0
- package/blz-rds/commands/math/trunc.js +18 -0
- package/blz-rds/commands/strings/concat.js +20 -0
- package/blz-rds/commands/strings/contains.js +12 -0
- package/blz-rds/commands/strings/ends-with.js +12 -0
- package/blz-rds/commands/strings/index-of.js +11 -0
- package/blz-rds/commands/strings/is-null-or-empty.js +11 -0
- package/blz-rds/commands/strings/is-null-or-white-space.js +11 -0
- package/blz-rds/commands/strings/join.js +22 -0
- package/blz-rds/commands/strings/last-index-of.js +11 -0
- package/blz-rds/commands/strings/length.js +10 -0
- package/blz-rds/commands/strings/pad-left.js +20 -0
- package/blz-rds/commands/strings/pad-right.js +20 -0
- package/blz-rds/commands/strings/replace.js +12 -0
- package/blz-rds/commands/strings/starts-with.js +12 -0
- package/blz-rds/commands/strings/substring.js +12 -0
- package/blz-rds/commands/strings/to-lower.js +10 -0
- package/blz-rds/commands/strings/to-upper.js +10 -0
- package/blz-rds/commands/strings/trim-end.js +10 -0
- package/blz-rds/commands/strings/trim-start.js +10 -0
- package/blz-rds/commands/strings/trim.js +10 -0
- package/blz-rds/index.js +744 -0
- package/blz-rds-mysql/base.js +857 -0
- package/blz-rds-mysql/connection-manager.js +129 -0
- package/blz-rds-mysql/execute-bulk-insert.js +35 -0
- package/blz-rds-mysql/execute-bulk-merge.js +45 -0
- package/blz-rds-mysql/execute-non-query.js +34 -0
- package/blz-rds-mysql/execute-query.js +50 -0
- package/blz-rds-mysql/index.js +41 -0
- package/blz-rds-mysql/stored-procedure.js +207 -0
- package/blz-rds-mysql/syntaxis.json +114 -0
- package/blz-rds-mysqlx/base.js +846 -0
- package/blz-rds-mysqlx/connection-manager.js +141 -0
- package/blz-rds-mysqlx/execute-bulk-insert.js +35 -0
- package/blz-rds-mysqlx/execute-bulk-merge.js +45 -0
- package/blz-rds-mysqlx/execute-non-query.js +29 -0
- package/blz-rds-mysqlx/execute-query.js +39 -0
- package/blz-rds-mysqlx/index.js +41 -0
- package/blz-rds-mysqlx/stored-procedure.js +179 -0
- package/blz-rds-mysqlx/syntaxis.json +105 -0
- package/blz-rds-oracle/index.js +540 -0
- package/blz-rds-oracle/syntaxis.json +112 -0
- package/blz-rds-postgres/base.js +861 -0
- package/blz-rds-postgres/connection-manager.js +225 -0
- package/blz-rds-postgres/execute-bulk-insert.js +81 -0
- package/blz-rds-postgres/execute-bulk-merge.js +93 -0
- package/blz-rds-postgres/execute-non-query.js +23 -0
- package/blz-rds-postgres/execute-query.js +37 -0
- package/blz-rds-postgres/index.js +41 -0
- package/blz-rds-postgres/result-set.js +51 -0
- package/blz-rds-postgres/stored-procedure.js +116 -0
- package/blz-rds-postgres/syntaxis.json +114 -0
- package/blz-redis/index.js +217 -0
- package/blz-redis/lib/redisCache.js +265 -0
- package/blz-regex/index.js +25 -0
- package/blz-security/.eslintrc.js +15 -0
- package/blz-security/__test__/AuthorizationKpn.yaml +1043 -0
- package/blz-security/__test__/FinancingSetting.yaml +177 -0
- package/blz-security/__test__/KpnConfigPortal.yaml +330 -0
- package/blz-security/__test__/OrderManagement.yaml +5190 -0
- package/blz-security/__test__/Security.yaml +128 -0
- package/blz-security/__test__/autorization.test.js +105 -0
- package/blz-security/__test__/orderManagement.test.js +26 -0
- package/blz-security/__test__/secureUrl.test.js +79 -0
- package/blz-security/__test__/solveMergeRule.test.js +109 -0
- package/blz-security/__test__/sqlInjectionGuard.test.js +203 -0
- package/blz-security/__test__/xssGuard.test.js +204 -0
- package/blz-security/authorizationService.js +536 -0
- package/blz-security/config/global.js +8 -0
- package/blz-security/config/welcome +8 -0
- package/blz-security/doc/README.md +75 -0
- package/blz-security/filescanner/index.js +46 -0
- package/blz-security/helpers/consts.js +229 -0
- package/blz-security/helpers/utils.js +267 -0
- package/blz-security/implementations/cache.js +90 -0
- package/blz-security/implementations/oidc.js +404 -0
- package/blz-security/implementations/pkceCacheStore.js +23 -0
- package/blz-security/implementations/saml.js +10 -0
- package/blz-security/implementations/uma.js +63 -0
- package/blz-security/implementations/webAuthn.js +9 -0
- package/blz-security/implementations/wstg.js +72 -0
- package/blz-security/index.js +77 -0
- package/blz-security/lab/index.js +27 -0
- package/blz-security/middleware/HapiServerAzureAd.js +641 -0
- package/blz-security/middleware/HapiServerKeycloak.js +840 -0
- package/blz-security/middleware/HapiServerSimToken.js +247 -0
- package/blz-security/middleware/hapi.js +515 -0
- package/blz-security/middleware/hapiServer.js +974 -0
- package/blz-security/navigationMemoryRepository.js +15 -0
- package/blz-security/navigationMongoDbRepository.js +73 -0
- package/blz-security/secureUrlService.js +47 -0
- package/blz-security/securityService.js +409 -0
- package/blz-security/sqlInjectionGuard.js +162 -0
- package/blz-security/templates/forbidden.html +0 -0
- package/blz-security/templates/session-iframe-azure-ad.html +7 -0
- package/blz-security/templates/session-iframe.html +73 -0
- package/blz-security/templates/unauthorized.html +1 -0
- package/blz-security/xssGuard.js +87 -0
- package/blz-strings/index.js +167 -0
- package/blz-uuid/index.js +7 -0
- package/blz-yaml/index.js +19 -0
- package/index.js +84 -0
- package/package.json +97 -0
- package/process-managers/index.js +422 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
const { Client } = require('hazelcast-client');
|
|
2
|
+
const genericPool = require('generic-pool');
|
|
3
|
+
|
|
4
|
+
// Connection Pool cache
|
|
5
|
+
let poolsByName = {};
|
|
6
|
+
|
|
7
|
+
const CACHE_TYPE = {
|
|
8
|
+
MAP: 'map',
|
|
9
|
+
LIST: 'list'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function createHazelcastClient(config) {
|
|
13
|
+
return {
|
|
14
|
+
mapGet: function(name, key) {
|
|
15
|
+
return send(config, name, CACHE_TYPE.MAP, 'get', key);
|
|
16
|
+
},
|
|
17
|
+
mapGetAll: function(name, keys) {
|
|
18
|
+
return send(config, name, CACHE_TYPE.MAP, 'getAll', keys);
|
|
19
|
+
},
|
|
20
|
+
mapSet: function(name, key, value, ttl) {
|
|
21
|
+
if (ttl) {
|
|
22
|
+
return send(config, name, CACHE_TYPE.MAP, 'set', key, value, ttl);
|
|
23
|
+
} else {
|
|
24
|
+
return send(config, name, CACHE_TYPE.MAP, 'set', key, value);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
mapSetAll: function(name, data) {
|
|
28
|
+
return send(config, name, CACHE_TYPE.MAP, 'setAll', data);
|
|
29
|
+
},
|
|
30
|
+
mapDelete: function(name, key) {
|
|
31
|
+
return send(config, name, CACHE_TYPE.MAP, 'delete', key);
|
|
32
|
+
},
|
|
33
|
+
mapSetTtl: function(name, key, ttl) {
|
|
34
|
+
return send(config, name, CACHE_TYPE.MAP, 'setTtl', key, ttl);
|
|
35
|
+
},
|
|
36
|
+
mapGetEntryView: function(name, key) {
|
|
37
|
+
return send(config, name, CACHE_TYPE.MAP, 'getEntryView', key);
|
|
38
|
+
},
|
|
39
|
+
mapContainsKey: function(name, key) {
|
|
40
|
+
return send(config, name, CACHE_TYPE.MAP, 'containsKey', key);
|
|
41
|
+
},
|
|
42
|
+
mapKeySet: function(name) {
|
|
43
|
+
return send(config, name, CACHE_TYPE.MAP, 'keySet');
|
|
44
|
+
},
|
|
45
|
+
mapValues: async function(name) {
|
|
46
|
+
const values = await send(config, name, CACHE_TYPE.MAP, 'values');
|
|
47
|
+
return values.toArray();
|
|
48
|
+
},
|
|
49
|
+
mapEntrySet: function(name) {
|
|
50
|
+
return send(config, name, CACHE_TYPE.MAP, 'entrySet');
|
|
51
|
+
},
|
|
52
|
+
mapSize: function(name) {
|
|
53
|
+
return send(config, name, CACHE_TYPE.MAP, 'size');
|
|
54
|
+
},
|
|
55
|
+
mapClear: function(name) {
|
|
56
|
+
return send(config, name, CACHE_TYPE.MAP, 'clear');
|
|
57
|
+
},
|
|
58
|
+
mapDestroy: function(name) {
|
|
59
|
+
return send(config, name, CACHE_TYPE.MAP, 'destroy');
|
|
60
|
+
},
|
|
61
|
+
listGet: function(name, index) {
|
|
62
|
+
return send(config, name, CACHE_TYPE.LIST, 'get', index);
|
|
63
|
+
},
|
|
64
|
+
listAdd: function(name, element) {
|
|
65
|
+
return send(config, name, CACHE_TYPE.LIST, 'add', element);
|
|
66
|
+
},
|
|
67
|
+
listAddAt: function(name, index, element) {
|
|
68
|
+
return send(config, name, CACHE_TYPE.LIST, 'addAt', index, element);
|
|
69
|
+
},
|
|
70
|
+
listAddAll: function(name, elements) {
|
|
71
|
+
return send(config, name, CACHE_TYPE.LIST, 'addAll', elements);
|
|
72
|
+
},
|
|
73
|
+
listRemove: function(name, element) {
|
|
74
|
+
return send(config, name, CACHE_TYPE.LIST, 'remove', element);
|
|
75
|
+
},
|
|
76
|
+
listRemoveAt: function(name, index) {
|
|
77
|
+
return send(config, name, CACHE_TYPE.LIST, 'removeAt', index);
|
|
78
|
+
},
|
|
79
|
+
listContains: function(name, element) {
|
|
80
|
+
return send(config, name, CACHE_TYPE.LIST, 'contains', element);
|
|
81
|
+
},
|
|
82
|
+
listIndexOf: function(name, element) {
|
|
83
|
+
return send(config, name, CACHE_TYPE.LIST, 'indexOf', element);
|
|
84
|
+
},
|
|
85
|
+
listSize: function(name) {
|
|
86
|
+
return send(config, name, CACHE_TYPE.LIST, 'size');
|
|
87
|
+
},
|
|
88
|
+
listClear: function(name) {
|
|
89
|
+
return send(config, name, CACHE_TYPE.LIST, 'clear');
|
|
90
|
+
},
|
|
91
|
+
listDestroy: function(name) {
|
|
92
|
+
return send(config, name, CACHE_TYPE.LIST, 'destroy');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function getConnection(config) {
|
|
98
|
+
if (!config.pool) {
|
|
99
|
+
return createConnection(config);
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
return await getPool(config).acquire();
|
|
103
|
+
} catch (err) {
|
|
104
|
+
throw error('HazelcastPoolAcquireError', { connectionName: config.connectionName }, err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function createConnection(config) {
|
|
109
|
+
let hz = null;
|
|
110
|
+
const lifecycleListener = (state) => {
|
|
111
|
+
if (state === 'DISCONNECTED') {
|
|
112
|
+
hz.active = false;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
config.connectionOptions.lifecycleListeners = [lifecycleListener];
|
|
117
|
+
|
|
118
|
+
return Client.newHazelcastClient(config.connectionOptions)
|
|
119
|
+
.then((hazelcastClient) => {
|
|
120
|
+
hazelcastClient.pool = config.pool;
|
|
121
|
+
hazelcastClient.connectionName = config.connectionName;
|
|
122
|
+
hazelcastClient.active = true;
|
|
123
|
+
hz = hazelcastClient;
|
|
124
|
+
return hz;
|
|
125
|
+
})
|
|
126
|
+
.catch((err) => {
|
|
127
|
+
throw error('HazelcastConnectionError', { connectionName: config.connectionName }, err);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function send(config, name, type, command, ...args) {
|
|
132
|
+
let connection = null;
|
|
133
|
+
try {
|
|
134
|
+
connection = await getConnection(config);
|
|
135
|
+
return await executeCommand(connection, name, type, command, ...args);
|
|
136
|
+
} catch (err) {
|
|
137
|
+
throw error('HazelcastError', null, err);
|
|
138
|
+
} finally {
|
|
139
|
+
if (connection) {
|
|
140
|
+
closeConnection(connection);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function executeCommand(connection, name, type, command, ...args) {
|
|
146
|
+
const cache = await getCache(connection, name, type);
|
|
147
|
+
return cache[command](...args);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function getCache(connection, name, type) {
|
|
151
|
+
let cache = null;
|
|
152
|
+
switch (type) {
|
|
153
|
+
case CACHE_TYPE.MAP:
|
|
154
|
+
cache = connection.getMap(name);
|
|
155
|
+
break;
|
|
156
|
+
case CACHE_TYPE.LIST:
|
|
157
|
+
cache = connection.getList(name);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
return cache;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function closeConnection(connection) {
|
|
164
|
+
if (!connection.pool) {
|
|
165
|
+
return destroyConnection(connection);
|
|
166
|
+
} else {
|
|
167
|
+
return getPool({connectionName: connection.connectionName}).release(connection);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function destroyConnection(connection) {
|
|
172
|
+
connection.shutdown();
|
|
173
|
+
connection.active = false;
|
|
174
|
+
return Promise.resolve();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function getPool(config) {
|
|
178
|
+
let key = config.connectionName;
|
|
179
|
+
let pool = poolsByName[key];
|
|
180
|
+
if (pool) {
|
|
181
|
+
return pool;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// Create pool using a factory object
|
|
185
|
+
const factory = {
|
|
186
|
+
create: async function() {
|
|
187
|
+
try {
|
|
188
|
+
const connection = await createConnection(config);
|
|
189
|
+
return connection;
|
|
190
|
+
} catch (err) {
|
|
191
|
+
return await new Promise(function (resolve, reject) {
|
|
192
|
+
setTimeout(() => {
|
|
193
|
+
reject(err);
|
|
194
|
+
}, config.poolRetryDelay);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
destroy: function(connection) {
|
|
199
|
+
return destroyConnection(connection);
|
|
200
|
+
},
|
|
201
|
+
validate: function(connection) {
|
|
202
|
+
return Promise.resolve(connection.active);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const opts = {
|
|
207
|
+
max: config.poolMax,
|
|
208
|
+
min: config.poolMin,
|
|
209
|
+
testOnBorrow: true,
|
|
210
|
+
acquireTimeoutMillis: config.poolAcquireTimeout || 10000
|
|
211
|
+
//autostart: false
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
pool = genericPool.createPool(factory, opts);
|
|
215
|
+
//pool.start();
|
|
216
|
+
pool.connectionName = config.connectionName;
|
|
217
|
+
poolsByName[key] = pool;
|
|
218
|
+
return pool;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function error(code, data, innerError) {
|
|
223
|
+
let err = new Error();
|
|
224
|
+
err.code = code;
|
|
225
|
+
if (data)
|
|
226
|
+
err.data = data;
|
|
227
|
+
if (innerError)
|
|
228
|
+
err.innerError = innerError;
|
|
229
|
+
return err;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
module.exports = {
|
|
233
|
+
createHazelcastClient: createHazelcastClient
|
|
234
|
+
}
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
errorUndefinedArgument: function( argName ) {
|
|
3
|
+
const err = new Error();
|
|
4
|
+
err.code = 'UndefinedArgument';
|
|
5
|
+
err.data = { argName: argName };
|
|
6
|
+
return err;
|
|
7
|
+
},
|
|
8
|
+
compare: function( value1, value2 ) { // TODO: Sort require for objects
|
|
9
|
+
if( value1 === null && value2 === null ) return 0;
|
|
10
|
+
if( value1 === null && value2 !== null ) return -1;
|
|
11
|
+
if( value1 !== null && value2 === null ) return 1;
|
|
12
|
+
|
|
13
|
+
const value1Type = toString.call( value1 );
|
|
14
|
+
const value2Type = toString.call( value2 );
|
|
15
|
+
let value1ToCompare = null;
|
|
16
|
+
let value2ToCompare = null;
|
|
17
|
+
if ((value1Type === '[object String]' && value2Type === '[object String]') ||
|
|
18
|
+
(value1Type === '[object Number]' && value2Type === '[object Number]')) {
|
|
19
|
+
value1ToCompare = value1;
|
|
20
|
+
value2ToCompare = value2;
|
|
21
|
+
}
|
|
22
|
+
else if( value1Type === '[object Boolean]' && value2Type === '[object Boolean]' ) {
|
|
23
|
+
value1ToCompare = value1 ? 1 : 0;
|
|
24
|
+
value2ToCompare = value2 ? 1 : 0;
|
|
25
|
+
}
|
|
26
|
+
else if( value1Type === '[object Date]' && value2Type === '[object Date]' ) {
|
|
27
|
+
value1ToCompare = value1.getTime();
|
|
28
|
+
value2ToCompare = value2.getTime();
|
|
29
|
+
}
|
|
30
|
+
else if( value1Type === '[object Object]' && value2Type === '[object Object]' ) {
|
|
31
|
+
value1ToCompare = JSON.stringify( value1 );
|
|
32
|
+
value2ToCompare = JSON.stringify( value2 );
|
|
33
|
+
}
|
|
34
|
+
else if( value1Type === '[object Array]' && value2Type === '[object Array]' ) {
|
|
35
|
+
let result = this.compare( value1.length, value2.length );
|
|
36
|
+
if( result !== 0 )
|
|
37
|
+
return result;
|
|
38
|
+
for( let i = 0; i < value1.length; ++i ) {
|
|
39
|
+
const item1 = value1[ i ];
|
|
40
|
+
const item2 = value2[ i ];
|
|
41
|
+
result = this.compare( item1, item2 );
|
|
42
|
+
if( result !== 0 )
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const getValueToCompare = ( valueType, value ) => {
|
|
49
|
+
switch( valueType ) {
|
|
50
|
+
case '[object String]' : return value
|
|
51
|
+
case '[object Number]' : return value.toString()
|
|
52
|
+
case '[object Boolean]' : return value ? '1' : '0'
|
|
53
|
+
case '[object Date]' : return value.toJSON()
|
|
54
|
+
default : return value.toString()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
value1ToCompare = getValueToCompare( value1Type, value1 )
|
|
60
|
+
value2ToCompare = getValueToCompare( value2Type, value2 )
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if( value1ToCompare === value2ToCompare ) return 0;
|
|
64
|
+
else if( value1ToCompare < value2ToCompare ) return -1;
|
|
65
|
+
else if( value1ToCompare > value2ToCompare ) return 1;
|
|
66
|
+
else return null;
|
|
67
|
+
|
|
68
|
+
},
|
|
69
|
+
all: function( list, fnCondition ) {
|
|
70
|
+
if( list === null ) return false;
|
|
71
|
+
|
|
72
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
73
|
+
const item = list[ i ];
|
|
74
|
+
if( !(fnCondition( item )) )
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
},
|
|
79
|
+
any: function( list, fnCondition ) {
|
|
80
|
+
if( list === null ) return false;
|
|
81
|
+
|
|
82
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
83
|
+
const item = list[ i ];
|
|
84
|
+
if( fnCondition( item ) )
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
},
|
|
89
|
+
avg: function( list, fnSelection ) {
|
|
90
|
+
if( list === null ) return null;
|
|
91
|
+
|
|
92
|
+
let totalSum = 0;
|
|
93
|
+
let totalCount = 0;
|
|
94
|
+
if( fnSelection ) {
|
|
95
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
96
|
+
const item = list[ i ];
|
|
97
|
+
const value = fnSelection( item );
|
|
98
|
+
if( value !== null ) {
|
|
99
|
+
totalSum += value;
|
|
100
|
+
totalCount++;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
106
|
+
const value = list[ i ];
|
|
107
|
+
if( value !== null ) {
|
|
108
|
+
totalSum += value;
|
|
109
|
+
totalCount++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return totalSum / totalCount;
|
|
114
|
+
},
|
|
115
|
+
concatList: function() {
|
|
116
|
+
if( arguments.length === 0 ) return null
|
|
117
|
+
if( arguments.length === 1 && arguments[ 0 ] === null ) return null
|
|
118
|
+
return Array.from( arguments ).filter( list => list !== null ).flat()
|
|
119
|
+
},
|
|
120
|
+
count: function( list ) {
|
|
121
|
+
if( list === null ) return null;
|
|
122
|
+
return list.length;
|
|
123
|
+
},
|
|
124
|
+
distinct: function( list, fnSelection ) {
|
|
125
|
+
if( list === null ) return null;
|
|
126
|
+
|
|
127
|
+
const resultArray = [];
|
|
128
|
+
if( fnSelection ) {
|
|
129
|
+
const keys = [];
|
|
130
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
131
|
+
const item = list[ i ];
|
|
132
|
+
const key = fnSelection( item );
|
|
133
|
+
if( keys.indexOf( key ) === -1 ) {
|
|
134
|
+
keys.push( key );
|
|
135
|
+
resultArray.push( item );
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
141
|
+
const item = list[ i ];
|
|
142
|
+
if( resultArray.indexOf( item ) === -1 )
|
|
143
|
+
resultArray.push( item );
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return resultArray;
|
|
147
|
+
},
|
|
148
|
+
elementAt: function( list, index ) {
|
|
149
|
+
if( list === null ) return null
|
|
150
|
+
|
|
151
|
+
const result = list[ index ]
|
|
152
|
+
return result === undefined ? null : result
|
|
153
|
+
},
|
|
154
|
+
getSelections: function( list, fnSelection ) {
|
|
155
|
+
if( !fnSelection ) return list
|
|
156
|
+
|
|
157
|
+
const selections = new Array( list.length )
|
|
158
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
159
|
+
selections[ i ] = fnSelection( list[ i ] )
|
|
160
|
+
}
|
|
161
|
+
return selections
|
|
162
|
+
},
|
|
163
|
+
except: function( listA, listB, fnSelection ) {
|
|
164
|
+
if( listA === null ) return null
|
|
165
|
+
if( listB === null ) return listA.slice()
|
|
166
|
+
|
|
167
|
+
const selectionsA = this.getSelections( listA, fnSelection )
|
|
168
|
+
const selectionsB = this.getSelections( listB, fnSelection )
|
|
169
|
+
|
|
170
|
+
const resultArray = [];
|
|
171
|
+
for( let i = 0; i < listA.length; ++i ) {
|
|
172
|
+
let except = false
|
|
173
|
+
for( let j = 0; j < listB.length; ++j ) {
|
|
174
|
+
if( this.compare( selectionsA[ i ], selectionsB[ j ] ) === 0 ) {
|
|
175
|
+
except = true
|
|
176
|
+
break
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if( !except ) resultArray.push( listA[ i ] )
|
|
180
|
+
}
|
|
181
|
+
return resultArray;
|
|
182
|
+
},
|
|
183
|
+
findAll: function( list, fnCondition ) {
|
|
184
|
+
if( list === null ) return null;
|
|
185
|
+
|
|
186
|
+
const resultArray = [];
|
|
187
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
188
|
+
const item = list[ i ];
|
|
189
|
+
if( fnCondition( item ) )
|
|
190
|
+
resultArray.push( item );
|
|
191
|
+
}
|
|
192
|
+
return resultArray;
|
|
193
|
+
},
|
|
194
|
+
findFirstInternal: function( list, fnCondition ) {
|
|
195
|
+
if( list === null ) return null
|
|
196
|
+
|
|
197
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
198
|
+
const item = list[ i ]
|
|
199
|
+
if( fnCondition( item ) )
|
|
200
|
+
return { item, index: i }
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return { item: null, index: -1 }
|
|
204
|
+
},
|
|
205
|
+
findFirst: function( list, fnCondition ) {
|
|
206
|
+
const result = this.findFirstInternal( list, fnCondition )
|
|
207
|
+
return result === null ? null : result.item
|
|
208
|
+
},
|
|
209
|
+
findIndex: function( list, fnCondition ) {
|
|
210
|
+
const result = this.findFirstInternal( list, fnCondition )
|
|
211
|
+
return result === null ? null : result.index
|
|
212
|
+
},
|
|
213
|
+
findLastInternal: function( list, fnCondition ) {
|
|
214
|
+
if( list === null ) return null
|
|
215
|
+
|
|
216
|
+
for( let i = ( list.length - 1 ); i > -1; i-- ) {
|
|
217
|
+
const item = list[ i ]
|
|
218
|
+
if( fnCondition( item ) )
|
|
219
|
+
return { item, index: i }
|
|
220
|
+
}
|
|
221
|
+
return { item: null, index: -1 }
|
|
222
|
+
},
|
|
223
|
+
findLast: function( list, fnCondition ) {
|
|
224
|
+
const result = this.findLastInternal( list, fnCondition )
|
|
225
|
+
return result === null ? null : result.item
|
|
226
|
+
},
|
|
227
|
+
findLastIndex: function( list, fnCondition ) {
|
|
228
|
+
const result = this.findLastInternal( list, fnCondition )
|
|
229
|
+
return result === null ? null : result.index
|
|
230
|
+
},
|
|
231
|
+
first: function( list ) {
|
|
232
|
+
if( list === null ) return null;
|
|
233
|
+
return list.length > 0 ? list[ 0 ] : null;
|
|
234
|
+
},
|
|
235
|
+
flat: function( list, depth ) {
|
|
236
|
+
if( list === null ) return null
|
|
237
|
+
return list.flat( depth )
|
|
238
|
+
},
|
|
239
|
+
includes: function( list, searchElement, fromIndex ) {
|
|
240
|
+
if( list === null ) return false
|
|
241
|
+
return list.includes( searchElement, fromIndex )
|
|
242
|
+
},
|
|
243
|
+
insertAt: function( list, index, elements ) {
|
|
244
|
+
if( list === null ) return null
|
|
245
|
+
if( elements === null ) return list.slice()
|
|
246
|
+
const copiedList = list.slice()
|
|
247
|
+
copiedList.splice( index, 0, ...elements )
|
|
248
|
+
return copiedList
|
|
249
|
+
},
|
|
250
|
+
intersect: function( listA, listB, fnSelection ) {
|
|
251
|
+
if( listA === null ) return null;
|
|
252
|
+
if( listB === null ) return null;
|
|
253
|
+
|
|
254
|
+
const selectionsA = this.getSelections( listA, fnSelection )
|
|
255
|
+
const selectionsB = this.getSelections( listB, fnSelection )
|
|
256
|
+
|
|
257
|
+
const resultArray = [];
|
|
258
|
+
for( let i = 0; i < listA.length; ++i ) {
|
|
259
|
+
let include = false;
|
|
260
|
+
for( let j = 0; j < listB.length; j++ ) {
|
|
261
|
+
if( this.compare( selectionsA[ i ], selectionsB[ j ] ) === 0 )
|
|
262
|
+
include = true;
|
|
263
|
+
}
|
|
264
|
+
if( include )
|
|
265
|
+
resultArray.push( listA[ i ] );
|
|
266
|
+
}
|
|
267
|
+
return resultArray;
|
|
268
|
+
},
|
|
269
|
+
last: function( list ) {
|
|
270
|
+
if( list === null ) return null;
|
|
271
|
+
return list.length > 0 ? list[ list.length - 1 ] : null;
|
|
272
|
+
},
|
|
273
|
+
max: function( list, fnSelection ) {
|
|
274
|
+
if( list === null ) return null;
|
|
275
|
+
|
|
276
|
+
let max = null;
|
|
277
|
+
if( fnSelection ) {
|
|
278
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
279
|
+
const item = list[ i ];
|
|
280
|
+
const value = fnSelection( item );
|
|
281
|
+
if( max === null || this.compare( value, max ) > 0 )
|
|
282
|
+
max = value;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
287
|
+
const value = list[ i ];
|
|
288
|
+
if( max === null || this.compare( value, max ) > 0 )
|
|
289
|
+
max = value;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return max;
|
|
293
|
+
},
|
|
294
|
+
min: function( list, fnSelection ) {
|
|
295
|
+
if( list === null ) return null;
|
|
296
|
+
|
|
297
|
+
let min = null;
|
|
298
|
+
if( fnSelection ) {
|
|
299
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
300
|
+
const item = list[ i ];
|
|
301
|
+
const value = fnSelection( item );
|
|
302
|
+
if( min === null || this.compare( value, min ) < 0 )
|
|
303
|
+
min = value;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
308
|
+
const value = list[ i ];
|
|
309
|
+
if( min === null || this.compare( value, min ) < 0 )
|
|
310
|
+
min = value;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return min;
|
|
314
|
+
},
|
|
315
|
+
removeAt: function( list, index, deleteCount ) {
|
|
316
|
+
if( list === null ) return null
|
|
317
|
+
const copiedList = list.slice()
|
|
318
|
+
copiedList.splice( index, deleteCount )
|
|
319
|
+
return copiedList
|
|
320
|
+
},
|
|
321
|
+
reverse: function( list ) {
|
|
322
|
+
if( list === null ) return null
|
|
323
|
+
return list.slice().reverse()
|
|
324
|
+
},
|
|
325
|
+
skip: function( list, count ) {
|
|
326
|
+
if( list === null ) return null
|
|
327
|
+
return list.slice( count )
|
|
328
|
+
},
|
|
329
|
+
skipWhile: function( list, fnCondition ) {
|
|
330
|
+
if( list === null ) return null
|
|
331
|
+
|
|
332
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
333
|
+
if( !fnCondition( list[ i ] ) ) {
|
|
334
|
+
return list.slice( i )
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return []
|
|
338
|
+
},
|
|
339
|
+
slice: function( list, start, end ) {
|
|
340
|
+
if( list === null ) return null
|
|
341
|
+
return list.slice( start, end )
|
|
342
|
+
},
|
|
343
|
+
sortInternal: function( { list, fnSelection, compareFunctionWithFnSelection, compareFunction } ) {
|
|
344
|
+
|
|
345
|
+
if( list === null ) return null
|
|
346
|
+
|
|
347
|
+
if( !fnSelection ) return list.slice().sort( compareFunction )
|
|
348
|
+
|
|
349
|
+
const unsorted = new Array( list.length )
|
|
350
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
351
|
+
unsorted[ i ] = { index: i, compareValue: fnSelection( list[ i ] ) }
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const sorted = unsorted.sort( compareFunctionWithFnSelection );
|
|
355
|
+
|
|
356
|
+
const resultArray = new Array( sorted.length )
|
|
357
|
+
for( let i = 0; i < sorted.length; ++i ) {
|
|
358
|
+
resultArray[ i ] = list[ sorted[ i ].index ]
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return resultArray;
|
|
362
|
+
},
|
|
363
|
+
sort: function( list, fnSelection ) {
|
|
364
|
+
return this.sortInternal( {
|
|
365
|
+
list,
|
|
366
|
+
fnSelection,
|
|
367
|
+
compareFunctionWithFnSelection: function( a, b ) { return this.compare( a.compareValue, b.compareValue ) }.bind( this ),
|
|
368
|
+
compareFunction: function( a, b ) { return this.compare( a, b ) }.bind( this )
|
|
369
|
+
} )
|
|
370
|
+
},
|
|
371
|
+
sortDescending: function( list, fnSelection ) {
|
|
372
|
+
return this.sortInternal( {
|
|
373
|
+
list,
|
|
374
|
+
fnSelection,
|
|
375
|
+
compareFunctionWithFnSelection: function( a, b ) { return this.compare( b.compareValue, a.compareValue ); }.bind( this ),
|
|
376
|
+
compareFunction: function( a, b ) { return this.compare( b, a ); }.bind( this )
|
|
377
|
+
} )
|
|
378
|
+
},
|
|
379
|
+
sum: function( list, fnSelection ) {
|
|
380
|
+
if( list === null ) return null;
|
|
381
|
+
let sum = 0;
|
|
382
|
+
if( fnSelection ) {
|
|
383
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
384
|
+
const item = list[ i ];
|
|
385
|
+
const value = fnSelection( item );
|
|
386
|
+
if( value !== null )
|
|
387
|
+
sum += value;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
for( let i = 0; i < list.length; ++i ) {
|
|
392
|
+
const value = list[ i ];
|
|
393
|
+
if( value !== null )
|
|
394
|
+
sum += value;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return sum;
|
|
398
|
+
},
|
|
399
|
+
take: function( list, count ) {
|
|
400
|
+
if( list === null ) return null
|
|
401
|
+
return list.slice( 0, count )
|
|
402
|
+
},
|
|
403
|
+
takeWhile: function( list, fnCondition ) {
|
|
404
|
+
if( list === null ) return null;
|
|
405
|
+
|
|
406
|
+
let i;
|
|
407
|
+
for( i = 0; i < list.length; ++i ) {
|
|
408
|
+
if( !fnCondition( list[ i ] ) ) {
|
|
409
|
+
break
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return list.slice( 0, i );
|
|
413
|
+
},
|
|
414
|
+
union: function( listA, listB, fnSelection ) {
|
|
415
|
+
if( listA === null && listB === null ) return null
|
|
416
|
+
if( listA === null ) return listB.slice()
|
|
417
|
+
if( listB === null ) return listA.slice()
|
|
418
|
+
|
|
419
|
+
if( !fnSelection ) {
|
|
420
|
+
return [ ...new Set( listA.concat( listB ) ) ]
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const resultArray = []
|
|
424
|
+
const keys = []
|
|
425
|
+
|
|
426
|
+
for( let i = 0; i < listA.length; ++i ) {
|
|
427
|
+
const item = listA[ i ]
|
|
428
|
+
const key = fnSelection( item )
|
|
429
|
+
if( keys.indexOf( key ) === -1 ) {
|
|
430
|
+
keys.push( key )
|
|
431
|
+
resultArray.push( item )
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
for( let i = 0; i < listB.length; ++i ) {
|
|
436
|
+
const item = listB[ i ]
|
|
437
|
+
const key = fnSelection( item )
|
|
438
|
+
if( keys.indexOf( key ) === -1 ) {
|
|
439
|
+
keys.push( key )
|
|
440
|
+
resultArray.push( item )
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return resultArray;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const validate = require('jsonschema').validate;
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
jsonSchemaValidate: function (data, schema) {
|
|
5
|
+
if (schema === undefined || schema === null)
|
|
6
|
+
throw new Error('schema undefined')
|
|
7
|
+
let result = validate(data, schema)
|
|
8
|
+
result.valid = (result.errors.length === 0)
|
|
9
|
+
return result
|
|
10
|
+
}
|
|
11
|
+
};
|