@golemio/core 1.6.5 → 1.6.6-dev.837110606

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.
Files changed (98) hide show
  1. package/README.md +0 -1
  2. package/bin/import-test-data.js +0 -72
  3. package/dist/helpers/HealthCheck.d.ts +0 -1
  4. package/dist/helpers/HealthCheck.js +0 -1
  5. package/dist/helpers/HealthCheck.js.map +1 -1
  6. package/dist/helpers/data-access/amqp/AlternateExchangeCreator.js +2 -1
  7. package/dist/helpers/data-access/amqp/AlternateExchangeCreator.js.map +1 -1
  8. package/dist/input-gateway/connectors/AMQPConnector.js +2 -1
  9. package/dist/input-gateway/connectors/AMQPConnector.js.map +1 -1
  10. package/dist/integration-engine/config/IntegrationEngineConfiguration.d.ts +0 -1
  11. package/dist/integration-engine/config/IntegrationEngineConfiguration.js +0 -1
  12. package/dist/integration-engine/config/IntegrationEngineConfiguration.js.map +1 -1
  13. package/dist/integration-engine/config/abstract.d.ts +0 -1
  14. package/dist/integration-engine/connectors/AMQPConnector.js +2 -1
  15. package/dist/integration-engine/connectors/AMQPConnector.js.map +1 -1
  16. package/dist/integration-engine/connectors/index.d.ts +0 -6
  17. package/dist/integration-engine/connectors/index.js +1 -6
  18. package/dist/integration-engine/connectors/index.js.map +1 -1
  19. package/dist/integration-engine/datasources/IDataSource.d.ts +2 -2
  20. package/dist/integration-engine/ioc/ContainerToken.d.ts +0 -1
  21. package/dist/integration-engine/ioc/ContainerToken.js +0 -1
  22. package/dist/integration-engine/ioc/ContainerToken.js.map +1 -1
  23. package/dist/integration-engine/ioc/Di.js +0 -2
  24. package/dist/integration-engine/ioc/Di.js.map +1 -1
  25. package/dist/integration-engine/models/IModel.d.ts +0 -12
  26. package/dist/integration-engine/models/PostgresModel.js +1 -1
  27. package/dist/integration-engine/models/PostgresModel.js.map +1 -1
  28. package/dist/integration-engine/models/index.d.ts +0 -1
  29. package/dist/integration-engine/models/index.js +0 -1
  30. package/dist/integration-engine/models/index.js.map +1 -1
  31. package/dist/integration-engine/queueprocessors/QueueProcessor.js +1 -1
  32. package/dist/integration-engine/queueprocessors/QueueProcessor.js.map +1 -1
  33. package/dist/integration-engine/workers/AbstractTask.d.ts +1 -0
  34. package/dist/integration-engine/workers/AbstractTask.js +1 -0
  35. package/dist/integration-engine/workers/AbstractTask.js.map +1 -1
  36. package/dist/integration-engine/workers/AbstractWorker.js +1 -0
  37. package/dist/integration-engine/workers/AbstractWorker.js.map +1 -1
  38. package/dist/integration-engine/workers/interfaces/ITask.d.ts +1 -0
  39. package/dist/monitoring/opentelemetry/instrumentation/configs/index.d.ts +0 -1
  40. package/dist/monitoring/opentelemetry/instrumentation/configs/index.js +1 -3
  41. package/dist/monitoring/opentelemetry/instrumentation/configs/index.js.map +1 -1
  42. package/dist/monitoring/opentelemetry/instrumentation/index.d.ts +1 -2
  43. package/dist/monitoring/opentelemetry/instrumentation/index.js +0 -2
  44. package/dist/monitoring/opentelemetry/instrumentation/index.js.map +1 -1
  45. package/dist/monitoring/sentry/sentry-provider.js +0 -1
  46. package/dist/monitoring/sentry/sentry-provider.js.map +1 -1
  47. package/dist/output-gateway/Geo.d.ts +1 -1
  48. package/dist/output-gateway/config/OutputGatewayConfiguration.d.ts +0 -3
  49. package/dist/output-gateway/config/OutputGatewayConfiguration.js +0 -11
  50. package/dist/output-gateway/config/OutputGatewayConfiguration.js.map +1 -1
  51. package/dist/output-gateway/database/index.d.ts +1 -30
  52. package/dist/output-gateway/database/index.js +1 -6
  53. package/dist/output-gateway/database/index.js.map +1 -1
  54. package/dist/output-gateway/ioc/ContainerToken.d.ts +0 -1
  55. package/dist/output-gateway/ioc/ContainerToken.js +0 -1
  56. package/dist/output-gateway/ioc/ContainerToken.js.map +1 -1
  57. package/dist/output-gateway/ioc/Di.js +0 -2
  58. package/dist/output-gateway/ioc/Di.js.map +1 -1
  59. package/dist/output-gateway/models/index.d.ts +0 -3
  60. package/dist/output-gateway/models/index.js +0 -3
  61. package/dist/output-gateway/models/index.js.map +1 -1
  62. package/dist/output-gateway/routes/index.d.ts +0 -2
  63. package/dist/output-gateway/routes/index.js +0 -2
  64. package/dist/output-gateway/routes/index.js.map +1 -1
  65. package/package.json +6 -7
  66. package/dist/integration-engine/connectors/MongoConnector.d.ts +0 -15
  67. package/dist/integration-engine/connectors/MongoConnector.js +0 -89
  68. package/dist/integration-engine/connectors/MongoConnector.js.map +0 -1
  69. package/dist/integration-engine/connectors/interfaces/IMongoConnector.d.ts +0 -7
  70. package/dist/integration-engine/connectors/interfaces/IMongoConnector.js +0 -3
  71. package/dist/integration-engine/connectors/interfaces/IMongoConnector.js.map +0 -1
  72. package/dist/integration-engine/models/MongoModel.d.ts +0 -42
  73. package/dist/integration-engine/models/MongoModel.js +0 -245
  74. package/dist/integration-engine/models/MongoModel.js.map +0 -1
  75. package/dist/monitoring/opentelemetry/instrumentation/configs/mongoose.d.ts +0 -2
  76. package/dist/monitoring/opentelemetry/instrumentation/configs/mongoose.js +0 -20
  77. package/dist/monitoring/opentelemetry/instrumentation/configs/mongoose.js.map +0 -1
  78. package/dist/output-gateway/database/MongoDatabase.d.ts +0 -19
  79. package/dist/output-gateway/database/MongoDatabase.js +0 -89
  80. package/dist/output-gateway/database/MongoDatabase.js.map +0 -1
  81. package/dist/output-gateway/models/GeoJsonModel.d.ts +0 -56
  82. package/dist/output-gateway/models/GeoJsonModel.js +0 -188
  83. package/dist/output-gateway/models/GeoJsonModel.js.map +0 -1
  84. package/dist/output-gateway/models/HistoryModel.d.ts +0 -30
  85. package/dist/output-gateway/models/HistoryModel.js +0 -96
  86. package/dist/output-gateway/models/HistoryModel.js.map +0 -1
  87. package/dist/output-gateway/models/MongoModel.d.ts +0 -74
  88. package/dist/output-gateway/models/MongoModel.js +0 -87
  89. package/dist/output-gateway/models/MongoModel.js.map +0 -1
  90. package/dist/output-gateway/routes/HistoryRouter.d.ts +0 -7
  91. package/dist/output-gateway/routes/HistoryRouter.js +0 -46
  92. package/dist/output-gateway/routes/HistoryRouter.js.map +0 -1
  93. package/dist/output-gateway/routes/RouterBuilder.d.ts +0 -70
  94. package/dist/output-gateway/routes/RouterBuilder.js +0 -92
  95. package/dist/output-gateway/routes/RouterBuilder.js.map +0 -1
  96. package/dist/shared/mongoose.d.ts +0 -2
  97. package/dist/shared/mongoose.js +0 -7
  98. package/dist/shared/mongoose.js.map +0 -1
