@6thbridge/utils 1.1.8 → 1.2.0-1
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/lib/data/rabbitmq/rabbitmq.script.js +1 -1
- package/lib/data/rabbitmq/rabbitmq.script.js.map +1 -1
- package/lib/data/redis/index.js +50 -5
- package/lib/data/redis/index.js.map +1 -1
- package/lib/data/redis/redis-example.js +1 -1
- package/lib/data/redis/redis-example.js.map +1 -1
- package/lib/database/MongoDBRepository.d.ts +3 -56
- package/lib/database/MongoDBRepository.js +6 -77
- package/lib/database/MongoDBRepository.js.map +1 -1
- package/lib/database/MongoDBTypeRepository.d.ts +103 -0
- package/lib/database/MongoDBTypeRepository.js +90 -0
- package/lib/database/MongoDBTypeRepository.js.map +1 -0
- package/lib/database/index.d.ts +1 -0
- package/lib/database/index.js +1 -0
- package/lib/database/index.js.map +1 -1
- package/lib/database/meta.entity.d.ts +10 -0
- package/lib/database/meta.entity.js +7 -0
- package/lib/database/meta.entity.js.map +1 -0
- package/lib/database/meta.model.d.ts +37 -0
- package/lib/database/meta.model.js +50 -0
- package/lib/database/meta.model.js.map +1 -0
- package/lib/database/meta.repository.d.ts +7 -0
- package/lib/database/meta.repository.js +16 -0
- package/lib/database/meta.repository.js.map +1 -0
- package/lib/logger/logger.d.ts +2 -2
- package/lib/middlewares/common.js +1 -1
- package/lib/middlewares/common.js.map +1 -1
- package/lib/monitoring/index.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +3 -1
- package/lib/types/index.js.map +1 -1
- package/lib/utils/database.js +11 -11
- package/lib/utils/database.js.map +1 -1
- package/package.json +21 -23
|
@@ -13,7 +13,7 @@ const _1 = require("./");
|
|
|
13
13
|
const helper_1 = require("../../utils/helper");
|
|
14
14
|
function test() {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const rabbitMQURL = 'amqp
|
|
16
|
+
const rabbitMQURL = 'amqp://@localhost:5672/local';
|
|
17
17
|
const config = {
|
|
18
18
|
url: rabbitMQURL,
|
|
19
19
|
retryCountBeforeExit: 10,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq.script.js","sourceRoot":"","sources":["../../../src/data/rabbitmq/rabbitmq.script.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAyD;AACzD,+CAA8C;AAG9C,SAAe,IAAI;;QACf,MAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"rabbitmq.script.js","sourceRoot":"","sources":["../../../src/data/rabbitmq/rabbitmq.script.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yBAAyD;AACzD,+CAA8C;AAG9C,SAAe,IAAI;;QACf,MAAM,WAAW,GAAG,8BAA8B,CAAC;QACnD,MAAM,MAAM,GAA0B;YAClC,GAAG,EAAE,WAAW;YAChB,oBAAoB,EAAE,EAAE;YACxB,MAAM,EAAE;gBACJ;oBACI,SAAS,EAAE,gCAAgC;oBAC3C,YAAY,EAAE;wBACV,OAAO,EAAE,IAAI;qBAChB;iBACJ;aACJ;YACD,SAAS,EAAE;gBACP;oBACI,YAAY,EAAE,8BAA8B;oBAC5C,YAAY,EAAE,QAAQ;oBACtB,eAAe,EAAE;wBACb,OAAO,EAAE,IAAI;qBAChB;iBACJ;aACJ;YACD,gBAAgB,EAAE;gBACd;oBACI,SAAS,EAAE,gCAAgC;oBAC3C,YAAY,EAAE,8BAA8B;oBAC5C,OAAO,EAAE,EAAE;iBACd;aACJ;SACJ,CAAA;QACD,MAAM,QAAQ,GAAG,IAAI,iBAAc,EAAE,CAAC;QACtC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEzB,MAAM,mBAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAE7B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACnB,MAAM,WAAW,GAAG,MAAM,iBAAc,CAAC,WAAW,CAAC,gCAAgC,EAAE;YACnF,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,SAAS;SACrB,EAAE;YACC,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAE1C,MAAM,cAAc,GAAG,MAAM,iBAAc,CAAC,iBAAiB,CAAC,8BAA8B,EAAE,EAAE,EAAE;YAC9F,QAAQ,EAAE,UAAU;YACpB,OAAO,EAAE,SAAS;SACrB,EAAE;YACC,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;QAEhD,MAAM,iBAAc,CAAC,MAAM,CAAC,gCAAgC,EAAE,EAAC,QAAQ,EAAE,CAAC,EAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;YAC9F,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YAClC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;QACH,MAAM,mBAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEhC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;CAAA;AAID,IAAI,EAAE,CAAC"}
|
package/lib/data/redis/index.js
CHANGED
|
@@ -9,6 +9,27 @@ const ioredis_1 = __importDefault(require("ioredis"));
|
|
|
9
9
|
const localhost = process.env.REDIS_HOST || '127.0.0.1';
|
|
10
10
|
const port = process.env.REDIS_PORT || 6379;
|
|
11
11
|
const password = process.env.REDIS_PASSWORD || '';
|
|
12
|
+
const redisDefaultUrl = `redis://${password ? ':' + password + '@' : ''}${localhost}:${port}`;
|
|
13
|
+
const splitConnectionUrls = (urls) => {
|
|
14
|
+
return urls
|
|
15
|
+
.split(',')
|
|
16
|
+
.map((item) => item.trim())
|
|
17
|
+
.filter(Boolean);
|
|
18
|
+
};
|
|
19
|
+
const getHostAndPort = (connectionUrl, defaultPort = 6379) => {
|
|
20
|
+
const normalizedUrl = connectionUrl.includes('://') ? connectionUrl : `redis://${connectionUrl}`;
|
|
21
|
+
const parsedUrl = new URL(normalizedUrl);
|
|
22
|
+
const parsedPort = Number(parsedUrl.port || defaultPort);
|
|
23
|
+
return {
|
|
24
|
+
host: parsedUrl.hostname,
|
|
25
|
+
port: Number.isNaN(parsedPort) ? defaultPort : parsedPort
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const getPasswordFromUrl = (connectionUrl) => {
|
|
29
|
+
const normalizedUrl = connectionUrl.includes('://') ? connectionUrl : `redis://${connectionUrl}`;
|
|
30
|
+
const parsedUrl = new URL(normalizedUrl);
|
|
31
|
+
return parsedUrl.password || undefined;
|
|
32
|
+
};
|
|
12
33
|
class RedisClient {
|
|
13
34
|
/**
|
|
14
35
|
* Get the singleton instance of Redis
|
|
@@ -29,13 +50,37 @@ class RedisClient {
|
|
|
29
50
|
}
|
|
30
51
|
connect(config = {}) {
|
|
31
52
|
this.config = config;
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
const sentinelUrlsRaw = process.env.REDIS_SENTINEL_URLS;
|
|
54
|
+
const clusterUrlsRaw = process.env.REDIS_CLUSTER_URLS || process.env.REDIS_CLUSTER_URL;
|
|
55
|
+
const standaloneUrl = config.url || process.env.REDIS_URL || redisDefaultUrl;
|
|
56
|
+
const standalonePassword = getPasswordFromUrl(standaloneUrl);
|
|
57
|
+
if (sentinelUrlsRaw) {
|
|
58
|
+
const sentinelUrls = splitConnectionUrls(sentinelUrlsRaw);
|
|
59
|
+
const sentinelPasswordFromUrl = sentinelUrls.length > 0 ? getPasswordFromUrl(sentinelUrls[0]) : undefined;
|
|
60
|
+
const sentinelNodes = sentinelUrls.map((url) => getHostAndPort(url, 26379));
|
|
61
|
+
console.log('Redis connection mode: sentinel', {
|
|
62
|
+
sentinelName: process.env.REDIS_SENTINEL_NAME || 'mymaster',
|
|
63
|
+
sentinelCount: sentinelNodes.length
|
|
64
|
+
});
|
|
65
|
+
this.redis = new ioredis_1.default({
|
|
66
|
+
sentinels: sentinelNodes,
|
|
67
|
+
name: process.env.REDIS_SENTINEL_NAME || 'mymaster',
|
|
68
|
+
password: process.env.REDIS_PASSWORD || standalonePassword || sentinelPasswordFromUrl,
|
|
69
|
+
sentinelPassword: process.env.REDIS_SENTINEL_PASSWORD || sentinelPasswordFromUrl
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else if (clusterUrlsRaw) {
|
|
73
|
+
const clusterNodes = splitConnectionUrls(clusterUrlsRaw).map(getHostAndPort);
|
|
74
|
+
console.log('Redis connection mode: cluster', {
|
|
75
|
+
nodeCount: clusterNodes.length
|
|
76
|
+
});
|
|
77
|
+
this.redis = new ioredis_1.default.Cluster(clusterNodes);
|
|
36
78
|
}
|
|
37
79
|
else {
|
|
38
|
-
|
|
80
|
+
console.log('Redis connection mode: standalone', {
|
|
81
|
+
url: standaloneUrl
|
|
82
|
+
});
|
|
83
|
+
this.redis = new ioredis_1.default(standaloneUrl);
|
|
39
84
|
}
|
|
40
85
|
this.redis.on('connected', function () {
|
|
41
86
|
console.log('Redis is connected');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data/redis/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AACb,8BAAgC;AAEhC,sDAAgD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data/redis/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AACb,8BAAgC;AAEhC,sDAAgD;AAMhD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,WAAW,CAAC;AACxD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI,CAAC;AAC5C,MAAM,QAAQ,GAAG,O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,CAAC;QAC5C,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACnB,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QACvD,CAAC;QAED,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC5B,WAAW,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAErC,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAGO,SAAS;QACb,UAAM,CAAC,GAAG,CAAC,iBAAiB,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3E,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAEM,iBAAiB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAEM,MAAM,CAAC,iBAAiB;QAC3B,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC,iBAAiB,EAAE,CAAC;IACzD,CAAC;IACO,MAAM,CAAC,QAAQ;QAClB,OAAO,WAAW,CAAC,WAAW,EAAE,CAAC,iBAAiB,EAAE,CAAC;IAEzD,CAAC;;AA/FN,kCAgGC;AA/FkB,oBAAQ,GAAuB,IAAI,CAAC"}
|
|
@@ -15,7 +15,7 @@ function redisExample() {
|
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const redis = new index_1.RedisClient();
|
|
17
17
|
redis.connect({
|
|
18
|
-
url:
|
|
18
|
+
url: 'redis://localhost:6379'
|
|
19
19
|
});
|
|
20
20
|
const setResult = yield index_1.RedisClient.getRedis().set("ping", "pong");
|
|
21
21
|
console.log("setResult: ", setResult);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-example.js","sourceRoot":"","sources":["../../../src/data/redis/redis-example.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAoC;AACpC,+CAA8C;AAG9C,SAAe,YAAY;;QACvB,MAAM,KAAK,GAAG,IAAI,mBAAW,EAAE,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC;YACV,GAAG,EAAE,wBAAwB;SAChC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"redis-example.js","sourceRoot":"","sources":["../../../src/data/redis/redis-example.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAoC;AACpC,+CAA8C;AAG9C,SAAe,YAAY;;QACvB,MAAM,KAAK,GAAG,IAAI,mBAAW,EAAE,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC;YACV,GAAG,EAAE,wBAAwB;SAChC,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,MAAM,mBAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QAEtC,MAAM,SAAS,GAAG,MAAM,mBAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QAGtC,MAAM,mBAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAEnC,CAAC;CAAA;AAGD,YAAY,EAAE,CAAC"}
|
|
@@ -1,58 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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/session" />
|
|
19
|
-
/// <reference types="mongoose/types/types" />
|
|
20
|
-
/// <reference types="mongoose/types/utility" />
|
|
21
|
-
/// <reference types="mongoose/types/validation" />
|
|
22
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
23
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
|
-
/// <reference types="mongoose-paginate-v2" />
|
|
27
|
-
import { ClientSession, CreateOptions, ProjectionType, QueryOptions, PaginateResult, PaginateModel, Model, InsertManyOptions } from 'mongoose';
|
|
28
|
-
export declare class MongooseOptions {
|
|
29
|
-
session?: ClientSession | null;
|
|
30
|
-
[x: string]: any;
|
|
31
|
-
}
|
|
32
|
-
export declare class FindOptions extends MongooseOptions {
|
|
33
|
-
[x: string]: any;
|
|
34
|
-
page?: number;
|
|
35
|
-
limit?: number;
|
|
36
|
-
lean?: boolean;
|
|
37
|
-
}
|
|
38
|
-
export type TypedModel<T> = PaginateModel<T> | Model<T>;
|
|
39
|
-
export declare class MongoDBRepository {
|
|
40
|
-
private readonly Model;
|
|
1
|
+
import { FindOptions, MongoDBTypeRepository, MongooseOptions, TypedModel } from './MongoDBTypeRepository';
|
|
2
|
+
export { FindOptions, MongooseOptions, TypedModel, };
|
|
3
|
+
export declare class MongoDBRepository<TEntity = any> extends MongoDBTypeRepository<TEntity> {
|
|
41
4
|
constructor(Model: TypedModel<any>);
|
|
42
|
-
getModel(): TypedModel<any>;
|
|
43
|
-
create(payload: Record<string, any>, options?: CreateOptions): Promise<any>;
|
|
44
|
-
findById(id: string, projection?: ProjectionType<any>, options?: QueryOptions): import("mongoose").Query<any, any, {}, any, "findOne", {}>;
|
|
45
|
-
findOne(condition?: Record<string, any>, sort?: Record<string, number>, options?: FindOptions): import("mongoose").Query<any, any, {}, any, "findOne", {}>;
|
|
46
|
-
find(condition: Record<string, any>, sort?: Record<string, any>, options?: FindOptions): import("mongoose").Query<any[], any, {}, any, "find", {}>;
|
|
47
|
-
paginate(condition: Record<string, any>, sort?: Record<string, any>, options?: FindOptions): Promise<PaginateResult<any>>;
|
|
48
|
-
deleteMany(condition?: Record<string, any>, options?: MongooseOptions): import("mongoose").Query<import("mongodb").DeleteResult, any, {}, any, "deleteMany", {}>;
|
|
49
|
-
insertMany(data: any[] | undefined, options: InsertManyOptions & {
|
|
50
|
-
lean: true;
|
|
51
|
-
}): never[] | Promise<any[]>;
|
|
52
|
-
countDocuments(condition?: Record<string, any>, options?: MongooseOptions): import("mongoose").Query<number, any, {}, any, "countDocuments", {}>;
|
|
53
|
-
updateOne(query?: Record<string, any>, update?: Record<string, any>, options?: MongooseOptions): import("mongoose").Query<import("mongoose").UpdateWriteOpResult, any, {}, any, "updateOne", {}>;
|
|
54
|
-
updateMany(query?: Record<string, any>, update?: Record<string, any>, options?: MongooseOptions): import("mongoose").Query<import("mongoose").UpdateWriteOpResult, any, {}, any, "updateMany", {}>;
|
|
55
|
-
upsert(query?: Record<string, any>, update?: any, options?: MongooseOptions): import("mongoose").Query<import("mongoose").UpdateWriteOpResult, any, {}, any, "updateOne", {}>;
|
|
56
|
-
findOneAndUpdate(filter: any, update: any, options?: MongooseOptions): import("mongoose").Query<any, any, {}, any, "findOneAndUpdate", {}>;
|
|
57
|
-
bulkWrite(bulkWritePayload: any): Promise<import("mongoose").MongooseBulkWriteResult>;
|
|
58
5
|
}
|
|
@@ -1,83 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongoDBRepository = exports.
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
exports
|
|
7
|
-
class
|
|
8
|
-
constructor() {
|
|
9
|
-
super(...arguments);
|
|
10
|
-
this.limit = 100;
|
|
11
|
-
this.lean = false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.FindOptions = FindOptions;
|
|
15
|
-
class MongoDBRepository {
|
|
3
|
+
exports.MongoDBRepository = exports.MongooseOptions = exports.FindOptions = void 0;
|
|
4
|
+
const MongoDBTypeRepository_1 = require("./MongoDBTypeRepository");
|
|
5
|
+
Object.defineProperty(exports, "FindOptions", { enumerable: true, get: function () { return MongoDBTypeRepository_1.FindOptions; } });
|
|
6
|
+
Object.defineProperty(exports, "MongooseOptions", { enumerable: true, get: function () { return MongoDBTypeRepository_1.MongooseOptions; } });
|
|
7
|
+
class MongoDBRepository extends MongoDBTypeRepository_1.MongoDBTypeRepository {
|
|
16
8
|
constructor(Model) {
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
getModel() {
|
|
20
|
-
return this.Model;
|
|
21
|
-
}
|
|
22
|
-
create(payload, options) {
|
|
23
|
-
return this.Model.create(payload, options);
|
|
24
|
-
}
|
|
25
|
-
findById(id, projection, options) {
|
|
26
|
-
return this.Model.findOne({ _id: id }, projection, options);
|
|
27
|
-
}
|
|
28
|
-
findOne(condition = {}, sort, options) {
|
|
29
|
-
const result = this.Model.findOne(condition).sort(sort);
|
|
30
|
-
if (options === null || options === void 0 ? void 0 : options.lean)
|
|
31
|
-
return result.lean();
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
find(condition, sort, options) {
|
|
35
|
-
var _a, _b;
|
|
36
|
-
if (options === null || options === void 0 ? void 0 : options.lean)
|
|
37
|
-
return this.Model.find(condition).sort(sort).lean().session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
38
|
-
return this.Model.find(condition).sort(sort).session((_b = options === null || options === void 0 ? void 0 : options.session) !== null && _b !== void 0 ? _b : null);
|
|
39
|
-
}
|
|
40
|
-
paginate(condition, sort, options) {
|
|
41
|
-
return this.Model.paginate(condition, {
|
|
42
|
-
sort,
|
|
43
|
-
page: options === null || options === void 0 ? void 0 : options.page,
|
|
44
|
-
limit: options === null || options === void 0 ? void 0 : options.limit,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
deleteMany(condition = {}, options) {
|
|
48
|
-
var _a;
|
|
49
|
-
return this.Model.deleteMany(condition).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
50
|
-
}
|
|
51
|
-
insertMany(data = [], options) {
|
|
52
|
-
if (data.length === 0)
|
|
53
|
-
return [];
|
|
54
|
-
return this.Model.insertMany(data, options);
|
|
55
|
-
}
|
|
56
|
-
countDocuments(condition = {}, options) {
|
|
57
|
-
var _a;
|
|
58
|
-
return this.Model.countDocuments(condition).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
59
|
-
}
|
|
60
|
-
updateOne(query = {}, update = {}, options) {
|
|
61
|
-
var _a;
|
|
62
|
-
return this.Model.updateOne(query, update).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
63
|
-
}
|
|
64
|
-
updateMany(query = {}, update = {}, options) {
|
|
65
|
-
var _a;
|
|
66
|
-
return this.Model.updateMany(query, update).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
67
|
-
}
|
|
68
|
-
upsert(query = {}, update = {}, options) {
|
|
69
|
-
var _a;
|
|
70
|
-
return this.Model.updateOne(query, update, {
|
|
71
|
-
upsert: true,
|
|
72
|
-
setDefaultsOnInsert: true,
|
|
73
|
-
}).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
74
|
-
}
|
|
75
|
-
findOneAndUpdate(filter, update, options) {
|
|
76
|
-
var _a;
|
|
77
|
-
return this.Model.findOneAndUpdate(filter, update, Object.assign({ new: true }, options)).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
78
|
-
}
|
|
79
|
-
bulkWrite(bulkWritePayload) {
|
|
80
|
-
return this.Model.bulkWrite(bulkWritePayload);
|
|
9
|
+
super(Model);
|
|
81
10
|
}
|
|
82
11
|
}
|
|
83
12
|
exports.MongoDBRepository = MongoDBRepository;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoDBRepository.js","sourceRoot":"","sources":["../../src/database/MongoDBRepository.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"MongoDBRepository.js","sourceRoot":"","sources":["../../src/database/MongoDBRepository.ts"],"names":[],"mappings":";;;AAAA,mEAKiC;AAG/B,4FAPA,mCAAW,OAOA;AACX,gGANA,uCAAe,OAMA;AAIjB,MAAa,iBAAiC,SAAQ,6CAA8B;IAClF,YAAY,KAAsB;QAChC,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;CACF;AAJD,8CAIC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
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/session" />
|
|
19
|
+
/// <reference types="mongoose/types/types" />
|
|
20
|
+
/// <reference types="mongoose/types/utility" />
|
|
21
|
+
/// <reference types="mongoose/types/validation" />
|
|
22
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
23
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
/// <reference types="mongoose/types/inferhydrateddoctype" />
|
|
26
|
+
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
27
|
+
/// <reference types="mongoose-paginate-v2" />
|
|
28
|
+
import { ClientSession, CreateOptions, Document, FlattenMaps, HydratedDocument, InsertManyOptions, Model, PaginateModel, PaginateResult, ProjectionType, QueryOptions, SortOrder, UpdateQuery } from 'mongoose';
|
|
29
|
+
export declare class MongooseOptions {
|
|
30
|
+
session?: ClientSession | null;
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
}
|
|
33
|
+
export declare class FindOptions extends MongooseOptions {
|
|
34
|
+
[x: string]: any;
|
|
35
|
+
page?: number;
|
|
36
|
+
limit?: number;
|
|
37
|
+
lean?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export type TypedModel<T> = PaginateModel<T> | Model<T>;
|
|
40
|
+
export type RepositoryDocument<TEntity> = TEntity extends Document ? TEntity : HydratedDocument<TEntity>;
|
|
41
|
+
export type LeanRepositoryDocument<TEntity> = FlattenMaps<TEntity>;
|
|
42
|
+
export type RepositoryModel<TEntity> = TypedModel<TEntity>;
|
|
43
|
+
type RepositoryFilter<TEntity> = Partial<TEntity> & Record<string, any>;
|
|
44
|
+
type RepositorySort<TEntity> = Partial<Record<Extract<keyof TEntity, string>, SortOrder>> & Record<string, any>;
|
|
45
|
+
type RepositoryPayload<TEntity> = Partial<TEntity> & Record<string, any>;
|
|
46
|
+
type RepositoryUpdate<TEntity> = UpdateQuery<TEntity> | Record<string, any>;
|
|
47
|
+
export declare class MongoDBTypeRepository<TEntity = any> {
|
|
48
|
+
private readonly Model;
|
|
49
|
+
private readonly model;
|
|
50
|
+
private readonly paginateModel;
|
|
51
|
+
constructor(Model: RepositoryModel<TEntity>);
|
|
52
|
+
getModel(): RepositoryModel<TEntity>;
|
|
53
|
+
create(payload: RepositoryPayload<TEntity>, options?: CreateOptions): Promise<RepositoryDocument<TEntity>>;
|
|
54
|
+
findById(id: string, projection?: ProjectionType<TEntity>, options?: QueryOptions<TEntity>): import("mongoose").Query<import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
55
|
+
__v: number;
|
|
56
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>> | null, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
57
|
+
__v: number;
|
|
58
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "findOne", {}>;
|
|
59
|
+
findOne(condition?: RepositoryFilter<TEntity>, sort?: RepositorySort<TEntity>, options?: FindOptions): import("mongoose").Query<import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
60
|
+
__v: number;
|
|
61
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>> | null, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
62
|
+
__v: number;
|
|
63
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "findOne", {}> | import("mongoose").Query<FlattenMaps<TEntity> | (import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
64
|
+
__v: number;
|
|
65
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>> extends infer T ? T extends import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
66
|
+
__v: number;
|
|
67
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>> ? T extends null ? FlattenMaps<TEntity> | null : FlattenMaps<TEntity> : never : never) | null, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
68
|
+
__v: number;
|
|
69
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "findOne", {}>;
|
|
70
|
+
find(condition: RepositoryFilter<TEntity>, sort?: RepositorySort<TEntity>, options?: FindOptions): import("mongoose").Query<import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
71
|
+
__v: number;
|
|
72
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>[], import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
73
|
+
__v: number;
|
|
74
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "find", {}> | import("mongoose").Query<FlattenMaps<TEntity>, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
75
|
+
__v: number;
|
|
76
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "find", {}>;
|
|
77
|
+
paginate(condition: RepositoryFilter<TEntity>, sort?: RepositorySort<TEntity>, options?: FindOptions): Promise<PaginateResult<RepositoryDocument<TEntity>>>;
|
|
78
|
+
deleteMany(condition?: RepositoryFilter<TEntity>, options?: MongooseOptions): import("mongoose").Query<import("mongodb").DeleteResult, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
79
|
+
__v: number;
|
|
80
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "deleteMany", {}>;
|
|
81
|
+
insertMany(data?: RepositoryPayload<TEntity>[], options?: InsertManyOptions & {
|
|
82
|
+
lean?: boolean;
|
|
83
|
+
}): never[] | Promise<RepositoryDocument<TEntity>[]>;
|
|
84
|
+
countDocuments(condition?: RepositoryFilter<TEntity>, options?: MongooseOptions): import("mongoose").Query<number, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
85
|
+
__v: number;
|
|
86
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "countDocuments", {}>;
|
|
87
|
+
updateOne(query?: RepositoryFilter<TEntity>, update?: RepositoryUpdate<TEntity>, options?: MongooseOptions): import("mongoose").Query<import("mongoose").UpdateWriteOpResult, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
88
|
+
__v: number;
|
|
89
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "updateOne", {}>;
|
|
90
|
+
updateMany(query?: RepositoryFilter<TEntity>, update?: RepositoryUpdate<TEntity>, options?: MongooseOptions): import("mongoose").Query<import("mongoose").UpdateWriteOpResult, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
91
|
+
__v: number;
|
|
92
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "updateMany", {}>;
|
|
93
|
+
upsert(query?: RepositoryFilter<TEntity>, update?: RepositoryUpdate<TEntity>, options?: MongooseOptions): import("mongoose").Query<import("mongoose").UpdateWriteOpResult, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
94
|
+
__v: number;
|
|
95
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "updateOne", {}>;
|
|
96
|
+
findOneAndUpdate(filter: RepositoryFilter<TEntity>, update: RepositoryUpdate<TEntity>, options?: MongooseOptions & QueryOptions<TEntity>): import("mongoose").Query<import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
97
|
+
__v: number;
|
|
98
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>> | null, import("mongoose").IfAny<TEntity, any, Document<unknown, {}, TEntity, {}, import("mongoose").DefaultSchemaOptions> & import("mongoose").Require_id<TEntity> & {
|
|
99
|
+
__v: number;
|
|
100
|
+
} & import("mongoose").AddDefaultId<TEntity, {}, import("mongoose").DefaultSchemaOptions>>, {}, TEntity, "findOneAndUpdate", {}>;
|
|
101
|
+
bulkWrite(bulkWritePayload: Parameters<Model<TEntity>['bulkWrite']>[0]): Promise<import("mongodb").BulkWriteResult>;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoDBTypeRepository = exports.FindOptions = exports.MongooseOptions = void 0;
|
|
4
|
+
class MongooseOptions {
|
|
5
|
+
}
|
|
6
|
+
exports.MongooseOptions = MongooseOptions;
|
|
7
|
+
class FindOptions extends MongooseOptions {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.limit = 100;
|
|
11
|
+
this.lean = false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.FindOptions = FindOptions;
|
|
15
|
+
class MongoDBTypeRepository {
|
|
16
|
+
constructor(Model) {
|
|
17
|
+
this.Model = Model;
|
|
18
|
+
this.model = Model;
|
|
19
|
+
this.paginateModel = Model;
|
|
20
|
+
}
|
|
21
|
+
getModel() {
|
|
22
|
+
return this.Model;
|
|
23
|
+
}
|
|
24
|
+
create(payload, options) {
|
|
25
|
+
return this.model.create(payload, options);
|
|
26
|
+
}
|
|
27
|
+
findById(id, projection, options) {
|
|
28
|
+
return this.model.findOne({ _id: id }, projection, options);
|
|
29
|
+
}
|
|
30
|
+
findOne(condition = {}, sort, options) {
|
|
31
|
+
const result = this.model.findOne(condition).sort(sort);
|
|
32
|
+
if (options === null || options === void 0 ? void 0 : options.lean)
|
|
33
|
+
return result.lean();
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
find(condition, sort, options) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
if (options === null || options === void 0 ? void 0 : options.lean)
|
|
39
|
+
return this.model.find(condition).sort(sort).lean().session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
40
|
+
return this.model.find(condition).sort(sort).session((_b = options === null || options === void 0 ? void 0 : options.session) !== null && _b !== void 0 ? _b : null);
|
|
41
|
+
}
|
|
42
|
+
paginate(condition, sort, options) {
|
|
43
|
+
return this.paginateModel.paginate(condition, {
|
|
44
|
+
sort,
|
|
45
|
+
page: options === null || options === void 0 ? void 0 : options.page,
|
|
46
|
+
limit: options === null || options === void 0 ? void 0 : options.limit,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
deleteMany(condition = {}, options) {
|
|
50
|
+
var _a;
|
|
51
|
+
return this.model.deleteMany(condition).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
52
|
+
}
|
|
53
|
+
insertMany(data = [], options) {
|
|
54
|
+
if (data.length === 0)
|
|
55
|
+
return [];
|
|
56
|
+
const model = this.model;
|
|
57
|
+
if (!options) {
|
|
58
|
+
return model.insertMany(data);
|
|
59
|
+
}
|
|
60
|
+
return model.insertMany(data, options);
|
|
61
|
+
}
|
|
62
|
+
countDocuments(condition = {}, options) {
|
|
63
|
+
var _a;
|
|
64
|
+
return this.model.countDocuments(condition).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
65
|
+
}
|
|
66
|
+
updateOne(query = {}, update = {}, options) {
|
|
67
|
+
var _a;
|
|
68
|
+
return this.model.updateOne(query, update).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
69
|
+
}
|
|
70
|
+
updateMany(query = {}, update = {}, options) {
|
|
71
|
+
var _a;
|
|
72
|
+
return this.model.updateMany(query, update).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
73
|
+
}
|
|
74
|
+
upsert(query = {}, update = {}, options) {
|
|
75
|
+
var _a;
|
|
76
|
+
return this.model.updateOne(query, update, {
|
|
77
|
+
upsert: true,
|
|
78
|
+
setDefaultsOnInsert: true,
|
|
79
|
+
}).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
80
|
+
}
|
|
81
|
+
findOneAndUpdate(filter, update, options) {
|
|
82
|
+
var _a;
|
|
83
|
+
return this.model.findOneAndUpdate(filter, update, Object.assign({ new: true }, options)).session((_a = options === null || options === void 0 ? void 0 : options.session) !== null && _a !== void 0 ? _a : null);
|
|
84
|
+
}
|
|
85
|
+
bulkWrite(bulkWritePayload) {
|
|
86
|
+
return this.model.bulkWrite(bulkWritePayload);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.MongoDBTypeRepository = MongoDBTypeRepository;
|
|
90
|
+
//# sourceMappingURL=MongoDBTypeRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongoDBTypeRepository.js","sourceRoot":"","sources":["../../src/database/MongoDBTypeRepository.ts"],"names":[],"mappings":";;;AAgBA,MAAa,eAAe;CAG3B;AAHD,0CAGC;AAED,MAAa,WAAY,SAAQ,eAAe;IAAhD;;QAIE,UAAK,GAAY,GAAG,CAAC;QACrB,SAAI,GAAa,KAAK,CAAC;IACzB,CAAC;CAAA;AAND,kCAMC;AAYD,MAAa,qBAAqB;IAIhC,YAA6B,KAA+B;QAA/B,UAAK,GAAL,KAAK,CAA0B;QAC1D,IAAI,CAAC,KAAK,GAAG,KAAuB,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,KAA+B,CAAC;IACvD,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,OAAmC,EAAE,OAAuB;QACjE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAc,EAAE,OAAO,CAAyC,CAAC;IAC5F,CAAC;IAED,QAAQ,CAAC,EAAU,EAAE,UAAoC,EAAE,OAA+B;QACxF,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,CAAC,YAAuC,EAAE,EAAE,IAA8B,EAAE,OAAqB;QACtG,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,C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AAO,CAAE,OAAO,mCAAI,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,gBAAgB,CAAC,MAAiC,EAAE,MAAiC,EAAE,OAAiD;;QACtI,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,kBAC/C,GAAG,EAAE,IAAI,IACN,OAAO,EACV,CAAC,OAAO,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,SAAS,CAAC,gBAA4D;QACpE,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,gBAAuB,CAAC,CAAC;IACvD,CAAC;CACF;AAtFD,sDAsFC"}
|
package/lib/database/index.d.ts
CHANGED
package/lib/database/index.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.MongoDB = exports.mongoosePaginate = void 0;
|
|
|
21
21
|
const mongoose_paginate_v2_1 = __importDefault(require("mongoose-paginate-v2"));
|
|
22
22
|
exports.mongoosePaginate = mongoose_paginate_v2_1.default;
|
|
23
23
|
__exportStar(require("./MongoDBRepository"), exports);
|
|
24
|
+
__exportStar(require("./MongoDBTypeRepository"), exports);
|
|
24
25
|
class MongoDB {
|
|
25
26
|
}
|
|
26
27
|
exports.MongoDB = MongoDB;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,gFAAoD;AAC3C,2BADF,8BAAgB,CACE;AACzB,sDAAoC;AACpC,MAAa,OAAO;CAMnB;AAND,0BAMC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,gFAAoD;AAC3C,2BADF,8BAAgB,CACE;AACzB,sDAAoC;AACpC,0DAAwC;AACxC,MAAa,OAAO;CAMnB;AAND,0BAMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.entity.js","sourceRoot":"","sources":["../../src/database/meta.entity.ts"],"names":[],"mappings":";;;AAEA,MAAa,UAAU;CAStB;AATD,gCASC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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/session" />
|
|
19
|
+
/// <reference types="mongoose/types/types" />
|
|
20
|
+
/// <reference types="mongoose/types/utility" />
|
|
21
|
+
/// <reference types="mongoose/types/validation" />
|
|
22
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
23
|
+
/// <reference types="mongoose" />
|
|
24
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
25
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
26
|
+
/// <reference types="mongoose/types/inferhydrateddoctype" />
|
|
27
|
+
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
28
|
+
/// <reference types="mongoose-paginate-v2" />
|
|
29
|
+
import { MetaEntity } from "./meta.entity";
|
|
30
|
+
declare const _default: import("mongoose").Model<MetaEntity, {}, {}, {}, import("mongoose").Document<unknown, {}, MetaEntity, {}, import("mongoose").DefaultSchemaOptions> & MetaEntity & {
|
|
31
|
+
_id: import("mongoose").Types.ObjectId;
|
|
32
|
+
} & {
|
|
33
|
+
__v: number;
|
|
34
|
+
} & {
|
|
35
|
+
id: string;
|
|
36
|
+
}, any, MetaEntity>;
|
|
37
|
+
export = _default;
|