@tsed/mongoose 7.0.0-alpha.2 → 7.0.0-beta.11
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/jest.config.js +14 -0
- package/lib/cjs/MongooseModule.js +36 -0
- package/lib/cjs/MongooseModule.js.map +1 -0
- package/lib/cjs/constants/constants.js +24 -0
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/auto.js +28 -0
- package/lib/cjs/decorators/auto.js.map +1 -0
- package/lib/cjs/decorators/discriminatorKey.js +14 -0
- package/lib/cjs/decorators/discriminatorKey.js.map +1 -0
- package/lib/cjs/decorators/dynamicRef.js +65 -0
- package/lib/cjs/decorators/dynamicRef.js.map +1 -0
- package/lib/cjs/decorators/excludeIndexes.js +28 -0
- package/lib/cjs/decorators/excludeIndexes.js.map +1 -0
- package/lib/cjs/decorators/expires.js +28 -0
- package/lib/cjs/decorators/expires.js.map +1 -0
- package/lib/cjs/decorators/immutable.js +30 -0
- package/lib/cjs/decorators/immutable.js.map +1 -0
- package/lib/cjs/decorators/indexed.js +26 -0
- package/lib/cjs/decorators/indexed.js.map +1 -0
- package/lib/cjs/decorators/lowercase.js +28 -0
- package/lib/cjs/decorators/lowercase.js.map +1 -0
- package/lib/cjs/decorators/model.js +68 -0
- package/lib/cjs/decorators/model.js.map +1 -0
- package/lib/cjs/decorators/mongooseIndex.js +39 -0
- package/lib/cjs/decorators/mongooseIndex.js.map +1 -0
- package/lib/cjs/decorators/mongooseIndexes.js +39 -0
- package/lib/cjs/decorators/mongooseIndexes.js.map +1 -0
- package/lib/cjs/decorators/mongoosePlugin.js +22 -0
- package/lib/cjs/decorators/mongoosePlugin.js.map +1 -0
- package/lib/cjs/decorators/numberDecimal.js +78 -0
- package/lib/cjs/decorators/numberDecimal.js.map +1 -0
- package/lib/cjs/decorators/objectID.js +26 -0
- package/lib/cjs/decorators/objectID.js.map +1 -0
- package/lib/cjs/decorators/postHook.js +26 -0
- package/lib/cjs/decorators/postHook.js.map +1 -0
- package/lib/cjs/decorators/preHook.js +71 -0
- package/lib/cjs/decorators/preHook.js.map +1 -0
- package/lib/cjs/decorators/ref.js +75 -0
- package/lib/cjs/decorators/ref.js.map +1 -0
- package/lib/cjs/decorators/schema.js +32 -0
- package/lib/cjs/decorators/schema.js.map +1 -0
- package/lib/cjs/decorators/schemaIgnore.js +27 -0
- package/lib/cjs/decorators/schemaIgnore.js.map +1 -0
- package/lib/cjs/decorators/select.js +28 -0
- package/lib/cjs/decorators/select.js.map +1 -0
- package/lib/cjs/decorators/sparse.js +30 -0
- package/lib/cjs/decorators/sparse.js.map +1 -0
- package/lib/cjs/decorators/text.js +29 -0
- package/lib/cjs/decorators/text.js.map +1 -0
- package/lib/cjs/decorators/trim.js +27 -0
- package/lib/cjs/decorators/trim.js.map +1 -0
- package/lib/cjs/decorators/unique.js +27 -0
- package/lib/cjs/decorators/unique.js.map +1 -0
- package/lib/cjs/decorators/uppercase.js +28 -0
- package/lib/cjs/decorators/uppercase.js.map +1 -0
- package/lib/cjs/decorators/versionKey.js +12 -0
- package/lib/cjs/decorators/versionKey.js.map +1 -0
- package/lib/cjs/decorators/virtualRef.js +38 -0
- package/lib/cjs/decorators/virtualRef.js.map +1 -0
- package/lib/cjs/index.js +51 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/MongooseConnectionOptions.js +3 -0
- package/lib/cjs/interfaces/MongooseConnectionOptions.js.map +1 -0
- package/lib/cjs/interfaces/MongooseDocument.js +3 -0
- package/lib/cjs/interfaces/MongooseDocument.js.map +1 -0
- package/lib/cjs/interfaces/MongooseModel.js +3 -0
- package/lib/cjs/interfaces/MongooseModel.js.map +1 -0
- package/lib/cjs/interfaces/MongooseModelOptions.js +3 -0
- package/lib/cjs/interfaces/MongooseModelOptions.js.map +1 -0
- package/lib/cjs/interfaces/MongooseSchemaOptions.js +3 -0
- package/lib/cjs/interfaces/MongooseSchemaOptions.js.map +1 -0
- package/lib/cjs/interfaces/MongooseSchemaTypes.js +10 -0
- package/lib/cjs/interfaces/MongooseSchemaTypes.js.map +1 -0
- package/lib/cjs/interfaces/MongooseVirtualRefOptions.js +3 -0
- package/lib/cjs/interfaces/MongooseVirtualRefOptions.js.map +1 -0
- package/lib/cjs/interfaces/interfaces.js +3 -0
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/registries/MongooseModels.js +5 -0
- package/lib/cjs/registries/MongooseModels.js.map +1 -0
- package/lib/cjs/services/MongooseConnections.js +47 -0
- package/lib/cjs/services/MongooseConnections.js.map +1 -0
- package/lib/cjs/services/MongooseService.js +73 -0
- package/lib/cjs/services/MongooseService.js.map +1 -0
- package/lib/cjs/utils/createModel.js +54 -0
- package/lib/cjs/utils/createModel.js.map +1 -0
- package/lib/cjs/utils/createSchema.js +160 -0
- package/lib/cjs/utils/createSchema.js.map +1 -0
- package/lib/cjs/utils/resolveRefType.js +19 -0
- package/lib/cjs/utils/resolveRefType.js.map +1 -0
- package/lib/cjs/utils/schemaOptions.js +60 -0
- package/lib/cjs/utils/schemaOptions.js.map +1 -0
- package/lib/esm/MongooseModule.js +33 -0
- package/lib/esm/MongooseModule.js.map +1 -0
- package/lib/esm/constants/constants.js +21 -0
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/auto.js +24 -0
- package/lib/esm/decorators/auto.js.map +1 -0
- package/lib/esm/decorators/discriminatorKey.js +10 -0
- package/lib/esm/decorators/discriminatorKey.js.map +1 -0
- package/lib/esm/decorators/dynamicRef.js +61 -0
- package/lib/esm/decorators/dynamicRef.js.map +1 -0
- package/lib/esm/decorators/excludeIndexes.js +24 -0
- package/lib/esm/decorators/excludeIndexes.js.map +1 -0
- package/lib/esm/decorators/expires.js +24 -0
- package/lib/esm/decorators/expires.js.map +1 -0
- package/lib/esm/decorators/immutable.js +26 -0
- package/lib/esm/decorators/immutable.js.map +1 -0
- package/lib/esm/decorators/indexed.js +22 -0
- package/lib/esm/decorators/indexed.js.map +1 -0
- package/lib/esm/decorators/lowercase.js +24 -0
- package/lib/esm/decorators/lowercase.js.map +1 -0
- package/lib/esm/decorators/model.js +64 -0
- package/lib/esm/decorators/model.js.map +1 -0
- package/lib/esm/decorators/mongooseIndex.js +35 -0
- package/lib/esm/decorators/mongooseIndex.js.map +1 -0
- package/lib/esm/decorators/mongooseIndexes.js +35 -0
- package/lib/esm/decorators/mongooseIndexes.js.map +1 -0
- package/lib/esm/decorators/mongoosePlugin.js +18 -0
- package/lib/esm/decorators/mongoosePlugin.js.map +1 -0
- package/lib/esm/decorators/numberDecimal.js +74 -0
- package/lib/esm/decorators/numberDecimal.js.map +1 -0
- package/lib/esm/decorators/objectID.js +22 -0
- package/lib/esm/decorators/objectID.js.map +1 -0
- package/lib/esm/decorators/postHook.js +22 -0
- package/lib/esm/decorators/postHook.js.map +1 -0
- package/lib/esm/decorators/preHook.js +67 -0
- package/lib/esm/decorators/preHook.js.map +1 -0
- package/lib/esm/decorators/ref.js +71 -0
- package/lib/esm/decorators/ref.js.map +1 -0
- package/lib/esm/decorators/schema.js +27 -0
- package/lib/esm/decorators/schema.js.map +1 -0
- package/lib/esm/decorators/schemaIgnore.js +23 -0
- package/lib/esm/decorators/schemaIgnore.js.map +1 -0
- package/lib/esm/decorators/select.js +24 -0
- package/lib/esm/decorators/select.js.map +1 -0
- package/lib/esm/decorators/sparse.js +26 -0
- package/lib/esm/decorators/sparse.js.map +1 -0
- package/lib/esm/decorators/text.js +25 -0
- package/lib/esm/decorators/text.js.map +1 -0
- package/lib/esm/decorators/trim.js +23 -0
- package/lib/esm/decorators/trim.js.map +1 -0
- package/lib/esm/decorators/unique.js +23 -0
- package/lib/esm/decorators/unique.js.map +1 -0
- package/lib/esm/decorators/uppercase.js +24 -0
- package/lib/esm/decorators/uppercase.js.map +1 -0
- package/lib/esm/decorators/versionKey.js +8 -0
- package/lib/esm/decorators/versionKey.js.map +1 -0
- package/lib/esm/decorators/virtualRef.js +34 -0
- package/lib/esm/decorators/virtualRef.js.map +1 -0
- package/lib/esm/index.js +48 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/MongooseConnectionOptions.js +2 -0
- package/lib/esm/interfaces/MongooseConnectionOptions.js.map +1 -0
- package/lib/esm/interfaces/MongooseDocument.js +2 -0
- package/lib/esm/interfaces/MongooseDocument.js.map +1 -0
- package/lib/esm/interfaces/MongooseModel.js +2 -0
- package/lib/esm/interfaces/MongooseModel.js.map +1 -0
- package/lib/esm/interfaces/MongooseModelOptions.js +2 -0
- package/lib/esm/interfaces/MongooseModelOptions.js.map +1 -0
- package/lib/esm/interfaces/MongooseSchemaOptions.js +2 -0
- package/lib/esm/interfaces/MongooseSchemaOptions.js.map +1 -0
- package/lib/esm/interfaces/MongooseSchemaTypes.js +7 -0
- package/lib/esm/interfaces/MongooseSchemaTypes.js.map +1 -0
- package/lib/esm/interfaces/MongooseVirtualRefOptions.js +2 -0
- package/lib/esm/interfaces/MongooseVirtualRefOptions.js.map +1 -0
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/registries/MongooseModels.js +2 -0
- package/lib/esm/registries/MongooseModels.js.map +1 -0
- package/lib/esm/services/MongooseConnections.js +44 -0
- package/lib/esm/services/MongooseConnections.js.map +1 -0
- package/lib/esm/services/MongooseService.js +70 -0
- package/lib/esm/services/MongooseService.js.map +1 -0
- package/lib/esm/utils/createModel.js +48 -0
- package/lib/esm/utils/createModel.js.map +1 -0
- package/lib/esm/utils/createSchema.js +151 -0
- package/lib/esm/utils/createSchema.js.map +1 -0
- package/lib/esm/utils/resolveRefType.js +15 -0
- package/lib/esm/utils/resolveRefType.js.map +1 -0
- package/lib/esm/utils/schemaOptions.js +54 -0
- package/lib/esm/utils/schemaOptions.js.map +1 -0
- package/lib/{MongooseModule.d.ts → types/MongooseModule.d.ts} +0 -0
- package/lib/{constants/index.d.ts → types/constants/constants.d.ts} +0 -0
- package/lib/{decorators → types/decorators}/auto.d.ts +0 -0
- package/lib/{decorators → types/decorators}/discriminatorKey.d.ts +0 -0
- package/lib/{decorators → types/decorators}/dynamicRef.d.ts +4 -2
- package/lib/{decorators → types/decorators}/excludeIndexes.d.ts +0 -0
- package/lib/{decorators → types/decorators}/expires.d.ts +0 -0
- package/lib/{decorators → types/decorators}/immutable.d.ts +0 -0
- package/lib/{decorators → types/decorators}/indexed.d.ts +0 -0
- package/lib/{decorators → types/decorators}/lowercase.d.ts +0 -0
- package/lib/{decorators → types/decorators}/model.d.ts +0 -0
- package/lib/{decorators → types/decorators}/mongooseIndex.d.ts +0 -0
- package/lib/types/decorators/mongooseIndexes.d.ts +32 -0
- package/lib/{decorators → types/decorators}/mongoosePlugin.d.ts +0 -0
- package/lib/{decorators → types/decorators}/numberDecimal.d.ts +0 -0
- package/lib/{decorators → types/decorators}/objectID.d.ts +0 -0
- package/lib/{decorators → types/decorators}/postHook.d.ts +1 -1
- package/lib/{decorators → types/decorators}/preHook.d.ts +1 -1
- package/lib/{decorators → types/decorators}/ref.d.ts +7 -2
- package/lib/{decorators → types/decorators}/schema.d.ts +1 -1
- package/lib/{decorators → types/decorators}/schemaIgnore.d.ts +0 -0
- package/lib/{decorators → types/decorators}/select.d.ts +0 -0
- package/lib/{decorators → types/decorators}/sparse.d.ts +0 -0
- package/lib/{decorators → types/decorators}/text.d.ts +0 -0
- package/lib/{decorators → types/decorators}/trim.d.ts +0 -0
- package/lib/{decorators → types/decorators}/unique.d.ts +0 -0
- package/lib/{decorators → types/decorators}/uppercase.d.ts +0 -0
- package/lib/{decorators → types/decorators}/versionKey.d.ts +0 -0
- package/lib/{decorators → types/decorators}/virtualRef.d.ts +0 -4
- package/lib/types/index.d.ts +47 -0
- package/lib/{interfaces → types/interfaces}/MongooseConnectionOptions.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/MongooseDocument.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/MongooseModel.d.ts +1 -2
- package/lib/{interfaces → types/interfaces}/MongooseModelOptions.d.ts +1 -1
- package/lib/{interfaces → types/interfaces}/MongooseSchemaOptions.d.ts +1 -1
- package/lib/{interfaces → types/interfaces}/MongooseSchemaTypes.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/MongooseVirtualRefOptions.d.ts +1 -0
- package/lib/{interfaces/index.d.ts → types/interfaces/interfaces.d.ts} +0 -6
- package/lib/{registries → types/registries}/MongooseModels.d.ts +0 -0
- package/lib/{services → types/services}/MongooseConnections.d.ts +0 -0
- package/lib/{services → types/services}/MongooseService.d.ts +0 -0
- package/lib/{utils → types/utils}/createModel.d.ts +3 -2
- package/lib/{utils → types/utils}/createSchema.d.ts +1 -1
- package/lib/{utils → types/utils}/resolveRefType.d.ts +0 -0
- package/lib/{utils → types/utils}/schemaOptions.d.ts +1 -1
- package/package.json +30 -27
- package/readme.md +124 -134
- package/tsconfig.compile.esm.json +13 -0
- package/.mocharc.js +0 -5
- package/.nycrc +0 -27
- package/lib/decorators/index.d.ts +0 -26
- package/lib/index.d.ts +0 -6
- package/lib/index.js +0 -1402
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -1362
- package/lib/index.modern.js.map +0 -1
- package/lib/utils/index.d.ts +0 -2
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "mongoose"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: {
|
|
8
|
+
branches: 93.45,
|
|
9
|
+
functions: 98.9,
|
|
10
|
+
lines: 98.9,
|
|
11
|
+
statements: 98.93
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongooseModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const di_1 = require("@tsed/di");
|
|
6
|
+
const di_2 = require("@tsed/di");
|
|
7
|
+
const MongooseConnections_1 = require("./services/MongooseConnections");
|
|
8
|
+
const MongooseService_1 = require("./services/MongooseService");
|
|
9
|
+
/**
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
12
|
+
let MongooseModule = class MongooseModule {
|
|
13
|
+
constructor(mongooseService, settings) {
|
|
14
|
+
this.mongooseService = mongooseService;
|
|
15
|
+
this.settings = settings;
|
|
16
|
+
// auto configure the cache manager when mongoose is used with @tsed/mongoose
|
|
17
|
+
const cache = this.settings.get("cache");
|
|
18
|
+
// istanbul ignore next
|
|
19
|
+
if (cache === null || cache === void 0 ? void 0 : cache.mongoose) {
|
|
20
|
+
cache.connection = this.mongooseService.get();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
$onInit() { }
|
|
24
|
+
$onDestroy() {
|
|
25
|
+
return this.mongooseService.closeConnections();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
MongooseModule = tslib_1.__decorate([
|
|
29
|
+
(0, di_2.Module)({
|
|
30
|
+
imports: [MongooseConnections_1.MONGOOSE_CONNECTIONS]
|
|
31
|
+
}),
|
|
32
|
+
tslib_1.__param(1, (0, di_1.Configuration)()),
|
|
33
|
+
tslib_1.__metadata("design:paramtypes", [MongooseService_1.MongooseService, Object])
|
|
34
|
+
], MongooseModule);
|
|
35
|
+
exports.MongooseModule = MongooseModule;
|
|
36
|
+
//# sourceMappingURL=MongooseModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongooseModule.js","sourceRoot":"","sources":["../../src/MongooseModule.ts"],"names":[],"mappings":";;;;AAAA,iCAA+C;AAC/C,iCAA2C;AAC3C,wEAAoE;AACpE,gEAA2D;AAE3D;;GAEG;AAIH,IAAa,cAAc,GAA3B,MAAa,cAAc;IACzB,YAAoB,eAAgC,EAA2B,QAAuB;QAAlF,oBAAe,GAAf,eAAe,CAAiB;QAA2B,aAAQ,GAAR,QAAQ,CAAe;QACpG,6EAA6E;QAC7E,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAM,OAAO,CAAC,CAAC;QAE9C,uBAAuB;QACvB,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE;YACnB,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;SAC/C;IACH,CAAC;IAED,OAAO,KAAyB,CAAC;IAEjC,UAAU;QACR,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,EAAE,CAAC;IACjD,CAAC;CACF,CAAA;AAhBY,cAAc;IAH1B,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,0CAAoB,CAAC;KAChC,CAAC;IAEuD,mBAAA,IAAA,kBAAa,GAAE,CAAA;6CAAjC,iCAAe;GADzC,cAAc,CAgB1B;AAhBY,wCAAc","sourcesContent":["import {Configuration, OnInit} from \"@tsed/di\";\nimport {Module, OnDestroy} from \"@tsed/di\";\nimport {MONGOOSE_CONNECTIONS} from \"./services/MongooseConnections\";\nimport {MongooseService} from \"./services/MongooseService\";\n\n/**\n * @ignore\n */\n@Module({\n imports: [MONGOOSE_CONNECTIONS]\n})\nexport class MongooseModule implements OnDestroy, OnInit {\n constructor(private mongooseService: MongooseService, @Configuration() private settings: Configuration) {\n // auto configure the cache manager when mongoose is used with @tsed/mongoose\n const cache = this.settings.get<any>(\"cache\");\n\n // istanbul ignore next\n if (cache?.mongoose) {\n cache.connection = this.mongooseService.get();\n }\n }\n\n $onInit(): void | Promise<any> {}\n\n $onDestroy(): Promise<any> | void {\n return this.mongooseService.closeConnections();\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MONGOOSE_MODEL_NAME = exports.MONGOOSE_MODEL = exports.MONGOOSE_SCHEMA_OPTIONS = exports.MONGOOSE_SCHEMA = void 0;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @type {string}
|
|
7
|
+
*/
|
|
8
|
+
exports.MONGOOSE_SCHEMA = "tsed:mongoose:schema";
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @type {string}
|
|
12
|
+
*/
|
|
13
|
+
exports.MONGOOSE_SCHEMA_OPTIONS = "tsed:mongoose:schema:options";
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @type {string}
|
|
17
|
+
*/
|
|
18
|
+
exports.MONGOOSE_MODEL = "tsed:mongoose:model";
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
exports.MONGOOSE_MODEL_NAME = "tsed:mongoose:model:name";
|
|
24
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,eAAe,GAAG,sBAAsB,CAAC;AACtD;;;GAGG;AACU,QAAA,uBAAuB,GAAG,8BAA8B,CAAC;AACtE;;;GAGG;AACU,QAAA,cAAc,GAAG,qBAAqB,CAAC;AACpD;;;GAGG;AACU,QAAA,mBAAmB,GAAG,0BAA0B,CAAC","sourcesContent":["/**\n *\n * @type {string}\n */\nexport const MONGOOSE_SCHEMA = \"tsed:mongoose:schema\";\n/**\n *\n * @type {string}\n */\nexport const MONGOOSE_SCHEMA_OPTIONS = \"tsed:mongoose:schema:options\";\n/**\n *\n * @type {string}\n */\nexport const MONGOOSE_MODEL = \"tsed:mongoose:model\";\n/**\n *\n * @type {string}\n */\nexport const MONGOOSE_MODEL_NAME = \"tsed:mongoose:model:name\";\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auto = void 0;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
/**
|
|
6
|
+
* If true, uses Mongoose's default _id settings. Only allowed for ObjectIds
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Model()
|
|
12
|
+
* export class EventModel {
|
|
13
|
+
* @ExcludeIndexes()
|
|
14
|
+
* field: string;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param {boolean} auto
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @decorator
|
|
21
|
+
* @mongoose
|
|
22
|
+
* @property
|
|
23
|
+
*/
|
|
24
|
+
function Auto(auto = true) {
|
|
25
|
+
return (0, schema_1.MongooseSchema)({ auto });
|
|
26
|
+
}
|
|
27
|
+
exports.Auto = Auto;
|
|
28
|
+
//# sourceMappingURL=auto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto.js","sourceRoot":"","sources":["../../../src/decorators/auto.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,IAAI,CAAC,OAAgB,IAAI;IACvC,OAAO,IAAA,uBAAc,EAAC,EAAC,IAAI,EAAQ,CAAC,CAAC;AACvC,CAAC;AAFD,oBAEC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If true, uses Mongoose's default _id settings. Only allowed for ObjectIds\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @ExcludeIndexes()\n * field: string;\n * }\n * ```\n *\n * @param {boolean} auto\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Auto(auto: boolean = true): PropertyDecorator {\n return MongooseSchema({auto} as any);\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiscriminatorKey = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
const schemaIgnore_1 = require("./schemaIgnore");
|
|
7
|
+
const schema_1 = require("@tsed/schema");
|
|
8
|
+
function DiscriminatorKey() {
|
|
9
|
+
return (0, core_1.useDecorators)((0, schema_1.Property)(), (0, schemaIgnore_1.SchemaIgnore)(), (target, propertyKey) => {
|
|
10
|
+
core_1.Store.from(target).merge(constants_1.MONGOOSE_SCHEMA_OPTIONS, { discriminatorKey: propertyKey });
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.DiscriminatorKey = DiscriminatorKey;
|
|
14
|
+
//# sourceMappingURL=discriminatorKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminatorKey.js","sourceRoot":"","sources":["../../../src/decorators/discriminatorKey.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAChD,sDAA+D;AAC/D,iDAA4C;AAC5C,yCAAsC;AAEtC,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,oBAAa,EAAC,IAAA,iBAAQ,GAAE,EAAE,IAAA,2BAAY,GAAE,EAAE,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACpF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,mCAAuB,EAAE,EAAC,gBAAgB,EAAE,WAAW,EAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,4CAIC","sourcesContent":["import {Store, useDecorators} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {SchemaIgnore} from \"./schemaIgnore\";\nimport {Property} from \"@tsed/schema\";\n\nexport function DiscriminatorKey(): PropertyDecorator {\n return useDecorators(Property(), SchemaIgnore(), (target: any, propertyKey: string) => {\n Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, {discriminatorKey: propertyKey});\n });\n}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicRef = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const schema_1 = require("@tsed/schema");
|
|
6
|
+
const mongoose_1 = require("mongoose");
|
|
7
|
+
const constants_1 = require("../constants/constants");
|
|
8
|
+
const json_mapper_1 = require("@tsed/json-mapper");
|
|
9
|
+
const MongooseModels_1 = require("../registries/MongooseModels");
|
|
10
|
+
function isRef(value) {
|
|
11
|
+
return (value && value._bsontype) || (0, core_1.isString)(value);
|
|
12
|
+
}
|
|
13
|
+
function getType(refPath, ctx) {
|
|
14
|
+
return ((ctx === null || ctx === void 0 ? void 0 : ctx.self[refPath]) && MongooseModels_1.MongooseModels.get(ctx.self[refPath])) || Object;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Define a property as mongoose reference to other Model (decorated with @Model).
|
|
18
|
+
*
|
|
19
|
+
* ### Example
|
|
20
|
+
*
|
|
21
|
+
* ```typescript
|
|
22
|
+
* @Model()
|
|
23
|
+
* class FooModel {
|
|
24
|
+
*
|
|
25
|
+
* @DynamicRef('type')
|
|
26
|
+
* field: DynamicRef<OtherFooModel | OtherModel>
|
|
27
|
+
*
|
|
28
|
+
* @Enum(['OtherFooModel', 'OtherModel'])
|
|
29
|
+
* type: string
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* @Model()
|
|
33
|
+
* class OtherFooModel {
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* @Model()
|
|
37
|
+
* class OtherModel {
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param refPath {String} the path to apply the correct model
|
|
42
|
+
* @param types {Type} the classes to generate the correct json schema
|
|
43
|
+
* @returns {Function}
|
|
44
|
+
* @decorator
|
|
45
|
+
* @mongoose
|
|
46
|
+
* @property
|
|
47
|
+
*/
|
|
48
|
+
function DynamicRef(refPath, ...types) {
|
|
49
|
+
return (0, core_1.useDecorators)((0, schema_1.Property)(Object), (0, schema_1.Example)("5ce7ad3028890bd71749d477"), (0, schema_1.Description)("Mongoose Ref ObjectId"), (0, core_1.StoreMerge)(constants_1.MONGOOSE_SCHEMA, {
|
|
50
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
51
|
+
refPath
|
|
52
|
+
}), (0, json_mapper_1.OnDeserialize)((value, ctx) => {
|
|
53
|
+
if (isRef(value)) {
|
|
54
|
+
return value.toString();
|
|
55
|
+
}
|
|
56
|
+
return (0, json_mapper_1.deserialize)(value, { ...ctx, type: getType(refPath, ctx) });
|
|
57
|
+
}), (0, json_mapper_1.OnSerialize)((value, ctx) => {
|
|
58
|
+
if (isRef(value)) {
|
|
59
|
+
return value.toString();
|
|
60
|
+
}
|
|
61
|
+
return (0, json_mapper_1.serialize)(value, { ...ctx, type: getType(refPath, ctx) });
|
|
62
|
+
}), (0, schema_1.OneOf)((0, schema_1.string)().example("5ce7ad3028890bd71749d477").description("Mongoose Ref ObjectId"), ...types));
|
|
63
|
+
}
|
|
64
|
+
exports.DynamicRef = DynamicRef;
|
|
65
|
+
//# sourceMappingURL=dynamicRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":";;;AAAA,qCAAyF;AACzF,yCAA4F;AAC5F,uCAAkD;AAClD,sDAAuD;AACvD,mDAAqF;AACrF,iEAA4D;AAE5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,OAAO,CAAC,OAAe,EAAE,GAAoB;IACpD,OAAO,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC,OAAO,CAAC,KAAI,+BAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAW,CAAC,CAAC,IAAI,MAAM,CAAC;AAC3F,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAgB,UAAU,CAAC,OAAe,EAAE,GAAG,KAAkB;IAC/D,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAChB,IAAA,gBAAO,EAAC,0BAA0B,CAAC,EACnC,IAAA,oBAAW,EAAC,uBAAuB,CAAC,EACpC,IAAA,iBAAU,EAAC,2BAAe,EAAE;QAC1B,IAAI,EAAE,iBAAc,CAAC,KAAK,CAAC,QAAQ;QACnC,OAAO;KACR,CAAC,EACF,IAAA,2BAAa,EAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,IAAA,yBAAW,EAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAC,CAAC,CAAC;IACnE,CAAC,CAAC,EACF,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,IAAA,uBAAS,EAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAC,CAAC,CAAC;IACjE,CAAC,CAAC,EACF,IAAA,cAAK,EAAC,IAAA,eAAM,GAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,GAAG,KAAK,CAAC,CAC9E,CAAC;AACzB,CAAC;AAzBD,gCAyBC","sourcesContent":["import {classOf, isArrowFn, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {Description, Example, JsonHookContext, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {deserialize, OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction getType(refPath: string, ctx: JsonHookContext) {\n return (ctx?.self[refPath] && MongooseModels.get(ctx.self[refPath] as string)) || Object;\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * class FooModel {\n *\n * @DynamicRef('type')\n * field: DynamicRef<OtherFooModel | OtherModel>\n *\n * @Enum(['OtherFooModel', 'OtherModel'])\n * type: string\n * }\n *\n * @Model()\n * class OtherFooModel {\n * }\n *\n * @Model()\n * class OtherModel {\n * }\n * ```\n *\n * @param refPath {String} the path to apply the correct model\n * @param types {Type} the classes to generate the correct json schema\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function DynamicRef(refPath: string, ...types: Type<any>[]): PropertyDecorator {\n return useDecorators(\n Property(Object),\n Example(\"5ce7ad3028890bd71749d477\"),\n Description(\"Mongoose Ref ObjectId\"),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types.ObjectId,\n refPath\n }),\n OnDeserialize((value, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return deserialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return serialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"Mongoose Ref ObjectId\"), ...types)\n ) as PropertyDecorator;\n}\n\nexport type DynamicRef<T> = T | string;\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExcludeIndexes = void 0;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
/**
|
|
6
|
+
* If true, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Model()
|
|
12
|
+
* export class EventModel {
|
|
13
|
+
* @ExcludeIndexes()
|
|
14
|
+
* field: string;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param {boolean} excludeIndexes
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @decorator
|
|
21
|
+
* @mongoose
|
|
22
|
+
* @property
|
|
23
|
+
*/
|
|
24
|
+
function ExcludeIndexes(excludeIndexes = true) {
|
|
25
|
+
return (0, schema_1.MongooseSchema)({ excludeIndexes });
|
|
26
|
+
}
|
|
27
|
+
exports.ExcludeIndexes = ExcludeIndexes;
|
|
28
|
+
//# sourceMappingURL=excludeIndexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excludeIndexes.js","sourceRoot":"","sources":["../../../src/decorators/excludeIndexes.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,cAAc,CAAC,iBAA0B,IAAI;IAC3D,OAAO,IAAA,uBAAc,EAAC,EAAC,cAAc,EAAQ,CAAC,CAAC;AACjD,CAAC;AAFD,wCAEC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If true, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @ExcludeIndexes()\n * field: string;\n * }\n * ```\n *\n * @param {boolean} excludeIndexes\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function ExcludeIndexes(excludeIndexes: boolean = true): PropertyDecorator {\n return MongooseSchema({excludeIndexes} as any);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Expires = void 0;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
/**
|
|
6
|
+
* Defines a TTL index on this path. Only allowed for dates.
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Model()
|
|
12
|
+
* export class EventModel {
|
|
13
|
+
* @Expires('5d')
|
|
14
|
+
* field: string;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param {boolean | any} expires
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @decorator
|
|
21
|
+
* @mongoose
|
|
22
|
+
* @property
|
|
23
|
+
*/
|
|
24
|
+
function Expires(expires) {
|
|
25
|
+
return (0, schema_1.MongooseSchema)({ expires });
|
|
26
|
+
}
|
|
27
|
+
exports.Expires = Expires;
|
|
28
|
+
//# sourceMappingURL=expires.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expires.js","sourceRoot":"","sources":["../../../src/decorators/expires.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,OAAO,CAAC,OAA+B;IACrD,OAAO,IAAA,uBAAc,EAAC,EAAC,OAAO,EAAQ,CAAC,CAAC;AAC1C,CAAC;AAFD,0BAEC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Defines a TTL index on this path. Only allowed for dates.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Expires('5d')\n * field: string;\n * }\n * ```\n *\n * @param {boolean | any} expires\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Expires(expires: number | string | Date): PropertyDecorator {\n return MongooseSchema({expires} as any);\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Immutable = void 0;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
/**
|
|
6
|
+
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
|
|
7
|
+
* disallow changes to this path once the document is saved to the database for the first time. Read more
|
|
8
|
+
* about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).
|
|
9
|
+
*
|
|
10
|
+
* ### Example
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @Model()
|
|
14
|
+
* export class EventModel {
|
|
15
|
+
* @Immutable()
|
|
16
|
+
* field: string;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param {boolean | any} immutable
|
|
21
|
+
* @returns {Function}
|
|
22
|
+
* @decorator
|
|
23
|
+
* @mongoose
|
|
24
|
+
* @property
|
|
25
|
+
*/
|
|
26
|
+
function Immutable(immutable = true) {
|
|
27
|
+
return (0, schema_1.MongooseSchema)({ immutable });
|
|
28
|
+
}
|
|
29
|
+
exports.Immutable = Immutable;
|
|
30
|
+
//# sourceMappingURL=immutable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"immutable.js","sourceRoot":"","sources":["../../../src/decorators/immutable.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,SAAS,CAAC,YAA0D,IAAI;IACtF,OAAO,IAAA,uBAAc,EAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC;AAFD,8BAEC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will\n * disallow changes to this path once the document is saved to the database for the first time. Read more\n * about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Immutable()\n * field: string;\n * }\n * ```\n *\n * @param {boolean | any} immutable\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Immutable(immutable: boolean | ((this: any, doc: any) => boolean) = true): PropertyDecorator {\n return MongooseSchema({immutable} as any);\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Indexed = void 0;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
/**
|
|
6
|
+
* Tell Mongoose whether to define an index for the property.
|
|
7
|
+
* ### Example
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Model()
|
|
11
|
+
* export class EventModel {
|
|
12
|
+
* @Indexed()
|
|
13
|
+
* field: string;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
* @decorator
|
|
19
|
+
* @mongoose
|
|
20
|
+
* @property
|
|
21
|
+
*/
|
|
22
|
+
function Indexed(index = true) {
|
|
23
|
+
return (0, schema_1.MongooseSchema)({ index });
|
|
24
|
+
}
|
|
25
|
+
exports.Indexed = Indexed;
|
|
26
|
+
//# sourceMappingURL=indexed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexed.js","sourceRoot":"","sources":["../../../src/decorators/indexed.ts"],"names":[],"mappings":";;;AACA,qCAAwC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,OAAO,CAAC,QAAyC,IAAI;IACnE,OAAO,IAAA,uBAAc,EAAC,EAAC,KAAK,EAAQ,CAAC,CAAC;AACxC,CAAC;AAFD,0BAEC","sourcesContent":["import {IndexOptions} from \"mongoose\";\nimport {MongooseSchema} from \"./schema\";\n\n/**\n * Tell Mongoose whether to define an index for the property.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Indexed()\n * field: string;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Indexed(index: IndexOptions | boolean | string = true): PropertyDecorator {\n return MongooseSchema({index} as any);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Lowercase = void 0;
|
|
4
|
+
const schema_1 = require("./schema");
|
|
5
|
+
/**
|
|
6
|
+
* If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in String#toLowerCase().
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Model()
|
|
12
|
+
* export class EventModel {
|
|
13
|
+
* @Lowercase()
|
|
14
|
+
* field: string;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param {boolean} lowercase
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @decorator
|
|
21
|
+
* @mongoose
|
|
22
|
+
* @property
|
|
23
|
+
*/
|
|
24
|
+
function Lowercase(lowercase = true) {
|
|
25
|
+
return (0, schema_1.MongooseSchema)({ lowercase });
|
|
26
|
+
}
|
|
27
|
+
exports.Lowercase = Lowercase;
|
|
28
|
+
//# sourceMappingURL=lowercase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowercase.js","sourceRoot":"","sources":["../../../src/decorators/lowercase.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,SAAS,CAAC,YAAqB,IAAI;IACjD,OAAO,IAAA,uBAAc,EAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC;AAFD,8BAEC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in String#toLowerCase().\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Lowercase()\n * field: string;\n * }\n * ```\n *\n * @param {boolean} lowercase\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Lowercase(lowercase: boolean = true): PropertyDecorator {\n return MongooseSchema({lowercase} as any);\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Model = void 0;
|
|
4
|
+
const di_1 = require("@tsed/di");
|
|
5
|
+
const MongooseConnections_1 = require("../services/MongooseConnections");
|
|
6
|
+
const createModel_1 = require("../utils/createModel");
|
|
7
|
+
const createSchema_1 = require("../utils/createSchema");
|
|
8
|
+
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
9
|
+
/**
|
|
10
|
+
* Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with
|
|
11
|
+
* `@Inject` annotation.
|
|
12
|
+
*
|
|
13
|
+
* ### Example
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* @Model()
|
|
17
|
+
* export class EventModel {
|
|
18
|
+
* @Property()
|
|
19
|
+
* field: string;
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Then inject the model into a service:
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* class MyService {
|
|
27
|
+
* constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {
|
|
28
|
+
* eventModel.findById().exec();
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ### Options
|
|
34
|
+
*
|
|
35
|
+
* - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.
|
|
36
|
+
* - `name` (String): model name.
|
|
37
|
+
* - `collection` (String): collection (optional, induced from model name).
|
|
38
|
+
* - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).
|
|
39
|
+
*
|
|
40
|
+
* @param {MongooseModelOptions} options
|
|
41
|
+
* @returns {(target: any) => void}
|
|
42
|
+
* @decorator
|
|
43
|
+
* @mongoose
|
|
44
|
+
* @class
|
|
45
|
+
*/
|
|
46
|
+
function Model(options = {}) {
|
|
47
|
+
return (target) => {
|
|
48
|
+
const { token, collectionName } = (0, createModel_1.getModelToken)(target, options);
|
|
49
|
+
(0, di_1.registerProvider)({
|
|
50
|
+
provide: token,
|
|
51
|
+
deps: [],
|
|
52
|
+
useFactory() {
|
|
53
|
+
return (0, createSchema_1.getSchema)(target, options);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
(0, di_1.registerProvider)({
|
|
57
|
+
provide: target,
|
|
58
|
+
type: "mongoose:model",
|
|
59
|
+
deps: [MongooseConnections_1.MONGOOSE_CONNECTIONS, token],
|
|
60
|
+
useFactory(connections, schema) {
|
|
61
|
+
(0, schemaOptions_1.applySchemaOptions)(schema, (0, schemaOptions_1.schemaOptions)(target));
|
|
62
|
+
return (0, createModel_1.createModel)(target, schema, collectionName, options.collection, options.overwriteModels, connections.get(options.connection), options.discriminatorValue);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
exports.Model = Model;
|
|
68
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/decorators/model.ts"],"names":[],"mappings":";;;AAAA,iCAA0C;AAG1C,yEAAqE;AACrE,sDAAgE;AAChE,wDAAgD;AAChD,0DAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,KAAK,CAAC,UAAgC,EAAE;IACtD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,EAAC,KAAK,EAAE,cAAc,EAAC,GAAG,IAAA,2BAAa,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE/D,IAAA,qBAAgB,EAAC;YACf,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;YACR,UAAU;gBACR,OAAO,IAAA,wBAAS,EAAC,MAAM,EAAE,OAAc,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;QAEH,IAAA,qBAAgB,EAAC;YACf,OAAO,EAAE,MAAM;YACf,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,CAAC,0CAAoB,EAAE,KAAK,CAAC;YACnC,UAAU,CAAC,WAAiC,EAAE,MAAc;gBAC1D,IAAA,kCAAkB,EAAC,MAAM,EAAE,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC,CAAC;gBAClD,OAAO,IAAA,yBAAW,EAChB,MAAM,EACN,MAAM,EACN,cAAc,EACd,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,eAAe,EACvB,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EACnC,OAAO,CAAC,kBAAkB,CAC3B,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA9BD,sBA8BC","sourcesContent":["import {registerProvider} from \"@tsed/di\";\nimport {Schema} from \"mongoose\";\nimport {MongooseModelOptions} from \"../interfaces/MongooseModelOptions\";\nimport {MONGOOSE_CONNECTIONS} from \"../services/MongooseConnections\";\nimport {createModel, getModelToken} from \"../utils/createModel\";\nimport {getSchema} from \"../utils/createSchema\";\nimport {applySchemaOptions, schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with\n * `@Inject` annotation.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * Then inject the model into a service:\n *\n * ```typescript\n * class MyService {\n * constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {\n * eventModel.findById().exec();\n * }\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n * - `name` (String): model name.\n * - `collection` (String): collection (optional, induced from model name).\n * - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).\n *\n * @param {MongooseModelOptions} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @class\n */\nexport function Model(options: MongooseModelOptions = {}) {\n return (target: any) => {\n const {token, collectionName} = getModelToken(target, options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(target, options as any);\n }\n });\n\n registerProvider({\n provide: target,\n type: \"mongoose:model\",\n deps: [MONGOOSE_CONNECTIONS, token],\n useFactory(connections: MONGOOSE_CONNECTIONS, schema: Schema) {\n applySchemaOptions(schema, schemaOptions(target));\n return createModel(\n target,\n schema,\n collectionName,\n options.collection,\n options.overwriteModels,\n connections.get(options.connection),\n options.discriminatorValue\n );\n }\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongooseIndex = void 0;
|
|
4
|
+
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
5
|
+
/**
|
|
6
|
+
* Calls schema.index() to define an index (most likely compound) for the schema.
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Model()
|
|
12
|
+
* @MongooseIndex({first: 1, second: 1}, {unique: 1})
|
|
13
|
+
* export class EventModel {
|
|
14
|
+
*
|
|
15
|
+
* @Property()
|
|
16
|
+
* first: string;
|
|
17
|
+
*
|
|
18
|
+
* @Property()
|
|
19
|
+
* second: string;
|
|
20
|
+
*
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param fields
|
|
25
|
+
* @param options
|
|
26
|
+
* @returns {Function}
|
|
27
|
+
* @decorator
|
|
28
|
+
* @mongoose
|
|
29
|
+
* @class
|
|
30
|
+
*/
|
|
31
|
+
function MongooseIndex(fields, options) {
|
|
32
|
+
return (target) => {
|
|
33
|
+
(0, schemaOptions_1.schemaOptions)(target, {
|
|
34
|
+
indexes: [{ fields, options }]
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.MongooseIndex = MongooseIndex;
|
|
39
|
+
//# sourceMappingURL=mongooseIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongooseIndex.js","sourceRoot":"","sources":["../../../src/decorators/mongooseIndex.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,aAAa,CAAC,MAAc,EAAE,OAAa;IACzD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,6BAAa,EAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAND,sCAMC","sourcesContent":["import {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Calls schema.index() to define an index (most likely compound) for the schema.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @MongooseIndex({first: 1, second: 1}, {unique: 1})\n * export class EventModel {\n *\n * @Property()\n * first: string;\n *\n * @Property()\n * second: string;\n *\n * }\n * ```\n *\n * @param fields\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongooseIndex(fields: object, options?: any): Function {\n return (target: any) => {\n schemaOptions(target, {\n indexes: [{fields, options}]\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongooseIndexes = void 0;
|
|
4
|
+
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
5
|
+
/**
|
|
6
|
+
* Calls schema.index() to define multiple indexes (most likely compound) for the schema.
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Model()
|
|
12
|
+
* @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])
|
|
13
|
+
* export class EventModel {
|
|
14
|
+
*
|
|
15
|
+
* @Property()
|
|
16
|
+
* first: string;
|
|
17
|
+
*
|
|
18
|
+
* @Property()
|
|
19
|
+
* second: string;
|
|
20
|
+
*
|
|
21
|
+
* @Property()
|
|
22
|
+
* third: string;
|
|
23
|
+
*
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param indexes - define multiple mongoose indexes
|
|
28
|
+
* @returns {Function}
|
|
29
|
+
* @decorator
|
|
30
|
+
* @mongoose
|
|
31
|
+
* @class
|
|
32
|
+
*/
|
|
33
|
+
function MongooseIndexes(indexes) {
|
|
34
|
+
return (target) => {
|
|
35
|
+
(0, schemaOptions_1.schemaOptions)(target, { indexes });
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.MongooseIndexes = MongooseIndexes;
|
|
39
|
+
//# sourceMappingURL=mongooseIndexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongooseIndexes.js","sourceRoot":"","sources":["../../../src/decorators/mongooseIndexes.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,eAAe,CAAC,OAA+C;IAC7E,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,6BAAa,EAAC,MAAM,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC;AAJD,0CAIC","sourcesContent":["import {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Calls schema.index() to define multiple indexes (most likely compound) for the schema.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])\n * export class EventModel {\n *\n * @Property()\n * first: string;\n *\n * @Property()\n * second: string;\n *\n * @Property()\n * third: string;\n *\n * }\n * ```\n *\n * @param indexes - define multiple mongoose indexes\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongooseIndexes(indexes: Array<{fields: object; options?: any}>): Function {\n return (target: any) => {\n schemaOptions(target, {indexes});\n };\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoosePlugin = void 0;
|
|
4
|
+
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {(schema: "mongoose".Schema, options?: any) => void} plugin
|
|
8
|
+
* @param options
|
|
9
|
+
* @returns {Function}
|
|
10
|
+
* @decorator
|
|
11
|
+
* @mongoose
|
|
12
|
+
* @class
|
|
13
|
+
*/
|
|
14
|
+
function MongoosePlugin(plugin, options) {
|
|
15
|
+
return (target) => {
|
|
16
|
+
(0, schemaOptions_1.schemaOptions)(target, {
|
|
17
|
+
plugins: [{ plugin, options }]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.MongoosePlugin = MongoosePlugin;
|
|
22
|
+
//# sourceMappingURL=mongoosePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoosePlugin.js","sourceRoot":"","sources":["../../../src/decorators/mongoosePlugin.ts"],"names":[],"mappings":";;;AACA,0DAAqD;AAErD;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,MAAwD,EAAE,OAAa;IACpG,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,6BAAa,EAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAND,wCAMC","sourcesContent":["import mongoose from \"mongoose\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n *\n * @param {(schema: \"mongoose\".Schema, options?: any) => void} plugin\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongoosePlugin(plugin: (schema: mongoose.Schema, options?: any) => void, options?: any): Function {\n return (target: any) => {\n schemaOptions(target, {\n plugins: [{plugin, options}]\n });\n };\n}\n"]}
|