@@ -1,245 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.MongoModel = void 0;
16
- const utils_1 = require("../../helpers/utils");
17
- const Logger_1 = require("../helpers/Logger");
18
- const errors_1 = require("@golemio/errors");
19
- const mongoose_1 = __importDefault(require("mongoose"));
20
- class MongoModel {
21
- constructor(name, settings, validator) {
22
- var _a;
23
- this.save = (data, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
24
- if (this.savingType === "readOnly") {
25
- throw new errors_1.CustomError("The model saving type is read only.", true, this.name);
26
- }
27
- // data validation
28
- if (this.validator) {
29
- try {
30
- yield this.validator.Validate(data);
31
- }
32
- catch (err) {
33
- throw new errors_1.CustomError("Error while validating data.", true, this.name, 4005, err);
34
- }
35
- }
36
- else {
37
- Logger_1.log.warn(this.name + ": Model validator is not set.");
38
- }
39
- const model = this.getMongooseModelSafely(useTmpTable);
40
- // calling the method based on savingType (this.insertOnly() or this.insertOrUpdate())
41
- return this[this.savingType](model, data);
42
- });
43
- this.updateOne = (opts, data, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
44
- if (this.savingType === "readOnly") {
45
- throw new errors_1.CustomError("The model saving type is read only.", true, this.name);
46
- }
47
- const model = this.getMongooseModelSafely(useTmpTable);
48
- return model.updateOne(opts, data, { runValidators: true }).exec();
49
- });
50
- this.updateOneById = (id, data, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
51
- if (this.savingType === "readOnly") {
52
- throw new errors_1.CustomError("The model saving type is read only.", true, this.name);
53
- }
54
- const model = this.getMongooseModelSafely(useTmpTable);
55
- return model.updateOne(this.searchPath(id), data, { runValidators: true }).exec();
56
- });
57
- this.truncate = (useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
58
- if (this.savingType === "readOnly") {
59
- throw new errors_1.CustomError("The model saving type is read only.", true, this.name);
60
- }
61
- const model = this.getMongooseModelSafely(useTmpTable);
62
- try {
63
- yield model.deleteMany({}).exec();
64
- }
65
- catch (err) {
66
- throw new errors_1.CustomError("Error while truncating data.", true, this.name, 4002, err);
67
- }
68
- });
69
- this.delete = (opts, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
70
- if (this.savingType === "readOnly") {
71
- throw new errors_1.CustomError("The model saving type is read only.", true, this.name);
72
- }
73
- const model = this.getMongooseModelSafely(useTmpTable);
74
- try {
75
- return yield model.deleteMany(opts).exec();
76
- }
77
- catch (err) {
78
- throw new errors_1.CustomError("Error while deleting data.", true, this.name, 4002, err);
79
- }
80
- });
81
- this.find = (opts, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
82
- const model = this.getMongooseModelSafely(useTmpTable);
83
- try {
84
- return yield model.find(opts);
85
- }
86
- catch (err) {
87
- throw new errors_1.CustomError("Error while getting from database.", true, this.name, 4004, err);
88
- }
89
- });
90
- this.findOne = (opts, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
91
- const model = this.getMongooseModelSafely(useTmpTable);
92
- try {
93
- return yield model.findOne(opts);
94
- }
95
- catch (err) {
96
- throw new errors_1.CustomError("Error while getting from database.", true, this.name, 4004, err);
97
- }
98
- });
99
- this.findOneById = (id, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
100
- const model = this.getMongooseModelSafely(useTmpTable);
101
- try {
102
- const data = yield model.findOne(this.searchPath(id)).exec();
103
- if (!data) {
104
- throw new errors_1.CustomError("Model data was not found.", true, this.name, 1014);
105
- }
106
- else {
107
- return data;
108
- }
109
- }
110
- catch (err) {
111
- throw new errors_1.CustomError("Error while getting from database.", true, this.name, 4004, err);
112
- }
113
- });
114
- this.aggregate = (aggregation, useTmpTable = false) => __awaiter(this, void 0, void 0, function* () {
115
- const model = this.getMongooseModelSafely(useTmpTable);
116
- try {
117
- return model.aggregate(aggregation).exec();
118
- }
119
- catch (err) {
120
- throw new errors_1.CustomError("Error while getting from database.", true, this.name, 4004, err);
121
- }
122
- });
123
- this.replaceOrigCollectionByTempCollection = () => __awaiter(this, void 0, void 0, function* () {
124
- if (this.savingType === "readOnly") {
125
- throw new errors_1.CustomError("The model saving type is read only.", true, this.name);
126
- }
127
- if (!this.tmpMongooseModel) {
128
- throw new errors_1.CustomError("Temporary model is not defined.", true, this.name);
129
- }
130
- try {
131
- yield mongoose_1.default.connection.db
132
- .collection(this.mongooseModel.collection.name)
133
- .rename("old_" + this.mongooseModel.collection.name);
134
- }
135
- catch (err) {
136
- Logger_1.log.warn("Collection " + this.mongooseModel.collection.name + "does not exist.");
137
- }
138
- try {
139
- yield mongoose_1.default.connection.db
140
- .collection(this.tmpMongooseModel.collection.name)
141
- .rename(this.mongooseModel.collection.name);
142
- }
143
- catch (err) {
144
- Logger_1.log.warn("Collection tmp_" + this.tmpMongooseModel.collection.name + "does not exist.");
145
- }
146
- try {
147
- yield mongoose_1.default.connection.db.collection("old_" + this.mongooseModel.collection.name).drop();
148
- }
149
- catch (err) {
150
- Logger_1.log.warn("Collection old_" + this.mongooseModel.collection.name + "does not exist.");
151
- }
152
- });
153
- this.insertOnly = (model, data) => __awaiter(this, void 0, void 0, function* () {
154
- try {
155
- if (data instanceof Array) {
156
- return model.insertMany(data);
157
- }
158
- else {
159
- return model.create(data);
160
- }
161
- }
162
- catch (err) {
163
- throw new errors_1.CustomError("Error while saving to database.", true, this.name, 4001, err);
164
- }
165
- });
166
- this.insertOrUpdate = (model, data) => __awaiter(this, void 0, void 0, function* () {
167
- try {
168
- if (data instanceof Array) {
169
- const promises = data.map((item) => {
170
- return this.insertOrUpdateOne(model, item);
171
- });
172
- return Promise.all(promises);
173
- }
174
- else {
175
- return this.insertOrUpdateOne(model, data);
176
- }
177
- }
178
- catch (err) {
179
- throw new errors_1.CustomError("Error while saving to database.", true, this.name, 4001, err);
180
- }
181
- });
182
- this.insertOrUpdateOne = (model, newData) => __awaiter(this, void 0, void 0, function* () {
183
- if (!this.updateValues) {
184
- throw new errors_1.CustomError("Method updateValues() is not defined.", true, this.name);
185
- }
186
- try {
187
- let dbData = yield model.findOne(this.searchPath((0, utils_1.getSubProperty)(this.identifierPath, newData))).exec();
188
- if (!dbData) {
189
- throw new errors_1.CustomError("Model data was not found.", true, this.name, 1014);
190
- }
191
- dbData = this.updateValues(dbData, newData);
192
- dbData.markModified("properties"); // TODO zkontrolovat jestli funguje na vsechny pripady
193
- return dbData.save();
194
- }
195
- catch (err) {
196
- if (err instanceof errors_1.CustomError && err.code === 1014) {
197
- return model.create(newData);
198
- }
199
- else {
200
- throw new errors_1.CustomError("Error while saving to database.", true, this.name, 4001, err);
201
- }
202
- }
203
- });
204
- this.getMongooseModelSafely = (useTmpTable) => {
205
- let model = this.mongooseModel;
206
- if (useTmpTable && this.tmpMongooseModel) {
207
- model = this.tmpMongooseModel;
208
- }
209
- else if (useTmpTable && !this.tmpMongooseModel) {
210
- throw new errors_1.CustomError("Temporary model is not defined.", true, this.name);
211
- }
212
- return model;
213
- };
214
- this.name = name;
215
- this.schema = new mongoose_1.default.Schema(settings.outputMongooseSchemaObject, { bufferCommands: false });
216
- try {
217
- this.mongooseModel = mongoose_1.default.model(this.name);
218
- }
219
- catch (error) {
220
- this.mongooseModel = mongoose_1.default.model(this.name, this.schema, settings.mongoCollectionName);
221
- }
222
- if (settings.tmpMongoCollectionName) {
223
- try {
224
- this.tmpMongooseModel = mongoose_1.default.model("tmp" + this.name);
225
- }
226
- catch (error) {
227
- this.tmpMongooseModel = mongoose_1.default.model("tmp" + this.name, this.schema, settings.tmpMongoCollectionName);
228
- }
229
- }
230
- this.validator = validator;
231
- this.savingType = settings.savingType;
232
- this.updateValues = settings.updateValues || null;
233
- this.searchPath = settings.searchPath
234
- ? settings.searchPath
235
- : (id, multiple = false) => (multiple ? { id: { $in: id } } : { id });
236
- this.resultsPath = settings.resultsPath || "";
237
- this.identifierPath = settings.identifierPath;
238
- this.select = settings.select || "-_id -__v";
239
- if ((_a = this.validator) === null || _a === void 0 ? void 0 : _a.setLogger) {
240
- this.validator.setLogger(Logger_1.log);
241
- }
242
- }
243
- }
244
- exports.MongoModel = MongoModel;
245
- //# sourceMappingURL=MongoModel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongoModel.js","sourceRoot":"","sources":["../../../src/integration-engine/models/MongoModel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAgD;AAChD,8CAAyC;AAEzC,4CAA8C;AAE9C,wDAAgC;AAEhC,MAAa,UAAU;IAwBnB,YAAY,IAAY,EAAE,QAA2B,EAAE,SAAoB;;QAiCpE,SAAI,GAAG,CAAO,IAAS,EAAE,cAAuB,KAAK,EAAgB,EAAE;YAC1E,IAAI,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE;gBAChC,MAAM,IAAI,oBAAW,CAAC,qCAAqC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aACjF;YAED,kBAAkB;YAClB,IAAI,IAAI,CAAC,SAAS,EAAE;gBAChB,IAAI;oBACA,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IA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C,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC;aAC3G;SACJ;QAED,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,IAAI,IAAI,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU;YACjC,CAAC,CAAC,QAAQ,CAAC,UAAU;YACrB,CAAC,CAAC,CAAC,EAAO,EAAE,QAAQ,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAW,IAAI,EAAE,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,WAAW,CAAC;QAE7C,IAAI,MAAA,IAAI,CAAC,SAAS,0CAAE,SAAS,EAAE;YAC3B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,YAAG,CAAC,CAAC;SACjC;IACL,CAAC;CAoMJ;AA3PD,gCA2PC"}
@@ -1,2 +0,0 @@
1
- import { MongooseInstrumentationConfig } from "opentelemetry-instrumentation-mongoose";
2
- export declare const mongooseConfig: MongooseInstrumentationConfig;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mongooseConfig = void 0;
4
- const mongooseSerializer = (operation, payload) => {
5
- try {
6
- const { options } = payload;
7
- if (options && typeof options === "object" && Object.keys(options).length === 0) {
8
- delete payload.options;
9
- }
10
- return JSON.stringify(payload);
11
- }
12
- catch (_a) {
13
- return "";
14
- }
15
- };
16
- exports.mongooseConfig = {
17
- suppressInternalInstrumentation: true,
18
- dbStatementSerializer: mongooseSerializer,
19
- };
20
- //# sourceMappingURL=mongoose.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongoose.js","sourceRoot":"","sources":["../../../../../src/monitoring/opentelemetry/instrumentation/configs/mongoose.ts"],"names":[],"mappings":";;;AAEA,MAAM,kBAAkB,GAA0B,CAAC,SAAiB,EAAE,OAA0B,EAAU,EAAE;IACxG,IAAI;QACA,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC5B,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YAC7E,OAAO,OAAO,CAAC,OAAO,CAAC;SAC1B;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;KAClC;IAAC,WAAM;QACJ,OAAO,EAAE,CAAC;KACb;AACL,CAAC,CAAC;AAEW,QAAA,cAAc,GAAkC;IACzD,+BAA+B,EAAE,IAAI;IACrC,qBAAqB,EAAE,kBAAkB;CAC5C,CAAC"}
@@ -1,19 +0,0 @@
1
- import { ILogger } from "../../helpers";
2
- import { OutputGatewayConfiguration } from "../config/OutputGatewayConfiguration";
3
- import mongoose from "mongoose";
4
- import { Disposable } from "tsyringe";
5
- /**
6
- * Class for connection to MongoDB database. Using mongoose https://www.npmjs.com/package/mongoose
7
- */
8
- export declare class MongoDatabase implements Disposable {
9
- private readonly log;
10
- private readonly connectionString;
11
- private readonly connectTimeoutMS;
12
- /** Set up connection string */
13
- constructor(config: OutputGatewayConfiguration, log: ILogger);
14
- /** Connects to db */
15
- connect: () => Promise<mongoose.Connection>;
16
- isConnected: () => Promise<boolean>;
17
- disconnect: () => Promise<void>;
18
- dispose: () => Promise<void>;
19
- }
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- var __importDefault = (this && this.__importDefault) || function (mod) {
24
- return (mod && mod.__esModule) ? mod : { "default": mod };
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.MongoDatabase = void 0;
28
- const ContainerToken_1 = require("../ioc/ContainerToken");
29
- const OutputGatewayConfiguration_1 = require("../config/OutputGatewayConfiguration");
30
- const errors_1 = require("@golemio/errors");
31
- const mongoose_1 = __importDefault(require("mongoose"));
32
- const tsyringe_1 = require("tsyringe");
33
- /**
34
- * Class for connection to MongoDB database. Using mongoose https://www.npmjs.com/package/mongoose
35
- */
36
- let MongoDatabase = class MongoDatabase {
37
- /** Set up connection string */
38
- constructor(config, log) {
39
- this.log = log;
40
- /** Connects to db */
41
- this.connect = () => __awaiter(this, void 0, void 0, function* () {
42
- try {
43
- if (!this.connectionString || this.connectionString === "YOUR CONNECTION STRING GOES HERE") {
44
- throw new Error("Undefined connection string.");
45
- }
46
- const connectOptions = {
47
- connectTimeoutMS: this.connectTimeoutMS,
48
- serverSelectionTimeoutMS: this.connectTimeoutMS,
49
- };
50
- yield mongoose_1.default.connect(this.connectionString, connectOptions);
51
- mongoose_1.default.connection.on("disconnected", () => {
52
- this.log.error("Mongo DB disconnected!");
53
- });
54
- mongoose_1.default.connection.on("reconnected", () => {
55
- this.log.warn("Mongo DB reconnected after connection lost.");
56
- });
57
- mongoose_1.default.connection.on("error", (err) => {
58
- this.log.error(err);
59
- });
60
- this.log.info("Connected to Mongo DB!");
61
- return mongoose_1.default.connection;
62
- }
63
- catch (err) {
64
- this.log.error("Could not connect to " + this.connectionString);
65
- throw new errors_1.CustomError("Error while connecting to Mongo DB", false, "MongoDatabase", 5001, err);
66
- }
67
- });
68
- this.isConnected = () => __awaiter(this, void 0, void 0, function* () {
69
- return mongoose_1.default.connection.readyState === 1;
70
- });
71
- this.disconnect = () => __awaiter(this, void 0, void 0, function* () {
72
- this.log.info("MongoDB disconnect called");
73
- return mongoose_1.default.connection.close();
74
- });
75
- this.dispose = () => __awaiter(this, void 0, void 0, function* () {
76
- yield this.disconnect();
77
- });
78
- this.connectionString = config.mongo_connection;
79
- this.connectTimeoutMS = config.mongo_timeout;
80
- }
81
- };
82
- MongoDatabase = __decorate([
83
- (0, tsyringe_1.injectable)(),
84
- __param(0, (0, tsyringe_1.inject)(ContainerToken_1.ContainerToken.Config)),
85
- __param(1, (0, tsyringe_1.inject)(ContainerToken_1.ContainerToken.Logger)),
86
- __metadata("design:paramtypes", [OutputGatewayConfiguration_1.OutputGatewayConfiguration, Object])
87
- ], MongoDatabase);
88
- exports.MongoDatabase = MongoDatabase;
89
- //# sourceMappingURL=MongoDatabase.js.map
@@ -1 +0,0 @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,CAAC,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;gBACxC,OAAO,kBAAQ,CAAC,UAAU,CAAC;aAC9B;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;gBAChE,MAAM,IAAI,oBAAW,CAAC,oCAAoC,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;aAClG;QACL,CAAC,CAAA,CAAC;QAEK,gBAAW,GAAG,GAA2B,EAAE;YAC9C,OAAO,kBAAQ,CAAC,UAAU,CAAC,UAAU,KAAK,CAAC,CAAC;QAChD,CAAC,CAAA,CAAC;QAEK,eAAU,GAAG,GAAwB,EAAE;YAC1C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YAC3C,OAAO,kBAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACvC,CAAC,CAAA,CAAC;QAEK,YAAO,GAAG,GAAwB,EAAE;YACvC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAC5B,CAAC,CAAA,CAAC;QAhDE,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAChD,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,aAAa,CAAC;IACjD,CAAC;CA+CJ,CAAA;AA1DY,aAAa;IADzB,IAAA,qBAAU,GAAE;IAOJ,WAAA,IAAA,iBAAM,EAAC,+BAAc,CAAC,MAAM,CAAC,CAAA;IAC7B,WAAA,IAAA,iBAAM,EAAC,+BAAc,CAAC,MAAM,CAAC,CAAA;qCADS,uDAA0B;GAN5D,aAAa,CA0DzB;AA1DY,sCAAa"}
@@ -1,56 +0,0 @@
1
- import { IGeoJSONFeature } from "../Geo";
2
- import { MongoModel } from "./";
3
- import { IPropertyResponseModel } from "./response";
4
- import { IGeoJsonAllFilterParameters } from "../routes/interfaces/IGeoJsonAllFilterParameters";
5
- import { SchemaDefinition } from "mongoose";
6
- import { IGeoJsonModel } from "./interfaces/IGeoJsonModel";
7
- /**
8
- * General model for GeoJSON data. Geo-spatial indexing and querying. Implements general GetAll and GetOne functions
9
- *
10
- * Expects GeoJSON data structure:
11
- *
12
- * geometry: { coordinates[], type },
13
- *
14
- * properties: { ... }
15
- *
16
- * type: Feature
17
- *
18
- * Model /DATA ACCESS LAYER/: Defines data structure, connects to DB storage and retrieves data directly from database.
19
- * Performs database queries.
20
- */
21
- export declare class GeoJsonModel extends MongoModel implements IGeoJsonModel {
22
- private log;
23
- /**
24
- * Creates a model with specified schema definition
25
- * @param inName Name of the model - corresponding with mongo collection name (eg. "parkings" for "Parking" model)
26
- * @param inSchema Schema of the data to be stored in this model
27
- * @param inCollectionName (optional) Name of the mongo collection
28
- * if empty, collection named as plural of model's name is used
29
- */
30
- constructor(inName: string, inSchema: SchemaDefinition, inCollectionName?: string);
31
- /** Retrieves all the records from database
32
- * @param options Object with options settings, with following properties.
33
- * @param options.lat Latitude to sort results by (by proximity)
34
- * @param options.lng Longitute to sort results by
35
- * @param options.range Maximum range from specified latLng. Only data within this range will be returned.
36
- * @param options.limit Limit
37
- * @param options.offset Offset
38
- * @param options.updatedSince Filters out all results with older updated_at than this parameter
39
- * (filters not-updated data)
40
- * @param options.additionalFilters Object with additional filter conditions to be added to the selection
41
- * @returns GeoJSON FeatureCollection with all retrieved objects in "features"
42
- */
43
- GetAll(options?: IGeoJsonAllFilterParameters): Promise<any>;
44
- /** Retrieves one record from database
45
- * @param inId Id of the record to be retrieved
46
- * @returns Object of the retrieved record or null
47
- */
48
- GetOne(inId: any): Promise<object>;
49
- /**
50
- * Retrieves properties of the current model
51
- * @returns Array of properties
52
- */
53
- GetProperties: () => Promise<IPropertyResponseModel[]>;
54
- protected MapUpdatedAtToISOString: (feature: IGeoJSONFeature) => IGeoJSONFeature;
55
- private HasRequiredGeojsonProps;
56
- }
@@ -1,188 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.GeoJsonModel = void 0;
16
- const Geo_1 = require("../Geo");
17
- const ioc_1 = require("../ioc");
18
- const models_1 = require("./");
19
- const errors_1 = require("@golemio/errors");
20
- const moment_timezone_1 = __importDefault(require("moment-timezone"));
21
- /**
22
- * General model for GeoJSON data. Geo-spatial indexing and querying. Implements general GetAll and GetOne functions
23
- *
24
- * Expects GeoJSON data structure:
25
- *
26
- * geometry: { coordinates[], type },
27
- *
28
- * properties: { ... }
29
- *
30
- * type: Feature
31
- *
32
- * Model /DATA ACCESS LAYER/: Defines data structure, connects to DB storage and retrieves data directly from database.
33
- * Performs database queries.
34
- */
35
- class GeoJsonModel extends models_1.MongoModel {
36
- /**
37
- * Creates a model with specified schema definition
38
- * @param inName Name of the model - corresponding with mongo collection name (eg. "parkings" for "Parking" model)
39
- * @param inSchema Schema of the data to be stored in this model
40
- * @param inCollectionName (optional) Name of the mongo collection
41
- * if empty, collection named as plural of model's name is used
42
- */
43
- constructor(inName, inSchema, inCollectionName) {
44
- super(inName, inSchema, inCollectionName);
45
- /**
46
- * Retrieves properties of the current model
47
- * @returns Array of properties
48
- */
49
- this.GetProperties = () => __awaiter(this, void 0, void 0, function* () {
50
- const result = yield this.model
51
- .aggregate([
52
- { $unwind: "$properties.properties" },
53
- { $group: { _id: "$properties.properties.id", setOne: { $addToSet: "$properties.properties" } } },
54
- { $project: { properties: { $setUnion: ["$setOne"] } } },
55
- ])
56
- .exec();
57
- return result
58
- .map((x) => x.properties)
59
- .reduce((x, y) => x.concat(y))
60
- .map((x) => {
61
- const property = {
62
- id: x.id,
63
- title: x.description,
64
- };
65
- return property;
66
- });
67
- });
68
- this.MapUpdatedAtToISOString = (feature) => {
69
- const properties = feature.properties;
70
- if (!isNaN(properties.updated_at)) {
71
- properties.updated_at = (0, moment_timezone_1.default)(+properties.updated_at).toISOString();
72
- }
73
- feature.properties = properties;
74
- return feature;
75
- };
76
- this.HasRequiredGeojsonProps = (inSchema) => {
77
- if (!inSchema || !inSchema.geometry || !inSchema.type || !inSchema.properties) {
78
- return false;
79
- }
80
- const schemaPropertiesField = inSchema.properties;
81
- if (!schemaPropertiesField.updated_at) {
82
- return false;
83
- }
84
- return true;
85
- };
86
- this.log = ioc_1.OutputGatewayContainer.resolve(ioc_1.ContainerToken.Logger);
87
- // create $geonear index
88
- this.schema.index({ geometry: "2dsphere" });
89
- if (!this.HasRequiredGeojsonProps(inSchema)) {
90
- this.log.warn("Creating " + inName + " GeoJSON model: imported schema not in GeoJSON format!");
91
- this.log.debug(inSchema);
92
- }
93
- }
94
- /** Retrieves all the records from database
95
- * @param options Object with options settings, with following properties.
96
- * @param options.lat Latitude to sort results by (by proximity)
97
- * @param options.lng Longitute to sort results by
98
- * @param options.range Maximum range from specified latLng. Only data within this range will be returned.
99
- * @param options.limit Limit
100
- * @param options.offset Offset
101
- * @param options.updatedSince Filters out all results with older updated_at than this parameter
102
- * (filters not-updated data)
103
- * @param options.additionalFilters Object with additional filter conditions to be added to the selection
104
- * @returns GeoJSON FeatureCollection with all retrieved objects in "features"
105
- */
106
- GetAll(options) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- if (!options) {
109
- options = {};
110
- }
111
- try {
112
- const q = this.model.find({}).lean();
113
- // Specify a query filter conditions to search by geometry location
114
- if (options.lat) {
115
- const selection = {
116
- geometry: {
117
- $near: {
118
- $geometry: {
119
- coordinates: [options.lng, options.lat],
120
- type: Geo_1.GeoCoordinatesType.Point,
121
- },
122
- },
123
- },
124
- };
125
- // Specify max range filter condition
126
- if (options.range !== undefined) {
127
- selection.geometry.$near.$maxDistance = options.range;
128
- }
129
- this.AddSelection(selection);
130
- }
131
- // Specify a query filter conditions to search by last updated time
132
- if (options.updatedSince) {
133
- const unixUpdatedSince = (0, moment_timezone_1.default)(options.updatedSince).unix();
134
- this.AddSelection({ "properties.updated_at": { $gte: unixUpdatedSince * 1000 } });
135
- }
136
- // Specify a query filter conditions to search by districts
137
- if (options.districts) {
138
- this.AddSelection({ "properties.district": { $in: options.districts } });
139
- }
140
- // Specify a query filter conditions to search by IDs
141
- if (options.ids) {
142
- this.AddSelection(this.PrimaryIdentifierSelection({ $in: options.ids }));
143
- }
144
- // Specify a query filter conditions to search by additional filter parameters
145
- if (options.additionalFilters) {
146
- this.AddSelection(options.additionalFilters);
147
- }
148
- q.where(this.selection);
149
- if (options.limit) {
150
- q.limit(options.limit);
151
- }
152
- if (options.offset) {
153
- q.skip(options.offset);
154
- }
155
- q.select(this.projection);
156
- this.log.silly("Executing query with selection: ");
157
- this.log.silly(this.selection);
158
- this.selection = {};
159
- const data = yield q.exec();
160
- // Create GeoJSON FeatureCollection output
161
- const featureCollection = (0, Geo_1.buildGeojsonFeatureCollection)(data);
162
- featureCollection.features = featureCollection.features.map((feature) => this.MapUpdatedAtToISOString(feature));
163
- return featureCollection;
164
- }
165
- catch (err) {
166
- throw new errors_1.CustomError("Database error", true, "GeoJsonModel", 500, err);
167
- }
168
- });
169
- }
170
- /** Retrieves one record from database
171
- * @param inId Id of the record to be retrieved
172
- * @returns Object of the retrieved record or null
173
- */
174
- GetOne(inId) {
175
- return __awaiter(this, void 0, void 0, function* () {
176
- const found = yield this.model.findOne(this.PrimaryIdentifierSelection(inId), "-_id -__v").lean().exec();
177
- if (!found || (found instanceof Array && found.length === 0)) {
178
- this.log.debug("Could not find any record by specified selection.", this.PrimaryIdentifierSelection(inId));
179
- throw new errors_1.CustomError("Id `" + inId + "` not found", true, "GeoJsonModel", 404);
180
- }
181
- else {
182
- return this.MapUpdatedAtToISOString(found);
183
- }
184
- });
185
- }
186
- }
187
- exports.GeoJsonModel = GeoJsonModel;
188
- //# sourceMappingURL=GeoJsonModel.js.map