@golemio/core 1.6.6 → 1.6.7-dev.846525251
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 +0 -1
- package/bin/import-test-data.js +0 -72
- package/dist/helpers/HealthCheck.d.ts +0 -1
- package/dist/helpers/HealthCheck.js +0 -1
- package/dist/helpers/HealthCheck.js.map +1 -1
- package/dist/integration-engine/config/IntegrationEngineConfiguration.d.ts +0 -1
- package/dist/integration-engine/config/IntegrationEngineConfiguration.js +0 -1
- package/dist/integration-engine/config/IntegrationEngineConfiguration.js.map +1 -1
- package/dist/integration-engine/config/abstract.d.ts +0 -1
- package/dist/integration-engine/connectors/index.d.ts +0 -6
- package/dist/integration-engine/connectors/index.js +1 -6
- package/dist/integration-engine/connectors/index.js.map +1 -1
- package/dist/integration-engine/datasources/IDataSource.d.ts +2 -2
- package/dist/integration-engine/ioc/ContainerToken.d.ts +0 -1
- package/dist/integration-engine/ioc/ContainerToken.js +0 -1
- package/dist/integration-engine/ioc/ContainerToken.js.map +1 -1
- package/dist/integration-engine/ioc/Di.js +0 -2
- package/dist/integration-engine/ioc/Di.js.map +1 -1
- package/dist/integration-engine/models/IModel.d.ts +0 -12
- package/dist/integration-engine/models/PostgresModel.js +1 -1
- package/dist/integration-engine/models/PostgresModel.js.map +1 -1
- package/dist/integration-engine/models/index.d.ts +0 -1
- package/dist/integration-engine/models/index.js +0 -1
- package/dist/integration-engine/models/index.js.map +1 -1
- package/dist/monitoring/opentelemetry/instrumentation/configs/index.d.ts +0 -1
- package/dist/monitoring/opentelemetry/instrumentation/configs/index.js +1 -3
- package/dist/monitoring/opentelemetry/instrumentation/configs/index.js.map +1 -1
- package/dist/monitoring/opentelemetry/instrumentation/index.d.ts +1 -2
- package/dist/monitoring/opentelemetry/instrumentation/index.js +0 -2
- package/dist/monitoring/opentelemetry/instrumentation/index.js.map +1 -1
- package/dist/monitoring/sentry/sentry-provider.js +0 -1
- package/dist/monitoring/sentry/sentry-provider.js.map +1 -1
- package/dist/output-gateway/Geo.d.ts +1 -1
- package/dist/output-gateway/config/OutputGatewayConfiguration.d.ts +0 -3
- package/dist/output-gateway/config/OutputGatewayConfiguration.js +0 -11
- package/dist/output-gateway/config/OutputGatewayConfiguration.js.map +1 -1
- package/dist/output-gateway/database/index.d.ts +1 -30
- package/dist/output-gateway/database/index.js +1 -6
- package/dist/output-gateway/database/index.js.map +1 -1
- package/dist/output-gateway/ioc/ContainerToken.d.ts +0 -1
- package/dist/output-gateway/ioc/ContainerToken.js +0 -1
- package/dist/output-gateway/ioc/ContainerToken.js.map +1 -1
- package/dist/output-gateway/ioc/Di.js +0 -2
- package/dist/output-gateway/ioc/Di.js.map +1 -1
- package/dist/output-gateway/models/index.d.ts +0 -3
- package/dist/output-gateway/models/index.js +0 -3
- package/dist/output-gateway/models/index.js.map +1 -1
- package/dist/output-gateway/routes/index.d.ts +0 -2
- package/dist/output-gateway/routes/index.js +0 -2
- package/dist/output-gateway/routes/index.js.map +1 -1
- package/package.json +3 -6
- package/dist/integration-engine/connectors/MongoConnector.d.ts +0 -15
- package/dist/integration-engine/connectors/MongoConnector.js +0 -89
- package/dist/integration-engine/connectors/MongoConnector.js.map +0 -1
- package/dist/integration-engine/connectors/interfaces/IMongoConnector.d.ts +0 -7
- package/dist/integration-engine/connectors/interfaces/IMongoConnector.js +0 -3
- package/dist/integration-engine/connectors/interfaces/IMongoConnector.js.map +0 -1
- package/dist/integration-engine/models/MongoModel.d.ts +0 -42
- package/dist/integration-engine/models/MongoModel.js +0 -245
- package/dist/integration-engine/models/MongoModel.js.map +0 -1
- package/dist/monitoring/opentelemetry/instrumentation/configs/mongoose.d.ts +0 -2
- package/dist/monitoring/opentelemetry/instrumentation/configs/mongoose.js +0 -20
- package/dist/monitoring/opentelemetry/instrumentation/configs/mongoose.js.map +0 -1
- package/dist/output-gateway/database/MongoDatabase.d.ts +0 -19
- package/dist/output-gateway/database/MongoDatabase.js +0 -89
- package/dist/output-gateway/database/MongoDatabase.js.map +0 -1
- package/dist/output-gateway/models/GeoJsonModel.d.ts +0 -56
- package/dist/output-gateway/models/GeoJsonModel.js +0 -188
- package/dist/output-gateway/models/GeoJsonModel.js.map +0 -1
- package/dist/output-gateway/models/HistoryModel.d.ts +0 -30
- package/dist/output-gateway/models/HistoryModel.js +0 -96
- package/dist/output-gateway/models/HistoryModel.js.map +0 -1
- package/dist/output-gateway/models/MongoModel.d.ts +0 -74
- package/dist/output-gateway/models/MongoModel.js +0 -87
- package/dist/output-gateway/models/MongoModel.js.map +0 -1
- package/dist/output-gateway/routes/HistoryRouter.d.ts +0 -7
- package/dist/output-gateway/routes/HistoryRouter.js +0 -46
- package/dist/output-gateway/routes/HistoryRouter.js.map +0 -1
- package/dist/output-gateway/routes/RouterBuilder.d.ts +0 -70
- package/dist/output-gateway/routes/RouterBuilder.js +0 -92
- package/dist/output-gateway/routes/RouterBuilder.js.map +0 -1
- package/dist/shared/mongoose.d.ts +0 -2
- package/dist/shared/mongoose.js +0 -7
- package/dist/shared/mongoose.js.map +0 -1
|
@@ -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 @@
|
|
|
1
|
-
{"version":3,"file":"MongoDatabase.js","sourceRoot":"","sources":["../../../src/output-gateway/database/MongoDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0DAAwD;AACxD,qFAAmF;AACnF,4CAA8C;AAC9C,wDAAoD;AACpD,uCAA0D;AAE1D;;GAEG;AAEH,IAAa,aAAa,GAA1B,MAAa,aAAa;IAItB,+BAA+B;IAC/B,YACmC,MAAkC,EACjB,GAAY;QAAZ,QAAG,GAAH,GAAG,CAAS;QAMhE,qBAAqB;QACd,YAAO,GAAG,GAAuC,EAAE;YACtD,IAAI;gBACA,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,gBAAgB,KAAK,kCAAkC,EAAE;oBACxF,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;iBACnD;gBACD,MAAM,cAAc,GAAmB;oBACnC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;oBACvC,wBAAwB,EAAE,IAAI,CAAC,gBAAgB;iBAClD,CAAC;gBAEF,MAAM,kBAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;gBAE9D,kBAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;oBACxC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;gBAC7C,CAAC,CAAC,CAAC;gBAEH,kBAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE;oBACvC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,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AM,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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GeoJsonModel.js","sourceRoot":"","sources":["../../../src/output-gateway/models/GeoJsonModel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,gCAAwH;AACxH,gCAAiE;AACjE,+BAAwC;AAGxC,4CAA8C;AAC9C,sEAAqC;AAIrC;;;;;;;;;;;;;GAaG;AACH,MAAa,YAAa,SAAQ,mBAAU;IAExC;;;;;;OAMG;IACH,YAAmB,MAAc,EAAE,QAA0B,EAAE,gBAAyB;QACpF,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QA2G9C;;;WAGG;QACI,kBAAa,GAAG,GAA4C,EAAE;YACjE,MAAM,MAAM,GAAU,MAAM,IAAI,CAAC,KAAK;iBACjC,SAAS,CAAC;gBACP,EAAE,OAAO,EAAE,wBAAwB,EAAE;gBACrC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,2BAA2B,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,wBAAwB,EAAE,EAAE,EAAE;gBACjG,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE;aAC3D,CAAC;iBACD,IAAI,EAAE,CAAC;YACZ,OAAO,MAAM;iBACR,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;iBACxB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAC7B,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE;gBACZ,MAAM,QAAQ,GAA2B;oBACrC,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,KAAK,EAAE,CAAC,CAAC,WAAW;iBACvB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;OAGG;IACU,MAAM,CAAC,IAAS;;YACzB,MAAM,KAAK,GAAoB,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YAC1H,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE;gBAC1D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,mDAAmD,EAAE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC3G,MAAM,IAAI,oBAAW,CAAC,MAAM,GAAG,IAAI,GAAG,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC;aACnF;iBAAM;gBACH,OAAO,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;aAC9C;QACL,CAAC;KAAA;CA6CJ;AAhKD,oCAgKC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { SchemaDefinition } from "mongoose";
|
|
2
|
-
import { MongoModel } from "./";
|
|
3
|
-
export declare class HistoryModel extends MongoModel {
|
|
4
|
-
/**
|
|
5
|
-
* Location of the property by which to filter the data according to sensor id
|
|
6
|
-
*/
|
|
7
|
-
primarySensorIdPropertyLocation: string;
|
|
8
|
-
/**
|
|
9
|
-
* Location of the property by which to filter (from-to) and sort the data according to time
|
|
10
|
-
*/
|
|
11
|
-
protected primaryTimePropertyLocation: string;
|
|
12
|
-
/**
|
|
13
|
-
* Instantiates the model according to the given schema.
|
|
14
|
-
*/
|
|
15
|
-
constructor(inName: string, inSchema: SchemaDefinition, inCollectionName?: string, timePropertyLocation?: string, sensorIdPropertyLocation?: string);
|
|
16
|
-
GetAll: (options: {
|
|
17
|
-
limit?: number;
|
|
18
|
-
offset?: number;
|
|
19
|
-
from?: number;
|
|
20
|
-
to?: number;
|
|
21
|
-
sensorId?: string | number;
|
|
22
|
-
}) => Promise<any[]>;
|
|
23
|
-
PrimaryIdentifierSelection: (inId: any) => object;
|
|
24
|
-
/**
|
|
25
|
-
* Get one historical entry
|
|
26
|
-
* @param inId Id of the record to be retrieved
|
|
27
|
-
* @returns Object of the retrieved record or null
|
|
28
|
-
*/
|
|
29
|
-
GetOne: (inId: any) => Promise<object>;
|
|
30
|
-
}
|
|
@@ -1,96 +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.HistoryModel = void 0;
|
|
16
|
-
const errors_1 = require("@golemio/errors");
|
|
17
|
-
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
18
|
-
const models_1 = require("./");
|
|
19
|
-
const Logger_1 = require("../Logger");
|
|
20
|
-
class HistoryModel extends models_1.MongoModel {
|
|
21
|
-
/**
|
|
22
|
-
* Instantiates the model according to the given schema.
|
|
23
|
-
*/
|
|
24
|
-
constructor(inName, inSchema, inCollectionName, timePropertyLocation, sensorIdPropertyLocation) {
|
|
25
|
-
super(inName, inSchema, inCollectionName);
|
|
26
|
-
/**
|
|
27
|
-
* Location of the property by which to filter the data according to sensor id
|
|
28
|
-
*/
|
|
29
|
-
this.primarySensorIdPropertyLocation = "id";
|
|
30
|
-
/**
|
|
31
|
-
* Location of the property by which to filter (from-to) and sort the data according to time
|
|
32
|
-
*/
|
|
33
|
-
this.primaryTimePropertyLocation = "updated_at";
|
|
34
|
-
this.GetAll = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
try {
|
|
36
|
-
const q = this.model.find().lean();
|
|
37
|
-
if (options.limit) {
|
|
38
|
-
q.limit(options.limit);
|
|
39
|
-
}
|
|
40
|
-
if (options.offset) {
|
|
41
|
-
q.skip(options.offset);
|
|
42
|
-
}
|
|
43
|
-
if (options.from) {
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
q.where({ [this.primaryTimePropertyLocation]: { $gt: options.from } });
|
|
46
|
-
}
|
|
47
|
-
if (options.to) {
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
q.where({ [this.primaryTimePropertyLocation]: { $lt: options.to } });
|
|
50
|
-
}
|
|
51
|
-
if (options.sensorId != null) {
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
q.where({ [this.primarySensorIdPropertyLocation]: { $in: options.sensorId } });
|
|
54
|
-
}
|
|
55
|
-
q.select(this.projection);
|
|
56
|
-
q.sort({ [this.primaryTimePropertyLocation]: -1 });
|
|
57
|
-
const data = yield q.exec();
|
|
58
|
-
return data.map((record) => {
|
|
59
|
-
if (record.updated_at) {
|
|
60
|
-
record.updated_at = (0, moment_timezone_1.default)(record.updated_at).toISOString();
|
|
61
|
-
}
|
|
62
|
-
return record;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
throw new errors_1.CustomError("Database error", true, "HistoryModel", 500, err);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
this.PrimaryIdentifierSelection = (inId) => {
|
|
70
|
-
return { id: inId };
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Get one historical entry
|
|
74
|
-
* @param inId Id of the record to be retrieved
|
|
75
|
-
* @returns Object of the retrieved record or null
|
|
76
|
-
*/
|
|
77
|
-
this.GetOne = (inId) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const found = yield this.model.findOne(this.PrimaryIdentifierSelection(inId), this.projection).exec();
|
|
79
|
-
if (!found || (found instanceof Array && found.length === 0)) {
|
|
80
|
-
Logger_1.log.debug("Could not find any record by specified selection.", this.PrimaryIdentifierSelection(inId));
|
|
81
|
-
throw new errors_1.CustomError("Id `" + inId + "` not found", true, "HistoryModel", 404);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return found;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
if (timePropertyLocation) {
|
|
88
|
-
this.primaryTimePropertyLocation = timePropertyLocation;
|
|
89
|
-
}
|
|
90
|
-
if (sensorIdPropertyLocation) {
|
|
91
|
-
this.primarySensorIdPropertyLocation = sensorIdPropertyLocation;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.HistoryModel = HistoryModel;
|
|
96
|
-
//# sourceMappingURL=HistoryModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HistoryModel.js","sourceRoot":"","sources":["../../../src/output-gateway/models/HistoryModel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAA8C;AAC9C,sEAAqC;AAErC,+BAAwC;AACxC,sCAAiC;AAEjC,MAAa,YAAa,SAAQ,mBAAU;IAWxC;;OAEG;IACH,YACI,MAAc,EACd,QAA0B,EAC1B,gBAAyB,EACzB,oBAA6B,EAC7B,wBAAiC;QAEjC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QApB9C;;WAEG;QACI,oCAA+B,GAAW,IAAI,CAAC;QAEtD;;WAEG;QACO,gCAA2B,GAAW,YAAY,CAAC;QAqBtD,WAAM,GAAG,CAAO,OAMtB,EAAE,EAA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0 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
import { BaseModel } from "./";
|
|
26
|
-
import { Model, Schema, SchemaDefinition } from "mongoose";
|
|
27
|
-
/**
|
|
28
|
-
* General model for data stored in MongoDB.
|
|
29
|
-
*
|
|
30
|
-
* Model /DATA ACCESS LAYER/: Defines data structure, connects to DB storage and retrieves data directly from database.
|
|
31
|
-
* Performs database queries.
|
|
32
|
-
*/
|
|
33
|
-
export declare abstract class MongoModel extends BaseModel {
|
|
34
|
-
/** The Mongoose Model */
|
|
35
|
-
model: Model<any>;
|
|
36
|
-
/** The Mongoose Schema object, defining structure of the data */
|
|
37
|
-
protected schema: Schema;
|
|
38
|
-
/** Name of the mongo collection where the model is stored in the database */
|
|
39
|
-
protected collectionName: string | undefined;
|
|
40
|
-
/** Selection object to filter the retrieved records */
|
|
41
|
-
protected selection: object;
|
|
42
|
-
/** Projection object to filter the retrieved record's attributes */
|
|
43
|
-
protected projection: object;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a model with specified schema definition
|
|
46
|
-
* @param inName Name of the model - corresponding with mongo collection name (eg. "parkings" for "Parking" model)
|
|
47
|
-
* @param inSchema Schema of the data
|
|
48
|
-
* @param inCollectionName (optional) Name of the mongo collection
|
|
49
|
-
* if empty, collection named as plural of model's name is used
|
|
50
|
-
*/
|
|
51
|
-
constructor(inName: string, inSchema: SchemaDefinition, inCollectionName?: string);
|
|
52
|
-
/**
|
|
53
|
-
* Returns current schema of the data
|
|
54
|
-
*/
|
|
55
|
-
GetSchema: () => Promise<Schema<any, Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
|
|
56
|
-
[x: string]: any;
|
|
57
|
-
}>>;
|
|
58
|
-
/**
|
|
59
|
-
* Specifies where is the primary ID of the entity.
|
|
60
|
-
* Searches by this selection in FindOne()
|
|
61
|
-
*/
|
|
62
|
-
PrimaryIdentifierSelection: (inId: any) => object;
|
|
63
|
-
IsPrimaryIdNumber: (idKey: string) => Promise<boolean>;
|
|
64
|
-
/**
|
|
65
|
-
* Adds a new selection condition to filter the retrieved results by
|
|
66
|
-
* @param newCondition New condition/filter object to be added to the "where" clause
|
|
67
|
-
*/
|
|
68
|
-
protected AddSelection: (newCondition: object) => void;
|
|
69
|
-
/**
|
|
70
|
-
* Adds a new projection to filter what attributes to retrieve from the selected objects
|
|
71
|
-
* @param newFilter New filter to be added to the "select" clause
|
|
72
|
-
*/
|
|
73
|
-
protected AddProjection: (newFilter: object) => void;
|
|
74
|
-
}
|
|
@@ -1,87 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.MongoModel = void 0;
|
|
13
|
-
const models_1 = require("./");
|
|
14
|
-
const mongoose_1 = require("mongoose");
|
|
15
|
-
/**
|
|
16
|
-
* General model for data stored in MongoDB.
|
|
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
|
-
class MongoModel extends models_1.BaseModel {
|
|
22
|
-
/**
|
|
23
|
-
* Creates a model with specified schema definition
|
|
24
|
-
* @param inName Name of the model - corresponding with mongo collection name (eg. "parkings" for "Parking" model)
|
|
25
|
-
* @param inSchema Schema of the data
|
|
26
|
-
* @param inCollectionName (optional) Name of the mongo collection
|
|
27
|
-
* if empty, collection named as plural of model's name is used
|
|
28
|
-
*/
|
|
29
|
-
constructor(inName, inSchema, inCollectionName) {
|
|
30
|
-
super(inName);
|
|
31
|
-
/** Selection object to filter the retrieved records */
|
|
32
|
-
this.selection = {};
|
|
33
|
-
/** Projection object to filter the retrieved record's attributes */
|
|
34
|
-
this.projection = {};
|
|
35
|
-
/**
|
|
36
|
-
* Returns current schema of the data
|
|
37
|
-
*/
|
|
38
|
-
this.GetSchema = () => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
return this.schema;
|
|
40
|
-
});
|
|
41
|
-
// TODO: Careful, Router takes this keys()[0] as a decision, if ID parameter can be string or number,
|
|
42
|
-
// that's weird dependency - selection with $or on two attributes for example will fail!
|
|
43
|
-
/**
|
|
44
|
-
* Specifies where is the primary ID of the entity.
|
|
45
|
-
* Searches by this selection in FindOne()
|
|
46
|
-
*/
|
|
47
|
-
this.PrimaryIdentifierSelection = (inId) => {
|
|
48
|
-
return { "properties.id": inId };
|
|
49
|
-
};
|
|
50
|
-
this.IsPrimaryIdNumber = (idKey) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const schema = yield this.GetSchema();
|
|
52
|
-
return schema.path(idKey) instanceof mongoose_1.Schema.Types.Number;
|
|
53
|
-
});
|
|
54
|
-
/**
|
|
55
|
-
* Adds a new selection condition to filter the retrieved results by
|
|
56
|
-
* @param newCondition New condition/filter object to be added to the "where" clause
|
|
57
|
-
*/
|
|
58
|
-
this.AddSelection = (newCondition) => {
|
|
59
|
-
this.selection = Object.assign(Object.assign({}, this.selection), newCondition);
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Adds a new projection to filter what attributes to retrieve from the selected objects
|
|
63
|
-
* @param newFilter New filter to be added to the "select" clause
|
|
64
|
-
*/
|
|
65
|
-
this.AddProjection = (newFilter) => {
|
|
66
|
-
this.projection = Object.assign(Object.assign({}, this.projection), newFilter);
|
|
67
|
-
};
|
|
68
|
-
this.name = inName;
|
|
69
|
-
this.schema = new mongoose_1.Schema(inSchema);
|
|
70
|
-
if (inCollectionName) {
|
|
71
|
-
this.collectionName = inCollectionName;
|
|
72
|
-
}
|
|
73
|
-
// assign existing mongo model or create new one
|
|
74
|
-
try {
|
|
75
|
-
this.model = (0, mongoose_1.model)(this.name); // existing model
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
// uses database collection named as plural of model's name (eg. "parkings" for "Parking" model)
|
|
79
|
-
// or collection name specified in the third parameter
|
|
80
|
-
this.model = (0, mongoose_1.model)(this.name, this.schema, this.collectionName);
|
|
81
|
-
}
|
|
82
|
-
// Don't return default mongoose values and mongo internal ID
|
|
83
|
-
this.AddProjection({ _id: 0, __v: 0 });
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.MongoModel = MongoModel;
|
|
87
|
-
//# sourceMappingURL=MongoModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MongoModel.js","sourceRoot":"","sources":["../../../src/output-gateway/models/MongoModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAuC;AACvC,uCAAkE;AAElE;;;;;GAKG;AACH,MAAsB,UAAW,SAAQ,kBAAS;IAY9C;;;;;;OAMG;IACH,YAAmB,MAAc,EAAE,QAA0B,EAAE,gBAAyB;QACpF,KAAK,CAAC,MAAM,CAAC,CAAC;QAblB,uDAAuD;QAC7C,cAAS,GAAW,EAAE,CAAC;QACjC,oEAAoE;QAC1D,eAAU,GAAW,EAAE,CAAC;QA4BlC;;WAEG;QACI,cAAS,GAAG,GAAS,EAAE;YAC1B,OAAO,IAAI,CAAC,MAAM,CAAC;QACvB,CAAC,CAAA,CAAC;QAEF,qGAAqG;QACrG,wFAAwF;QACxF;;;WAGG;QACI,+BAA0B,GAAG,CAAC,IAAS,EAAU,EAAE;YACtD,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QACrC,CAAC,CAAC;QAEK,sBAAiB,GAAG,CAAO,KAAa,EAAoB,EAAE;YACjE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;YAEtC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,iBAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QAC7D,CAAC,CAAA,CAAC;QAEF;;;WAGG;QACO,iBAAY,GAAG,CAAC,YAAoB,EAAE,EAAE;YAC9C,IAAI,CAAC,SAAS,mCAAQ,IAAI,CAAC,SAAS,GAAK,YAAY,CAAE,CAAC;QAC5D,CAAC,CAA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