@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,131 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
abs: function (value) {
|
|
3
|
+
if (value === null || value === undefined)
|
|
4
|
+
return null;
|
|
5
|
+
return Math.abs(value);
|
|
6
|
+
},
|
|
7
|
+
acos: function (value) {
|
|
8
|
+
if (value === null || value === undefined)
|
|
9
|
+
return null;
|
|
10
|
+
return Math.acos(value);
|
|
11
|
+
},
|
|
12
|
+
asin: function (value) {
|
|
13
|
+
if (value === null || value === undefined)
|
|
14
|
+
return null;
|
|
15
|
+
return Math.asin(value);
|
|
16
|
+
},
|
|
17
|
+
atan: function (value) {
|
|
18
|
+
if (value === null || value === undefined)
|
|
19
|
+
return null;
|
|
20
|
+
return Math.atan(value);
|
|
21
|
+
},
|
|
22
|
+
atan2: function (valueX, valueY) {
|
|
23
|
+
if (valueX === null || valueX === undefined)
|
|
24
|
+
return null;
|
|
25
|
+
if (valueY === null || valueY === undefined)
|
|
26
|
+
return null;
|
|
27
|
+
return Math.atan(valueY, valueX);
|
|
28
|
+
},
|
|
29
|
+
ceil: function (value) {
|
|
30
|
+
if (value === null || value === undefined)
|
|
31
|
+
return null;
|
|
32
|
+
return Math.ceil(value);
|
|
33
|
+
},
|
|
34
|
+
cos: function (value) {
|
|
35
|
+
if (value === null || value === undefined)
|
|
36
|
+
return null;
|
|
37
|
+
return Math.cos(value);
|
|
38
|
+
},
|
|
39
|
+
cosh: function (value) {
|
|
40
|
+
if (value === null || value === undefined)
|
|
41
|
+
return null;
|
|
42
|
+
return Math.cosh(value);
|
|
43
|
+
},
|
|
44
|
+
exp: function (value) {
|
|
45
|
+
if (value === null || value === undefined)
|
|
46
|
+
return null;
|
|
47
|
+
return Math.exp(value);
|
|
48
|
+
},
|
|
49
|
+
floor: function (value) {
|
|
50
|
+
if (value === null || value === undefined)
|
|
51
|
+
return null;
|
|
52
|
+
return Math.floor(value);
|
|
53
|
+
},
|
|
54
|
+
log: function (value, base) {
|
|
55
|
+
if (value === null || value === undefined)
|
|
56
|
+
return null;
|
|
57
|
+
if (base)
|
|
58
|
+
return Math.log(value) / Math.log(base);
|
|
59
|
+
else
|
|
60
|
+
return Math.log(value);
|
|
61
|
+
},
|
|
62
|
+
log10: function (value) {
|
|
63
|
+
if (value === null || value === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
return Math.log10(value);
|
|
66
|
+
},
|
|
67
|
+
pow: function (value, power) {
|
|
68
|
+
if (value === null || value === undefined)
|
|
69
|
+
return null;
|
|
70
|
+
return Math.pow(value, power ? power : 0);
|
|
71
|
+
},
|
|
72
|
+
random: function () {
|
|
73
|
+
if (typeof window !== 'undefined') {
|
|
74
|
+
let crypto = window.crypto || window.msCrypto;
|
|
75
|
+
var array = new Uint32Array(2);
|
|
76
|
+
crypto.getRandomValues(array);
|
|
77
|
+
let mantissa = (array[0] * Math.pow(2, 20)) + (array[1] >>> 12);
|
|
78
|
+
return mantissa * Math.pow(2, -52);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
let crypto = require('crypto');
|
|
82
|
+
return crypto.randomBytes(4).readUInt32BE(0) / 4294967296;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
round: function (value, decimals) {
|
|
86
|
+
if (value === null || value === undefined)
|
|
87
|
+
return null;
|
|
88
|
+
if (decimals)
|
|
89
|
+
return Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
90
|
+
else
|
|
91
|
+
return Math.round(value);
|
|
92
|
+
},
|
|
93
|
+
sign: function (value) {
|
|
94
|
+
if (value === null || value === undefined)
|
|
95
|
+
return null;
|
|
96
|
+
return Math.sign(value);
|
|
97
|
+
},
|
|
98
|
+
sin: function (value) {
|
|
99
|
+
if (value === null || value === undefined)
|
|
100
|
+
return null;
|
|
101
|
+
return Math.sin(value);
|
|
102
|
+
},
|
|
103
|
+
sinh: function (value) {
|
|
104
|
+
if (value === null || value === undefined)
|
|
105
|
+
return null;
|
|
106
|
+
return Math.sinh(value);
|
|
107
|
+
},
|
|
108
|
+
sqrt: function (value) {
|
|
109
|
+
if (value === null || value === undefined)
|
|
110
|
+
return null;
|
|
111
|
+
return Math.sqrt(value);
|
|
112
|
+
},
|
|
113
|
+
tan: function (value) {
|
|
114
|
+
if (value === null || value === undefined)
|
|
115
|
+
return null;
|
|
116
|
+
return Math.tan(value);
|
|
117
|
+
},
|
|
118
|
+
tanh: function (value) {
|
|
119
|
+
if (value === null || value === undefined)
|
|
120
|
+
return null;
|
|
121
|
+
return Math.tanh(value);
|
|
122
|
+
},
|
|
123
|
+
trunc: function (value, decimals) {
|
|
124
|
+
if (value === null || value === undefined)
|
|
125
|
+
return null;
|
|
126
|
+
if (decimals)
|
|
127
|
+
return Math.trunc(value * Math.pow(10, decimals)) / Math.pow(10, decimals);
|
|
128
|
+
else
|
|
129
|
+
return Math.trunc(value);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
const { MongoClient, ObjectId } = require('mongodb');
|
|
2
|
+
const Fs = require('fs-extra');
|
|
3
|
+
const AsyncRetry = require('async-retry');
|
|
4
|
+
|
|
5
|
+
let mongodbConnections = {};
|
|
6
|
+
|
|
7
|
+
let getMongodbConnection = async function (connection) {
|
|
8
|
+
let mongodbConnection = mongodbConnections[connection.name];
|
|
9
|
+
if (mongodbConnection === null || mongodbConnection === undefined) {
|
|
10
|
+
let mongoConfig = {};
|
|
11
|
+
// [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
|
|
12
|
+
// mongoConfig.useUnifiedTopology = true;
|
|
13
|
+
if (connection.ssl) {
|
|
14
|
+
mongoConfig.ssl = true;
|
|
15
|
+
if (connection.sslCert)
|
|
16
|
+
mongoConfig.sslCert = await convertFileArg(connection.sslCert);
|
|
17
|
+
if (connection.sslCrl)
|
|
18
|
+
mongoConfig.tlsCRLFile = await convertFileArg(connection.sslCrl);
|
|
19
|
+
if (connection.sslKey)
|
|
20
|
+
mongoConfig.tlsCertificateKeyFile = await convertFileArg(connection.sslKey);
|
|
21
|
+
if (connection.sslPass)
|
|
22
|
+
mongoConfig.tlsCertificateKeyFilePassword = connection.sslPass;
|
|
23
|
+
if (connection.sslValidate)
|
|
24
|
+
mongoConfig.sslValidate = true;
|
|
25
|
+
}
|
|
26
|
+
if (connection.tls) {
|
|
27
|
+
mongoConfig.tls = true;
|
|
28
|
+
if (connection.tlsCaFile)
|
|
29
|
+
mongoConfig.tlsCAFile = connection.tlsCaFile;
|
|
30
|
+
if (connection.caFile)
|
|
31
|
+
mongoConfig.tlsCAFile = connection.caFile;
|
|
32
|
+
if (connection.tlsCertificateFile)
|
|
33
|
+
mongoConfig.tlsCertificateFile = await convertFileArg(connection.tlsCertificateFile);
|
|
34
|
+
if (connection.tlsCertificateKeyFile)
|
|
35
|
+
mongoConfig.tlsCertificateKeyFile = await convertFileArg(connection.tlsCertificateKeyFile);
|
|
36
|
+
if (connection.tlsCertificateKeyFilePassword)
|
|
37
|
+
mongoConfig.tlsCertificateKeyFilePassword = connection.tlsCertificateKeyFilePassword;
|
|
38
|
+
}
|
|
39
|
+
// start connect mongo with retry
|
|
40
|
+
let mongoClient = null;
|
|
41
|
+
if (connection.useRetries){
|
|
42
|
+
await AsyncRetry(async () => {
|
|
43
|
+
mongoClient = new MongoClient(connection.url, mongoConfig);
|
|
44
|
+
try {
|
|
45
|
+
await mongoClient.connect();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error('Error connecting to MongoDB:', err);
|
|
48
|
+
throw err; // This will trigger a retry
|
|
49
|
+
} finally {
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
retries: connection.retryCount,
|
|
53
|
+
minTimeout: connection.minRetryInterval * 1000,
|
|
54
|
+
maxTimeout: connection.maxRetryInterval * 1000,
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
mongoClient = await MongoClient.connect(connection.url, mongoConfig);
|
|
58
|
+
}
|
|
59
|
+
mongodbConnection = mongoClient.db(connection.databaseName);
|
|
60
|
+
mongodbConnections[connection.name] = mongodbConnection;
|
|
61
|
+
}
|
|
62
|
+
return mongodbConnection;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let convertFileArg = async function (fileArg) {
|
|
66
|
+
if (fileArg) {
|
|
67
|
+
let fileArgParts = fileArg.split(',');
|
|
68
|
+
if (fileArgParts.length === 1) {
|
|
69
|
+
return await Fs.readFile(fileArgParts[0], 'utf-8');
|
|
70
|
+
}
|
|
71
|
+
else if (fileArgParts.length > 1) {
|
|
72
|
+
let promises = [];
|
|
73
|
+
for (let i = 0; i < fileArgParts.length; i++) {
|
|
74
|
+
let fileArgPart = fileArgParts[0];
|
|
75
|
+
promises.push(Fs.readFile(fileArgParts[i], 'utf-8'));
|
|
76
|
+
}
|
|
77
|
+
return await Promise.all(promises);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
let convertFromMongodb = function (value) {
|
|
84
|
+
if (value) {
|
|
85
|
+
let strType = toString.call(value);
|
|
86
|
+
if (strType === '[object Object]') {
|
|
87
|
+
if (value._bsontype && value._bsontype === 'ObjectID') {
|
|
88
|
+
let result = {};
|
|
89
|
+
result['$oid'] = value.toHexString();
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
for (let prop in value) {
|
|
93
|
+
value[prop] = convertFromMongodb(value[prop]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (strType === '[object Array]') {
|
|
97
|
+
for (let i = 0; i < value.length; i++) {
|
|
98
|
+
value[i] = convertFromMongodb(value[i]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return value;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
let convertToMongodb = function (value) {
|
|
106
|
+
if (value) {
|
|
107
|
+
let strType = toString.call(value);
|
|
108
|
+
if (strType === '[object Object]') {
|
|
109
|
+
if (value['$oid'])
|
|
110
|
+
return new ObjectId(value['$oid']);
|
|
111
|
+
for (let prop in value) {
|
|
112
|
+
value[prop] = convertToMongodb(value[prop]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (strType === '[object Array]') {
|
|
116
|
+
for (let i = 0; i < value.length; i++) {
|
|
117
|
+
value[i] = convertToMongodb(value[i]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return value;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
let mongodbAggregate = async function (connection, collectionName, pipeline, options) {
|
|
125
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
126
|
+
let mongodbCursor = await mongodbConnection.collection(collectionName).aggregate(convertToMongodb(pipeline), options);
|
|
127
|
+
if (mongodbCursor)
|
|
128
|
+
return await mongodbCursor.map(function (mongoDbDoc) { return convertFromMongodb(mongoDbDoc); }).toArray();
|
|
129
|
+
return null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
let mongodbBulkWrite = async function (connection, collectionName, operations, options) {
|
|
133
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
134
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).bulkWrite(convertToMongodb(operations), options);
|
|
135
|
+
return convertFromMongodb(mongodbResult);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
let mongodbCountDocuments = async function (connection, collectionName, query, options) {
|
|
139
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
140
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).countDocuments(convertToMongodb(query), options);
|
|
141
|
+
return convertFromMongodb(mongodbResult);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
let mongodbCreateIndex = async function (connection, collectionName, fieldOrSpec, options) {
|
|
145
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
146
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).createIndex(convertToMongodb(fieldOrSpec), options);
|
|
147
|
+
return convertFromMongodb(mongodbResult);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
let mongodbDeleteMany = async function (connection, collectionName, filter, options) {
|
|
151
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
152
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).deleteMany(convertToMongodb(filter), options);
|
|
153
|
+
let result = convertFromMongodb(mongodbResult);
|
|
154
|
+
return result.deletedCount;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
let mongodbDeleteOne = async function (connection, collectionName, filter, options) {
|
|
158
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
159
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).deleteOne(convertToMongodb(filter), options);
|
|
160
|
+
let result = convertFromMongodb(mongodbResult);
|
|
161
|
+
return result.deletedCount;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let mongodbDistinct = async function (connection, collectionName, key, query, options) {
|
|
165
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
166
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).distinct(key, convertToMongodb(query), options);
|
|
167
|
+
return convertFromMongodb(mongodbResult);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
let mongodbDrop = async function (connection, collectionName, options) {
|
|
171
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
172
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).drop(options);
|
|
173
|
+
return convertFromMongodb(mongodbResult);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
let mongodbDropIndex = async function (connection, collectionName, indexName, options) {
|
|
177
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
178
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).dropIndex(indexName, options);
|
|
179
|
+
return convertFromMongodb(mongodbResult);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
let mongodbDropIndexes = async function (connection, collectionName, options) {
|
|
183
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
184
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).dropIndexes(options);
|
|
185
|
+
return convertFromMongodb(mongodbResult);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
let mongodbFind = async function (connection, collectionName, query, options) {
|
|
189
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
190
|
+
let mongodbCursor = await mongodbConnection.collection(collectionName).find(convertToMongodb(query), options);
|
|
191
|
+
if (mongodbCursor){
|
|
192
|
+
const list = await mongodbCursor.map(function (mongoDbDoc) { return convertFromMongodb(mongoDbDoc); }).toArray();
|
|
193
|
+
return list;
|
|
194
|
+
}
|
|
195
|
+
return [];
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
let mongodbFindOne = async function (connection, collectionName, query, options) {
|
|
199
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
200
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).findOne(convertToMongodb(query), options);
|
|
201
|
+
return convertFromMongodb(mongodbResult);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
let mongodbGeoHaystackSearch = async function (connection, collectionName, x, y, options) {
|
|
205
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
206
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).geoHaystackSearch(x, y, options);
|
|
207
|
+
if (mongodbResult && mongodbResult.results) {
|
|
208
|
+
let finalResults = [];
|
|
209
|
+
for (let i = 0; i < mongodbResult.results.length; i++)
|
|
210
|
+
finalResults.push(convertFromMongodb(mongodbResult.results[i]));
|
|
211
|
+
return finalResults;
|
|
212
|
+
}
|
|
213
|
+
return [];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
let mongodbIndexExists = async function (connection, collectionName, indexName, options) {
|
|
217
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
218
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).indexExists(indexName, options);
|
|
219
|
+
return convertFromMongodb(mongodbResult);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
let mongodbInsertMany = async function (connection, collectionName, docs, options) {
|
|
223
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
224
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).insertMany(convertToMongodb(docs), options);
|
|
225
|
+
return convertFromMongodb(mongodbResult);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
let mongodbInsertOne = async function (connection, collectionName, doc, options) {
|
|
229
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
230
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).insertOne(convertToMongodb(doc), options);
|
|
231
|
+
let result = convertFromMongodb(mongodbResult);
|
|
232
|
+
return result.insertedId;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
let mongodbIsCapped = async function (connection, collectionName, options) {
|
|
236
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
237
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).isCapped(options);
|
|
238
|
+
return convertFromMongodb(mongodbResult);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
let mongodbListIndexes = async function (connection, collectionName, options) {
|
|
242
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
243
|
+
let mongodbCursor = await mongodbConnection.collection(collectionName).listIndexes(options);
|
|
244
|
+
if (mongodbCursor)
|
|
245
|
+
return await mongodbCursor.map(function (mongoDbDoc) { return convertFromMongodb(mongoDbDoc); }).toArray();
|
|
246
|
+
return [];
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
let mongodbOptions = async function (connection, collectionName, options) {
|
|
250
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
251
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).options(options);
|
|
252
|
+
return convertFromMongodb(mongodbResult);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
let mongodbReIndex = async function (connection, collectionName, options) {
|
|
256
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
257
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).reIndex(options);
|
|
258
|
+
return convertFromMongodb(mongodbResult);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
let mongodbReplaceOne = async function (connection, collectionName, filter, replacement, options) {
|
|
262
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
263
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).replaceOne(convertToMongodb(filter), convertToMongodb(replacement), options);
|
|
264
|
+
return convertFromMongodb(mongodbResult);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
let mongodbStats = async function (connection, collectionName, options) {
|
|
268
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
269
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).stats(options);
|
|
270
|
+
return convertFromMongodb(mongodbResult);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
let mongodbUpdateMany = async function (connection, collectionName, filter, update, options) {
|
|
274
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
275
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).updateMany(convertToMongodb(filter), convertToMongodb(update), options);
|
|
276
|
+
return convertFromMongodb(mongodbResult);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
let mongodbUpdateOne = async function (connection, collectionName, filter, update, options) {
|
|
280
|
+
let mongodbConnection = await getMongodbConnection(connection);
|
|
281
|
+
let mongodbResult = await mongodbConnection.collection(collectionName).updateOne(convertToMongodb(filter), convertToMongodb(update), options);
|
|
282
|
+
return convertFromMongodb(mongodbResult);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
let mongodbConnectionHealthCheck = async function (connection) {
|
|
286
|
+
try {
|
|
287
|
+
let mongodbConnection = (mongodbConnections[connection.name]) ?? await getMongodbConnection(connection)
|
|
288
|
+
const collections = await mongodbConnection.listCollections().toArray(); // Get all collections
|
|
289
|
+
|
|
290
|
+
if (collections.length > 0) {
|
|
291
|
+
return { status: "ok", message: "Connected, and collections readable." };
|
|
292
|
+
} else {
|
|
293
|
+
return { status: "ok", message: "Connected, but no collections readable." };
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
return { status: "error", message: error.message };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
module.exports = {
|
|
301
|
+
mongodbAggregate: mongodbAggregate,
|
|
302
|
+
mongodbBulkWrite: mongodbBulkWrite,
|
|
303
|
+
mongodbCountDocuments: mongodbCountDocuments,
|
|
304
|
+
mongodbCreateIndex: mongodbCreateIndex,
|
|
305
|
+
mongodbDeleteMany: mongodbDeleteMany,
|
|
306
|
+
mongodbDeleteOne: mongodbDeleteOne,
|
|
307
|
+
mongodbDistinct: mongodbDistinct,
|
|
308
|
+
mongodbDrop: mongodbDrop,
|
|
309
|
+
mongodbDropIndex: mongodbDropIndex,
|
|
310
|
+
mongodbDropIndexes: mongodbDropIndexes,
|
|
311
|
+
mongodbFind: mongodbFind,
|
|
312
|
+
mongodbFindOne: mongodbFindOne,
|
|
313
|
+
mongodbGeoHaystackSearch: mongodbGeoHaystackSearch,
|
|
314
|
+
mongodbIndexExists: mongodbIndexExists,
|
|
315
|
+
mongodbInsertMany: mongodbInsertMany,
|
|
316
|
+
mongodbInsertOne: mongodbInsertOne,
|
|
317
|
+
mongodbIsCapped: mongodbIsCapped,
|
|
318
|
+
mongodbListIndexes: mongodbListIndexes,
|
|
319
|
+
mongodbOptions: mongodbOptions,
|
|
320
|
+
mongodbReIndex: mongodbReIndex,
|
|
321
|
+
mongodbReplaceOne: mongodbReplaceOne,
|
|
322
|
+
mongodbStats: mongodbStats,
|
|
323
|
+
mongodbUpdateMany: mongodbUpdateMany,
|
|
324
|
+
mongodbUpdateOne: mongodbUpdateOne,
|
|
325
|
+
mongodbConnectionHealthCheck: mongodbConnectionHealthCheck
|
|
326
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const { rdsEscape, rdsEscapeId } = require('../index.js');
|
|
2
|
+
|
|
3
|
+
describe('rdsEscape', () => {
|
|
4
|
+
test("should escape a string with a single quote", () => {
|
|
5
|
+
const input = "O'Reilly";
|
|
6
|
+
const output = rdsEscape(input);
|
|
7
|
+
expect(output).toBe("'O\\'Reilly'");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("should escape an empty string", () => {
|
|
11
|
+
const input = "";
|
|
12
|
+
const output = rdsEscape(input);
|
|
13
|
+
expect(output).toBe("''");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("should escape null as NULL", () => {
|
|
17
|
+
const input = null;
|
|
18
|
+
const output = rdsEscape(input);
|
|
19
|
+
expect(output).toBe("NULL");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("should escape a number as string", () => {
|
|
23
|
+
const input = 42;
|
|
24
|
+
const output = rdsEscape(input);
|
|
25
|
+
expect(output).toBe("42");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("should escape booleans correctly", () => {
|
|
29
|
+
expect(rdsEscape(true)).toBe("true");
|
|
30
|
+
expect(rdsEscape(false)).toBe("false");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('rdsEscapeId', () => {
|
|
35
|
+
test("should escape an identifier containing backticks", () => {
|
|
36
|
+
const input = "user`name";
|
|
37
|
+
const output = rdsEscapeId(input);
|
|
38
|
+
expect(output).toBe("`user``name`");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("should escape multiple identifiers (array)", () => {
|
|
42
|
+
const input = ['users', 'name'];
|
|
43
|
+
const output = rdsEscapeId(input);
|
|
44
|
+
expect(output).toBe("`users`, `name`");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("should escape identifiers with special characters", () => {
|
|
48
|
+
const input = "order;DROP TABLE users";
|
|
49
|
+
const output = rdsEscapeId(input);
|
|
50
|
+
expect(output).toBe("`order;DROP TABLE users`");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("should escape empty string as ``", () => {
|
|
54
|
+
const input = "";
|
|
55
|
+
const output = rdsEscapeId(input);
|
|
56
|
+
expect(output).toBe("``");
|
|
57
|
+
});
|
|
58
|
+
});
|