@tsed/mongoose 7.0.0-alpha.2 → 7.0.0-beta.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/jest.config.js +14 -0
- package/lib/cjs/MongooseModule.js +36 -0
- package/lib/cjs/MongooseModule.js.map +1 -0
- package/lib/cjs/constants/index.js +24 -0
- package/lib/cjs/constants/index.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 +46 -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/index.js +30 -0
- package/lib/cjs/decorators/index.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 +67 -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 +10 -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/index.js +10 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/cjs/registries/MongooseModels.js +5 -0
- package/lib/cjs/registries/MongooseModels.js.map +1 -0
- package/lib/cjs/services/MongooseConnections.js +51 -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 +58 -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/index.js +6 -0
- package/lib/cjs/utils/index.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/index.js +21 -0
- package/lib/esm/constants/index.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 +42 -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/index.js +27 -0
- package/lib/esm/decorators/index.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 +63 -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 +7 -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/index.js +7 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/registries/MongooseModels.js +2 -0
- package/lib/esm/registries/MongooseModels.js.map +1 -0
- package/lib/esm/services/MongooseConnections.js +48 -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 +52 -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/index.js +3 -0
- package/lib/esm/utils/index.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 → types/constants}/index.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 +0 -0
- 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}/index.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 +0 -0
- package/lib/{decorators → types/decorators}/preHook.d.ts +0 -0
- package/lib/{decorators → types/decorators}/ref.d.ts +7 -2
- package/lib/{decorators → types/decorators}/schema.d.ts +0 -0
- 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 -0
- package/lib/{index.d.ts → types/index.d.ts} +0 -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 +0 -0
- package/lib/{interfaces → types/interfaces}/MongooseModelOptions.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/MongooseSchemaOptions.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/MongooseSchemaTypes.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/MongooseVirtualRefOptions.d.ts +1 -0
- package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
- 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 +2 -1
- package/lib/{utils → types/utils}/createSchema.d.ts +0 -0
- package/lib/{utils → types/utils}/index.d.ts +0 -0
- package/lib/{utils → types/utils}/resolveRefType.d.ts +0 -0
- package/lib/{utils → types/utils}/schemaOptions.d.ts +0 -0
- package/package.json +25 -24
- package/tsconfig.compile.esm.json +23 -0
- package/.mocharc.js +0 -5
- package/.nycrc +0 -27
- 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
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySchemaOptions = exports.buildPreHook = exports.schemaOptions = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
function schemaOptions(target, options) {
|
|
10
|
+
const store = core_1.Store.from(target);
|
|
11
|
+
if (!store.has(constants_1.MONGOOSE_SCHEMA_OPTIONS)) {
|
|
12
|
+
store.set(constants_1.MONGOOSE_SCHEMA_OPTIONS, {});
|
|
13
|
+
}
|
|
14
|
+
if (options) {
|
|
15
|
+
store.set(constants_1.MONGOOSE_SCHEMA_OPTIONS, (0, core_1.deepMerge)(store.get(constants_1.MONGOOSE_SCHEMA_OPTIONS), options));
|
|
16
|
+
}
|
|
17
|
+
return store.get(constants_1.MONGOOSE_SCHEMA_OPTIONS);
|
|
18
|
+
}
|
|
19
|
+
exports.schemaOptions = schemaOptions;
|
|
20
|
+
function mapHookArgs(hook) {
|
|
21
|
+
return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @ignore
|
|
25
|
+
*/
|
|
26
|
+
function buildPreHook(fn) {
|
|
27
|
+
return fn.length === 2
|
|
28
|
+
? function (next) {
|
|
29
|
+
return fn(this, next);
|
|
30
|
+
}
|
|
31
|
+
: function (next, options) {
|
|
32
|
+
return fn(this, next, options);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.buildPreHook = buildPreHook;
|
|
36
|
+
/**
|
|
37
|
+
* @ignore
|
|
38
|
+
*/
|
|
39
|
+
function applySchemaOptions(schema, options) {
|
|
40
|
+
if (options.plugins) {
|
|
41
|
+
options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));
|
|
42
|
+
}
|
|
43
|
+
if (options.indexes) {
|
|
44
|
+
options.indexes.forEach((item) => schema.index(item.fields, item.options));
|
|
45
|
+
}
|
|
46
|
+
if (options.pre) {
|
|
47
|
+
options.pre.forEach((item) => {
|
|
48
|
+
item = {
|
|
49
|
+
...item,
|
|
50
|
+
fn: buildPreHook(item.fn)
|
|
51
|
+
};
|
|
52
|
+
schema.pre(...mapHookArgs(item));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (options.post) {
|
|
56
|
+
options.post.forEach((item) => schema.post(...mapHookArgs(item)));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.applySchemaOptions = applySchemaOptions;
|
|
60
|
+
//# sourceMappingURL=schemaOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":";;;AAAA,qCAAyD;AAEzD,4CAAqD;AAGrD;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAW,EAAE,OAA+B;IACxE,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,EAAE;QACvC,KAAK,CAAC,GAAG,CAAC,mCAAuB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,IAAI,OAAO,EAAE;QACX,KAAK,CAAC,GAAG,CAAC,mCAAuB,EAAE,IAAA,gBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;KAC5F;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,mCAAuB,CAAC,CAAC;AAC5C,CAAC;AAZD,sCAYC;AAED,SAAS,WAAW,CAAC,IAAwC;IAC3D,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAQ,CAAC;AAC3G,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,EAAY;IACvC,OAAO,EAAE,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,CAAC,UAAU,IAAoB;YAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC;QACH,CAAC,CAAC,UAAU,IAAoB,EAAE,OAAY;YAC1C,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC;AACR,CAAC;AARD,oCAQC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,MAAc,EAAE,OAA8B;IAC/E,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC7E;IAED,IAAI,OAAO,CAAC,OAAO,EAAE;QACnB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KAC5E;IAED,IAAI,OAAO,CAAC,GAAG,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3B,IAAI,GAAG;gBACL,GAAG,IAAI;gBACP,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;aAC1B,CAAC;YAED,MAAM,CAAC,GAAW,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC5E;AACH,CAAC;AAvBD,gDAuBC","sourcesContent":["import {cleanObject, deepMerge, Store} from \"@tsed/core\";\nimport {Schema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants\";\nimport {MongooseNextCB, MongoosePostHook, MongoosePreHook, MongooseSchemaOptions} from \"../interfaces\";\n\n/**\n * @ignore\n */\nexport function schemaOptions(target: any, options?: MongooseSchemaOptions) {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA_OPTIONS)) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, {});\n }\n\n if (options) {\n store.set(MONGOOSE_SCHEMA_OPTIONS, deepMerge(store.get(MONGOOSE_SCHEMA_OPTIONS), options));\n }\n\n return store.get(MONGOOSE_SCHEMA_OPTIONS);\n}\n\nfunction mapHookArgs(hook: MongoosePreHook | MongoosePostHook): [string | RegExp, Function] {\n return [hook.method, hook.options || hook.fn, hook.options ? hook.fn : undefined].filter(Boolean) as any;\n}\n\n/**\n * @ignore\n */\nexport function buildPreHook(fn: Function) {\n return fn.length === 2\n ? function (next: MongooseNextCB) {\n return fn(this, next);\n }\n : function (next: MongooseNextCB, options: any) {\n return fn(this, next, options);\n };\n}\n\n/**\n * @ignore\n */\nexport function applySchemaOptions(schema: Schema, options: MongooseSchemaOptions) {\n if (options.plugins) {\n options.plugins.forEach((item) => schema.plugin(item.plugin, item.options));\n }\n\n if (options.indexes) {\n options.indexes.forEach((item) => schema.index(item.fields, item.options));\n }\n\n if (options.pre) {\n options.pre.forEach((item) => {\n item = {\n ...item,\n fn: buildPreHook(item.fn)\n };\n\n (schema.pre as any)(...mapHookArgs(item));\n });\n }\n\n if (options.post) {\n options.post.forEach((item) => (schema.post as any)(...mapHookArgs(item)));\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Configuration } from "@tsed/di";
|
|
3
|
+
import { Module } from "@tsed/di";
|
|
4
|
+
import { MONGOOSE_CONNECTIONS } from "./services/MongooseConnections";
|
|
5
|
+
import { MongooseService } from "./services/MongooseService";
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
let MongooseModule = class MongooseModule {
|
|
10
|
+
constructor(mongooseService, settings) {
|
|
11
|
+
this.mongooseService = mongooseService;
|
|
12
|
+
this.settings = settings;
|
|
13
|
+
// auto configure the cache manager when mongoose is used with @tsed/mongoose
|
|
14
|
+
const cache = this.settings.get("cache");
|
|
15
|
+
// istanbul ignore next
|
|
16
|
+
if (cache === null || cache === void 0 ? void 0 : cache.mongoose) {
|
|
17
|
+
cache.connection = this.mongooseService.get();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
$onInit() { }
|
|
21
|
+
$onDestroy() {
|
|
22
|
+
return this.mongooseService.closeConnections();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
MongooseModule = __decorate([
|
|
26
|
+
Module({
|
|
27
|
+
imports: [MONGOOSE_CONNECTIONS]
|
|
28
|
+
}),
|
|
29
|
+
__param(1, Configuration()),
|
|
30
|
+
__metadata("design:paramtypes", [MongooseService, Object])
|
|
31
|
+
], MongooseModule);
|
|
32
|
+
export { MongooseModule };
|
|
33
|
+
//# sourceMappingURL=MongooseModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MongooseModule.js","sourceRoot":"","sources":["../../src/MongooseModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAS,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAC,MAAM,EAAY,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;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,MAAM,CAAC;QACN,OAAO,EAAE,CAAC,oBAAoB,CAAC;KAChC,CAAC;IAEuD,WAAA,aAAa,EAAE,CAAA;qCAAjC,eAAe;GADzC,cAAc,CAgB1B;SAhBY,cAAc","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,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @type {string}
|
|
4
|
+
*/
|
|
5
|
+
export const MONGOOSE_SCHEMA = "tsed:mongoose:schema";
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @type {string}
|
|
9
|
+
*/
|
|
10
|
+
export const MONGOOSE_SCHEMA_OPTIONS = "tsed:mongoose:schema:options";
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {string}
|
|
14
|
+
*/
|
|
15
|
+
export const MONGOOSE_MODEL = "tsed:mongoose:model";
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @type {string}
|
|
19
|
+
*/
|
|
20
|
+
export const MONGOOSE_MODEL_NAME = "tsed:mongoose:model:name";
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC;AACtD;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AACtE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AACpD;;;GAGG;AACH,MAAM,CAAC,MAAM,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,24 @@
|
|
|
1
|
+
import { MongooseSchema } from "./schema";
|
|
2
|
+
/**
|
|
3
|
+
* If true, uses Mongoose's default _id settings. Only allowed for ObjectIds
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Model()
|
|
9
|
+
* export class EventModel {
|
|
10
|
+
* @ExcludeIndexes()
|
|
11
|
+
* field: string;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param {boolean} auto
|
|
16
|
+
* @returns {Function}
|
|
17
|
+
* @decorator
|
|
18
|
+
* @mongoose
|
|
19
|
+
* @property
|
|
20
|
+
*/
|
|
21
|
+
export function Auto(auto = true) {
|
|
22
|
+
return MongooseSchema({ auto });
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=auto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto.js","sourceRoot":"","sources":["../../../src/decorators/auto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,IAAI,CAAC,OAAgB,IAAI;IACvC,OAAO,cAAc,CAAC,EAAC,IAAI,EAAQ,CAAC,CAAC;AACvC,CAAC","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,10 @@
|
|
|
1
|
+
import { Store, useDecorators } from "@tsed/core";
|
|
2
|
+
import { MONGOOSE_SCHEMA_OPTIONS } from "../constants";
|
|
3
|
+
import { SchemaIgnore } from "./schemaIgnore";
|
|
4
|
+
import { Property } from "@tsed/schema";
|
|
5
|
+
export function DiscriminatorKey() {
|
|
6
|
+
return useDecorators(Property(), SchemaIgnore(), (target, propertyKey) => {
|
|
7
|
+
Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, { discriminatorKey: propertyKey });
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=discriminatorKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminatorKey.js","sourceRoot":"","sources":["../../../src/decorators/discriminatorKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAChD,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEtC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,aAAa,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,EAAE,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACpF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAC,gBAAgB,EAAE,WAAW,EAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {Store, useDecorators} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../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,42 @@
|
|
|
1
|
+
import { StoreMerge, useDecorators } from "@tsed/core";
|
|
2
|
+
import { Description, Example, Property } from "@tsed/schema";
|
|
3
|
+
import { Schema as MongooseSchema } from "mongoose";
|
|
4
|
+
import { MONGOOSE_SCHEMA } from "../constants";
|
|
5
|
+
/**
|
|
6
|
+
* Define a property as mongoose reference to other Model (decorated with @Model).
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Model()
|
|
12
|
+
* class FooModel {
|
|
13
|
+
*
|
|
14
|
+
* @DynamicRef('type')
|
|
15
|
+
* field: DynamicRef<OtherFooModel | OtherModel>
|
|
16
|
+
*
|
|
17
|
+
* @Enum(['OtherFooModel', 'OtherModel'])
|
|
18
|
+
* type: string
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* @Model()
|
|
22
|
+
* class OtherFooModel {
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* @Model()
|
|
26
|
+
* class OtherModel {
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param refPath
|
|
31
|
+
* @returns {Function}
|
|
32
|
+
* @decorator
|
|
33
|
+
* @mongoose
|
|
34
|
+
* @property
|
|
35
|
+
*/
|
|
36
|
+
export function DynamicRef(refPath) {
|
|
37
|
+
return useDecorators(Property(String), Example("5ce7ad3028890bd71749d477"), Description("Mongoose Ref ObjectId"), StoreMerge(MONGOOSE_SCHEMA, {
|
|
38
|
+
type: MongooseSchema.Types.ObjectId,
|
|
39
|
+
refPath
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=dynamicRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,UAAU,CAAC;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,OAAO,aAAa,CAClB,QAAQ,CAAC,MAAM,CAAC,EAChB,OAAO,CAAC,0BAA0B,CAAC,EACnC,WAAW,CAAC,uBAAuB,CAAC,EACpC,UAAU,CAAC,eAAe,EAAE;QAC1B,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ;QACnC,OAAO;KACR,CAAC,CACkB,CAAC;AACzB,CAAC","sourcesContent":["import {StoreMerge, useDecorators} from \"@tsed/core\";\nimport {Description, Example, Property} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\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\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function DynamicRef(refPath: string): PropertyDecorator {\n return useDecorators(\n Property(String),\n Example(\"5ce7ad3028890bd71749d477\"),\n Description(\"Mongoose Ref ObjectId\"),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types.ObjectId,\n refPath\n })\n ) as PropertyDecorator;\n}\n\nexport type DynamicRef<T> = T | string;\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MongooseSchema } from "./schema";
|
|
2
|
+
/**
|
|
3
|
+
* If true, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Model()
|
|
9
|
+
* export class EventModel {
|
|
10
|
+
* @ExcludeIndexes()
|
|
11
|
+
* field: string;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param {boolean} excludeIndexes
|
|
16
|
+
* @returns {Function}
|
|
17
|
+
* @decorator
|
|
18
|
+
* @mongoose
|
|
19
|
+
* @property
|
|
20
|
+
*/
|
|
21
|
+
export function ExcludeIndexes(excludeIndexes = true) {
|
|
22
|
+
return MongooseSchema({ excludeIndexes });
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=excludeIndexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excludeIndexes.js","sourceRoot":"","sources":["../../../src/decorators/excludeIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAAC,iBAA0B,IAAI;IAC3D,OAAO,cAAc,CAAC,EAAC,cAAc,EAAQ,CAAC,CAAC;AACjD,CAAC","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,24 @@
|
|
|
1
|
+
import { MongooseSchema } from "./schema";
|
|
2
|
+
/**
|
|
3
|
+
* Defines a TTL index on this path. Only allowed for dates.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Model()
|
|
9
|
+
* export class EventModel {
|
|
10
|
+
* @Expires('5d')
|
|
11
|
+
* field: string;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param {boolean | any} expires
|
|
16
|
+
* @returns {Function}
|
|
17
|
+
* @decorator
|
|
18
|
+
* @mongoose
|
|
19
|
+
* @property
|
|
20
|
+
*/
|
|
21
|
+
export function Expires(expires) {
|
|
22
|
+
return MongooseSchema({ expires });
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=expires.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expires.js","sourceRoot":"","sources":["../../../src/decorators/expires.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CAAC,OAA+B;IACrD,OAAO,cAAc,CAAC,EAAC,OAAO,EAAQ,CAAC,CAAC;AAC1C,CAAC","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,26 @@
|
|
|
1
|
+
import { MongooseSchema } from "./schema";
|
|
2
|
+
/**
|
|
3
|
+
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
|
|
4
|
+
* disallow changes to this path once the document is saved to the database for the first time. Read more
|
|
5
|
+
* about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).
|
|
6
|
+
*
|
|
7
|
+
* ### Example
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* @Model()
|
|
11
|
+
* export class EventModel {
|
|
12
|
+
* @Immutable()
|
|
13
|
+
* field: string;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param {boolean | any} immutable
|
|
18
|
+
* @returns {Function}
|
|
19
|
+
* @decorator
|
|
20
|
+
* @mongoose
|
|
21
|
+
* @property
|
|
22
|
+
*/
|
|
23
|
+
export function Immutable(immutable = true) {
|
|
24
|
+
return MongooseSchema({ immutable });
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=immutable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"immutable.js","sourceRoot":"","sources":["../../../src/decorators/immutable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,SAAS,CAAC,YAA0D,IAAI;IACtF,OAAO,cAAc,CAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC","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,27 @@
|
|
|
1
|
+
export * from "./auto";
|
|
2
|
+
export * from "./discriminatorKey";
|
|
3
|
+
export * from "./dynamicRef";
|
|
4
|
+
export * from "./excludeIndexes";
|
|
5
|
+
export * from "./expires";
|
|
6
|
+
export * from "./immutable";
|
|
7
|
+
export * from "./indexed";
|
|
8
|
+
export * from "./lowercase";
|
|
9
|
+
export * from "./model";
|
|
10
|
+
export * from "./mongooseIndex";
|
|
11
|
+
export * from "./mongoosePlugin";
|
|
12
|
+
export * from "./numberDecimal";
|
|
13
|
+
export * from "./objectID";
|
|
14
|
+
export * from "./postHook";
|
|
15
|
+
export * from "./preHook";
|
|
16
|
+
export * from "./ref";
|
|
17
|
+
export * from "./schema";
|
|
18
|
+
export * from "./schemaIgnore";
|
|
19
|
+
export * from "./select";
|
|
20
|
+
export * from "./sparse";
|
|
21
|
+
export * from "./text";
|
|
22
|
+
export * from "./trim";
|
|
23
|
+
export * from "./unique";
|
|
24
|
+
export * from "./uppercase";
|
|
25
|
+
export * from "./versionKey";
|
|
26
|
+
export * from "./virtualRef";
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./auto\";\nexport * from \"./discriminatorKey\";\nexport * from \"./dynamicRef\";\nexport * from \"./excludeIndexes\";\nexport * from \"./expires\";\nexport * from \"./immutable\";\nexport * from \"./indexed\";\nexport * from \"./lowercase\";\nexport * from \"./model\";\nexport * from \"./mongooseIndex\";\nexport * from \"./mongoosePlugin\";\nexport * from \"./numberDecimal\";\nexport * from \"./objectID\";\nexport * from \"./postHook\";\nexport * from \"./preHook\";\nexport * from \"./ref\";\nexport * from \"./schema\";\nexport * from \"./schemaIgnore\";\nexport * from \"./select\";\nexport * from \"./sparse\";\nexport * from \"./text\";\nexport * from \"./trim\";\nexport * from \"./unique\";\nexport * from \"./uppercase\";\nexport * from \"./versionKey\";\nexport * from \"./virtualRef\";\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MongooseSchema } from "./schema";
|
|
2
|
+
/**
|
|
3
|
+
* Tell Mongoose whether to define an index for the property.
|
|
4
|
+
* ### Example
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @Model()
|
|
8
|
+
* export class EventModel {
|
|
9
|
+
* @Indexed()
|
|
10
|
+
* field: string;
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @returns {Function}
|
|
15
|
+
* @decorator
|
|
16
|
+
* @mongoose
|
|
17
|
+
* @property
|
|
18
|
+
*/
|
|
19
|
+
export function Indexed(index = true) {
|
|
20
|
+
return MongooseSchema({ index });
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=indexed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexed.js","sourceRoot":"","sources":["../../../src/decorators/indexed.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CAAC,QAAyC,IAAI;IACnE,OAAO,cAAc,CAAC,EAAC,KAAK,EAAQ,CAAC,CAAC;AACxC,CAAC","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,24 @@
|
|
|
1
|
+
import { MongooseSchema } from "./schema";
|
|
2
|
+
/**
|
|
3
|
+
* If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in String#toLowerCase().
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Model()
|
|
9
|
+
* export class EventModel {
|
|
10
|
+
* @Lowercase()
|
|
11
|
+
* field: string;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param {boolean} lowercase
|
|
16
|
+
* @returns {Function}
|
|
17
|
+
* @decorator
|
|
18
|
+
* @mongoose
|
|
19
|
+
* @property
|
|
20
|
+
*/
|
|
21
|
+
export function Lowercase(lowercase = true) {
|
|
22
|
+
return MongooseSchema({ lowercase });
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=lowercase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowercase.js","sourceRoot":"","sources":["../../../src/decorators/lowercase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,YAAqB,IAAI;IACjD,OAAO,cAAc,CAAC,EAAC,SAAS,EAAQ,CAAC,CAAC;AAC5C,CAAC","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,63 @@
|
|
|
1
|
+
import { registerProvider } from "@tsed/di";
|
|
2
|
+
import { MONGOOSE_CONNECTIONS } from "../services/MongooseConnections";
|
|
3
|
+
import { createModel, getModelToken, getSchema } from "../utils";
|
|
4
|
+
import { applySchemaOptions, schemaOptions } from "../utils/schemaOptions";
|
|
5
|
+
/**
|
|
6
|
+
* Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with
|
|
7
|
+
* `@Inject` annotation.
|
|
8
|
+
*
|
|
9
|
+
* ### Example
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* @Model()
|
|
13
|
+
* export class EventModel {
|
|
14
|
+
* @Property()
|
|
15
|
+
* field: string;
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Then inject the model into a service:
|
|
20
|
+
*
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class MyService {
|
|
23
|
+
* constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {
|
|
24
|
+
* eventModel.findById().exec();
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ### Options
|
|
30
|
+
*
|
|
31
|
+
* - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.
|
|
32
|
+
* - `name` (String): model name.
|
|
33
|
+
* - `collection` (String): collection (optional, induced from model name).
|
|
34
|
+
* - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).
|
|
35
|
+
*
|
|
36
|
+
* @param {MongooseModelOptions} options
|
|
37
|
+
* @returns {(target: any) => void}
|
|
38
|
+
* @decorator
|
|
39
|
+
* @mongoose
|
|
40
|
+
* @class
|
|
41
|
+
*/
|
|
42
|
+
export function Model(options = {}) {
|
|
43
|
+
return (target) => {
|
|
44
|
+
const { token, collectionName } = getModelToken(target, options);
|
|
45
|
+
registerProvider({
|
|
46
|
+
provide: token,
|
|
47
|
+
deps: [],
|
|
48
|
+
useFactory() {
|
|
49
|
+
return getSchema(target, options);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
registerProvider({
|
|
53
|
+
provide: target,
|
|
54
|
+
type: "mongoose:model",
|
|
55
|
+
deps: [MONGOOSE_CONNECTIONS, token],
|
|
56
|
+
useFactory(connections, schema) {
|
|
57
|
+
applySchemaOptions(schema, schemaOptions(target));
|
|
58
|
+
return createModel(target, schema, collectionName, options.collection, options.skipInit, connections.get(options.connection), options.discriminatorValue);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/decorators/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAC,oBAAoB,EAAC,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAC,kBAAkB,EAAE,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,KAAK,CAAC,UAAgC,EAAE;IACtD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,EAAC,KAAK,EAAE,cAAc,EAAC,GAAG,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE/D,gBAAgB,CAAC;YACf,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;YACR,UAAU;gBACR,OAAO,SAAS,CAAC,MAAM,EAAE,OAAc,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;QAEH,gBAAgB,CAAC;YACf,OAAO,EAAE,MAAM;YACf,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,CAAC,oBAAoB,EAAE,KAAK,CAAC;YACnC,UAAU,CAAC,WAAiC,EAAE,MAAc;gBAC1D,kBAAkB,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;gBAClD,OAAO,WAAW,CAChB,MAAM,EACN,MAAM,EACN,cAAc,EACd,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,QAAQ,EAChB,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EACnC,OAAO,CAAC,kBAAkB,CAC3B,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {registerProvider} from \"@tsed/di\";\nimport {Schema} from \"mongoose\";\nimport {MongooseModelOptions} from \"../interfaces/MongooseModelOptions\";\nimport {MONGOOSE_CONNECTIONS} from \"../services/MongooseConnections\";\nimport {createModel, getModelToken, getSchema} from \"../utils\";\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.skipInit,\n connections.get(options.connection),\n options.discriminatorValue\n );\n }\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { schemaOptions } from "../utils/schemaOptions";
|
|
2
|
+
/**
|
|
3
|
+
* Calls schema.index() to define an index (most likely compound) for the schema.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Model()
|
|
9
|
+
* @MongooseIndex({first: 1, second: 1}, {unique: 1})
|
|
10
|
+
* export class EventModel {
|
|
11
|
+
*
|
|
12
|
+
* @Property()
|
|
13
|
+
* first: string;
|
|
14
|
+
*
|
|
15
|
+
* @Property()
|
|
16
|
+
* second: string;
|
|
17
|
+
*
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param fields
|
|
22
|
+
* @param options
|
|
23
|
+
* @returns {Function}
|
|
24
|
+
* @decorator
|
|
25
|
+
* @mongoose
|
|
26
|
+
* @class
|
|
27
|
+
*/
|
|
28
|
+
export function MongooseIndex(fields, options) {
|
|
29
|
+
return (target) => {
|
|
30
|
+
schemaOptions(target, {
|
|
31
|
+
indexes: [{ fields, options }]
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=mongooseIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongooseIndex.js","sourceRoot":"","sources":["../../../src/decorators/mongooseIndex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,OAAa;IACzD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,aAAa,CAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","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,35 @@
|
|
|
1
|
+
import { schemaOptions } from "../utils/schemaOptions";
|
|
2
|
+
/**
|
|
3
|
+
* Calls schema.index() to define multiple indexes (most likely compound) for the schema.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @Model()
|
|
9
|
+
* @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])
|
|
10
|
+
* export class EventModel {
|
|
11
|
+
*
|
|
12
|
+
* @Property()
|
|
13
|
+
* first: string;
|
|
14
|
+
*
|
|
15
|
+
* @Property()
|
|
16
|
+
* second: string;
|
|
17
|
+
*
|
|
18
|
+
* @Property()
|
|
19
|
+
* third: string;
|
|
20
|
+
*
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param indexes - define multiple mongoose indexes
|
|
25
|
+
* @returns {Function}
|
|
26
|
+
* @decorator
|
|
27
|
+
* @mongoose
|
|
28
|
+
* @class
|
|
29
|
+
*/
|
|
30
|
+
export function MongooseIndexes(indexes) {
|
|
31
|
+
return (target) => {
|
|
32
|
+
schemaOptions(target, { indexes });
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=mongooseIndexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongooseIndexes.js","sourceRoot":"","sources":["../../../src/decorators/mongooseIndexes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,eAAe,CAAC,OAA+C;IAC7E,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,aAAa,CAAC,MAAM,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC","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,18 @@
|
|
|
1
|
+
import { schemaOptions } from "../utils/schemaOptions";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {(schema: "mongoose".Schema, options?: any) => void} plugin
|
|
5
|
+
* @param options
|
|
6
|
+
* @returns {Function}
|
|
7
|
+
* @decorator
|
|
8
|
+
* @mongoose
|
|
9
|
+
* @class
|
|
10
|
+
*/
|
|
11
|
+
export function MongoosePlugin(plugin, options) {
|
|
12
|
+
return (target) => {
|
|
13
|
+
schemaOptions(target, {
|
|
14
|
+
plugins: [{ plugin, options }]
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=mongoosePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoosePlugin.js","sourceRoot":"","sources":["../../../src/decorators/mongoosePlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,MAAwD,EAAE,OAAa;IACpG,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,aAAa,CAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","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"]}
|