@tsed/mongoose 7.0.0-beta.1 → 7.0.0-beta.4
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 +1 -1
- package/lib/cjs/MongooseModule.js +3 -3
- package/lib/cjs/MongooseModule.js.map +1 -1
- package/lib/cjs/constants/{index.js → constants.js} +1 -1
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/discriminatorKey.js +1 -1
- package/lib/cjs/decorators/discriminatorKey.js.map +1 -1
- package/lib/cjs/decorators/dynamicRef.js +24 -5
- package/lib/cjs/decorators/dynamicRef.js.map +1 -1
- package/lib/cjs/decorators/model.js +5 -4
- package/lib/cjs/decorators/model.js.map +1 -1
- package/lib/cjs/decorators/numberDecimal.js +2 -2
- package/lib/cjs/decorators/numberDecimal.js.map +1 -1
- package/lib/cjs/decorators/postHook.js.map +1 -1
- package/lib/cjs/decorators/preHook.js.map +1 -1
- package/lib/cjs/decorators/ref.js +1 -1
- package/lib/cjs/decorators/ref.js.map +1 -1
- package/lib/cjs/decorators/schema.js +1 -1
- package/lib/cjs/decorators/schema.js.map +1 -1
- package/lib/cjs/decorators/versionKey.js +1 -1
- package/lib/cjs/decorators/versionKey.js.map +1 -1
- package/lib/cjs/decorators/virtualRef.js +1 -1
- package/lib/cjs/decorators/virtualRef.js.map +1 -1
- package/lib/cjs/index.js +47 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/MongooseModel.js.map +1 -1
- package/lib/cjs/interfaces/MongooseModelOptions.js.map +1 -1
- package/lib/cjs/interfaces/MongooseSchemaOptions.js.map +1 -1
- 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/services/MongooseConnections.js +1 -5
- package/lib/cjs/services/MongooseConnections.js.map +1 -1
- package/lib/cjs/services/MongooseService.js +4 -4
- package/lib/cjs/services/MongooseService.js.map +1 -1
- package/lib/cjs/utils/createModel.js +7 -11
- package/lib/cjs/utils/createModel.js.map +1 -1
- package/lib/cjs/utils/createSchema.js +2 -2
- package/lib/cjs/utils/createSchema.js.map +1 -1
- package/lib/cjs/utils/resolveRefType.js +1 -1
- package/lib/cjs/utils/resolveRefType.js.map +1 -1
- package/lib/cjs/utils/schemaOptions.js +1 -1
- package/lib/cjs/utils/schemaOptions.js.map +1 -1
- package/lib/esm/MongooseModule.js +2 -2
- package/lib/esm/constants/{index.js → constants.js} +1 -1
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/auto.js +1 -1
- package/lib/esm/decorators/discriminatorKey.js +2 -2
- package/lib/esm/decorators/discriminatorKey.js.map +1 -1
- package/lib/esm/decorators/dynamicRef.js +26 -7
- package/lib/esm/decorators/dynamicRef.js.map +1 -1
- package/lib/esm/decorators/excludeIndexes.js +1 -1
- package/lib/esm/decorators/expires.js +1 -1
- package/lib/esm/decorators/immutable.js +1 -1
- package/lib/esm/decorators/indexed.js +1 -1
- package/lib/esm/decorators/lowercase.js +1 -1
- package/lib/esm/decorators/model.js +5 -4
- package/lib/esm/decorators/model.js.map +1 -1
- package/lib/esm/decorators/mongooseIndex.js +1 -1
- package/lib/esm/decorators/mongooseIndexes.js +1 -1
- package/lib/esm/decorators/mongoosePlugin.js +1 -1
- package/lib/esm/decorators/numberDecimal.js +1 -1
- package/lib/esm/decorators/numberDecimal.js.map +1 -1
- package/lib/esm/decorators/postHook.js +1 -1
- package/lib/esm/decorators/postHook.js.map +1 -1
- package/lib/esm/decorators/preHook.js +1 -1
- package/lib/esm/decorators/preHook.js.map +1 -1
- package/lib/esm/decorators/ref.js +3 -3
- package/lib/esm/decorators/ref.js.map +1 -1
- package/lib/esm/decorators/schema.js +2 -2
- package/lib/esm/decorators/schema.js.map +1 -1
- package/lib/esm/decorators/schemaIgnore.js +1 -1
- package/lib/esm/decorators/select.js +1 -1
- package/lib/esm/decorators/sparse.js +1 -1
- package/lib/esm/decorators/text.js +1 -1
- package/lib/esm/decorators/trim.js +1 -1
- package/lib/esm/decorators/unique.js +1 -1
- package/lib/esm/decorators/uppercase.js +1 -1
- package/lib/esm/decorators/versionKey.js +1 -1
- package/lib/esm/decorators/versionKey.js.map +1 -1
- package/lib/esm/decorators/virtualRef.js +2 -2
- package/lib/esm/decorators/virtualRef.js.map +1 -1
- package/lib/esm/index.js +47 -6
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/MongooseModel.js.map +1 -1
- package/lib/esm/interfaces/MongooseModelOptions.js.map +1 -1
- package/lib/esm/interfaces/MongooseSchemaOptions.js.map +1 -1
- 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/services/MongooseConnections.js +2 -6
- package/lib/esm/services/MongooseConnections.js.map +1 -1
- package/lib/esm/utils/createModel.js +8 -12
- package/lib/esm/utils/createModel.js.map +1 -1
- package/lib/esm/utils/createSchema.js +3 -3
- package/lib/esm/utils/createSchema.js.map +1 -1
- package/lib/esm/utils/resolveRefType.js +1 -1
- package/lib/esm/utils/resolveRefType.js.map +1 -1
- package/lib/esm/utils/schemaOptions.js +1 -1
- package/lib/esm/utils/schemaOptions.js.map +1 -1
- package/lib/types/constants/{index.d.ts → constants.d.ts} +0 -0
- package/lib/types/decorators/dynamicRef.d.ts +4 -2
- package/lib/types/decorators/postHook.d.ts +1 -1
- package/lib/types/decorators/preHook.d.ts +1 -1
- package/lib/types/decorators/schema.d.ts +1 -1
- package/lib/types/decorators/virtualRef.d.ts +0 -4
- package/lib/types/index.d.ts +46 -5
- package/lib/types/interfaces/MongooseModel.d.ts +1 -2
- package/lib/types/interfaces/MongooseModelOptions.d.ts +1 -1
- package/lib/types/interfaces/MongooseSchemaOptions.d.ts +1 -1
- package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -6
- package/lib/types/utils/createModel.d.ts +2 -2
- package/lib/types/utils/createSchema.d.ts +1 -1
- package/lib/types/utils/schemaOptions.d.ts +1 -1
- package/package.json +20 -18
- package/readme.md +124 -134
- package/tsconfig.compile.esm.json +2 -12
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/decorators/index.js +0 -30
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/cjs/interfaces/index.js +0 -10
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/cjs/utils/index.js +0 -6
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/esm/constants/index.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -27
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -7
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/esm/utils/index.js +0 -3
- package/lib/esm/utils/index.js.map +0 -1
- package/lib/types/decorators/index.d.ts +0 -26
- package/lib/types/utils/index.d.ts +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Store } from "@tsed/core";
|
|
2
|
-
import { MONGOOSE_SCHEMA_OPTIONS } from "../constants";
|
|
2
|
+
import { MONGOOSE_SCHEMA_OPTIONS } from "../constants/constants.js";
|
|
3
3
|
export function VersionKey() {
|
|
4
4
|
return (target, propertyKey) => {
|
|
5
5
|
Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, { versionKey: propertyKey });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versionKey.js","sourceRoot":"","sources":["../../../src/decorators/versionKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,uBAAuB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"versionKey.js","sourceRoot":"","sources":["../../../src/decorators/versionKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AAE/D,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\n\nexport function VersionKey(): PropertyDecorator {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(MONGOOSE_SCHEMA_OPTIONS, {versionKey: propertyKey});\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isPlainObject, isString, Store, StoreMerge, useDecorators } from "@tsed/core";
|
|
2
2
|
import { CollectionOf, Property } from "@tsed/schema";
|
|
3
|
-
import { MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA } from "../constants";
|
|
4
|
-
import { MongooseModels } from "../registries/MongooseModels";
|
|
3
|
+
import { MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA } from "../constants/constants.js";
|
|
4
|
+
import { MongooseModels } from "../registries/MongooseModels.js";
|
|
5
5
|
function getRef(opts) {
|
|
6
6
|
const ref = opts.ref;
|
|
7
7
|
return isString(ref) ? ref : Store.from(ref).get(MONGOOSE_MODEL_NAME);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrF,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACpD,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[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AAE,IAAI,CAAC,OAAO,IAAI,KAAK;QAC9B,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,KAAK;QAC1B,OAAO,EAAE,IAAI,CAAC,OAAO;KACtB,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAsBD,MAAM,UAAU,UAAU,CAAC,OAA2C,EAAE,YAAqB;IAC3F,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3B,OAAO,aAAa,CAClB,UAAU,CAAC,eAAe,EAAE,MAAM,CAAC,EACnC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CACjG,CAAC;AACJ,CAAC","sourcesContent":["import {isPlainObject, isString, Store, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {CollectionOf, Property} from \"@tsed/schema\";\nimport {MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseVirtualRefOptions} from \"../interfaces/MongooseVirtualRefOptions\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction getRef(opts: any) {\n const ref = opts.ref;\n\n return isString(ref) ? ref : Store.from(ref).get(MONGOOSE_MODEL_NAME);\n}\n\nfunction getType(opts: any) {\n const ref = opts.ref;\n return !isString(ref) ? ref : MongooseModels.get(ref) || (() => MongooseModels.get(ref) || Object);\n}\n\nfunction getInitialOpts(options: string | MongooseVirtualRefOptions, foreignField?: string): any {\n return isPlainObject(options) ? options : {ref: options as any, foreignField};\n}\n\nfunction mapToSchema(opts: any) {\n const ref = getRef(opts);\n\n const schema: any = {\n ref,\n localField: opts.localField || \"_id\",\n foreignField: opts.foreignField,\n justOne: opts.justOne || false,\n count: opts.count || false,\n options: opts.options\n };\n\n return schema;\n}\n\n/**\n * Define a property as mongoose virtual reference to other Model (decorated with @Model).\n *\n * ::: warning\n * To avoid circular dependencies, do not use the virtual reference model in\n * anything except a type declaration. Using the virtual reference model will prevent\n * typescript transpiler from stripping away the import statement and cause a circular\n * import in node.\n * :::\n *\n * @param ref\n * @param foreignField\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function VirtualRef(ref: string, foreignField: string): Function;\nexport function VirtualRef(options: MongooseVirtualRefOptions): Function;\nexport function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function;\nexport function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function {\n const opts = getInitialOpts(options, foreignField);\n const schema = mapToSchema(opts);\n const type = getType(opts);\n\n return useDecorators(\n StoreMerge(MONGOOSE_SCHEMA, schema),\n schema.count ? Property(Number) : type && (schema.justOne ? Property(type) : CollectionOf(type))\n );\n}\n\nexport type VirtualRef<T> = T | null;\nexport type VirtualRefs<T> = T[];\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,7 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./MongooseModule";
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./decorators";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./MongooseModule.js";
|
|
5
|
+
export * from "./constants/constants.js";
|
|
6
|
+
export * from "./decorators/auto.js";
|
|
7
|
+
export * from "./decorators/discriminatorKey.js";
|
|
8
|
+
export * from "./decorators/dynamicRef.js";
|
|
9
|
+
export * from "./decorators/excludeIndexes.js";
|
|
10
|
+
export * from "./decorators/expires.js";
|
|
11
|
+
export * from "./decorators/immutable.js";
|
|
12
|
+
export * from "./decorators/indexed.js";
|
|
13
|
+
export * from "./decorators/lowercase.js";
|
|
14
|
+
export * from "./decorators/model.js";
|
|
15
|
+
export * from "./decorators/mongooseIndex.js";
|
|
16
|
+
export * from "./decorators/mongooseIndexes.js";
|
|
17
|
+
export * from "./decorators/mongoosePlugin.js";
|
|
18
|
+
export * from "./decorators/numberDecimal.js";
|
|
19
|
+
export * from "./decorators/objectID.js";
|
|
20
|
+
export * from "./decorators/postHook.js";
|
|
21
|
+
export * from "./decorators/preHook.js";
|
|
22
|
+
export * from "./decorators/ref.js";
|
|
23
|
+
export * from "./decorators/schema.js";
|
|
24
|
+
export * from "./decorators/schemaIgnore.js";
|
|
25
|
+
export * from "./decorators/select.js";
|
|
26
|
+
export * from "./decorators/sparse.js";
|
|
27
|
+
export * from "./decorators/text.js";
|
|
28
|
+
export * from "./decorators/trim.js";
|
|
29
|
+
export * from "./decorators/unique.js";
|
|
30
|
+
export * from "./decorators/uppercase.js";
|
|
31
|
+
export * from "./decorators/versionKey.js";
|
|
32
|
+
export * from "./decorators/virtualRef.js";
|
|
33
|
+
export * from "./interfaces/MongooseConnectionOptions.js";
|
|
34
|
+
export * from "./interfaces/MongooseDocument.js";
|
|
35
|
+
export * from "./interfaces/MongooseModel.js";
|
|
36
|
+
export * from "./interfaces/MongooseModelOptions.js";
|
|
37
|
+
export * from "./interfaces/MongooseSchemaOptions.js";
|
|
38
|
+
export * from "./interfaces/MongooseSchemaTypes.js";
|
|
39
|
+
export * from "./interfaces/MongooseVirtualRefOptions.js";
|
|
40
|
+
export * from "./interfaces/interfaces.js";
|
|
41
|
+
export * from "./registries/MongooseModels.js";
|
|
42
|
+
export * from "./services/MongooseConnections.js";
|
|
43
|
+
export * from "./services/MongooseService.js";
|
|
44
|
+
export * from "./utils/createModel.js";
|
|
45
|
+
export * from "./utils/createSchema.js";
|
|
46
|
+
export * from "./utils/resolveRefType.js";
|
|
47
|
+
export * from "./utils/schemaOptions.js";
|
|
7
48
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC;AACvD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./MongooseModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/auto\";\nexport * from \"./decorators/discriminatorKey\";\nexport * from \"./decorators/dynamicRef\";\nexport * from \"./decorators/excludeIndexes\";\nexport * from \"./decorators/expires\";\nexport * from \"./decorators/immutable\";\nexport * from \"./decorators/indexed\";\nexport * from \"./decorators/lowercase\";\nexport * from \"./decorators/model\";\nexport * from \"./decorators/mongooseIndex\";\nexport * from \"./decorators/mongooseIndexes\";\nexport * from \"./decorators/mongoosePlugin\";\nexport * from \"./decorators/numberDecimal\";\nexport * from \"./decorators/objectID\";\nexport * from \"./decorators/postHook\";\nexport * from \"./decorators/preHook\";\nexport * from \"./decorators/ref\";\nexport * from \"./decorators/schema\";\nexport * from \"./decorators/schemaIgnore\";\nexport * from \"./decorators/select\";\nexport * from \"./decorators/sparse\";\nexport * from \"./decorators/text\";\nexport * from \"./decorators/trim\";\nexport * from \"./decorators/unique\";\nexport * from \"./decorators/uppercase\";\nexport * from \"./decorators/versionKey\";\nexport * from \"./decorators/virtualRef\";\nexport * from \"./interfaces/MongooseConnectionOptions\";\nexport * from \"./interfaces/MongooseDocument\";\nexport * from \"./interfaces/MongooseModel\";\nexport * from \"./interfaces/MongooseModelOptions\";\nexport * from \"./interfaces/MongooseSchemaOptions\";\nexport * from \"./interfaces/MongooseSchemaTypes\";\nexport * from \"./interfaces/MongooseVirtualRefOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./registries/MongooseModels\";\nexport * from \"./services/MongooseConnections\";\nexport * from \"./services/MongooseService\";\nexport * from \"./utils/createModel\";\nexport * from \"./utils/createSchema\";\nexport * from \"./utils/resolveRefType\";\nexport * from \"./utils/schemaOptions\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongooseModel.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModel.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MongooseModel.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModel.ts"],"names":[],"mappings":"","sourcesContent":["import {Document, Model} from \"mongoose\";\n\n// TODO since v5.11.5 Model require Document with id, See issue https://github.com/Automattic/mongoose/issues/9684\nexport type MongooseMergedDocument<T> = {[K in keyof T]: T[K]};\n\nexport interface MongooseDocumentMethods<T> {\n toClass(): T;\n}\n\nexport type MongooseModel<T> = Model<MongooseMergedDocument<Document & T & MongooseDocumentMethods<T>>>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongooseModelOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModelOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {MongooseSchemaOptions} from \"./MongooseSchemaOptions\";\n\nexport interface MongooseModelOptions extends MongooseSchemaOptions {\n name?: string;\n connection?: string;\n collection?: string;\n
|
|
1
|
+
{"version":3,"file":"MongooseModelOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseModelOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {MongooseSchemaOptions} from \"./MongooseSchemaOptions\";\nimport {CompileModelOptions} from \"mongoose\";\n\nexport interface MongooseModelOptions extends MongooseSchemaOptions {\n name?: string;\n connection?: string;\n collection?: string;\n overwriteModels?: boolean;\n discriminatorValue?: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {NativeError, Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: NativeError) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongoosePreHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: NativeError, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: NativeError) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields:
|
|
1
|
+
{"version":3,"file":"MongooseSchemaOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseSchemaOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {NativeError, Schema, SchemaOptions} from \"mongoose\";\nimport {MongooseDocument} from \"./MongooseDocument\";\n\nexport type MongooseNextCB = (err?: NativeError) => void;\n\nexport interface MongooseHookOptions {\n document?: boolean;\n query?: boolean;\n parallel?: boolean;\n}\n\nexport type MongoosePreHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport type MongoosePostHookCB<T = any> =\n | ((doc: T | MongooseDocument<T>, error: NativeError, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>, error: NativeError) => Promise<void> | void)\n | ((doc: T | MongooseDocument<T>, next: MongooseNextCB) => void)\n | ((doc: T | MongooseDocument<T>) => Promise<void> | void);\n\nexport interface MongoosePreHook<T = any> {\n method: string | RegExp;\n fn: MongoosePreHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePostHook<T = any> {\n method: string | RegExp;\n fn: MongoosePostHookCB<T>;\n options?: MongooseHookOptions;\n}\n\nexport interface MongoosePluginOptions {\n plugin: (schema: Schema, options?: any) => void;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseIndexOptions {\n fields: Record<any, any>;\n options?: Record<string, unknown>;\n}\n\nexport interface MongooseSchemaOptions {\n schemaOptions?: SchemaOptions;\n plugins?: MongoosePluginOptions[];\n indexes?: MongooseIndexOptions[];\n pre?: MongoosePreHook[];\n post?: MongoosePostHook[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {MongooseConnectionOptions} from \"./MongooseConnectionOptions\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n mongoose: Omit<MongooseConnectionOptions, \"id\"> | MongooseConnectionOptions[];\n }\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Configuration, registerProvider } from "@tsed/di";
|
|
2
2
|
import { isArray } from "@tsed/core";
|
|
3
|
-
import { MongooseService } from "../services/MongooseService";
|
|
3
|
+
import { MongooseService } from "../services/MongooseService.js";
|
|
4
4
|
/**
|
|
5
5
|
* @ignore
|
|
6
6
|
*/
|
|
@@ -35,11 +35,7 @@ registerProvider({
|
|
|
35
35
|
const settings = mapOptions(configuration.get("mongoose"));
|
|
36
36
|
let isDefault = true;
|
|
37
37
|
for (const current of settings) {
|
|
38
|
-
await mongooseService.connect(current.id, current.url, current.connectionOptions || {
|
|
39
|
-
useCreateIndex: true,
|
|
40
|
-
useNewUrlParser: true,
|
|
41
|
-
useUnifiedTopology: true
|
|
42
|
-
}, isDefault);
|
|
38
|
+
await mongooseService.connect(current.id, current.url, current.connectionOptions || {}, isDefault);
|
|
43
39
|
isDefault = false;
|
|
44
40
|
}
|
|
45
41
|
return mongooseService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongooseConnections.js","sourceRoot":"","sources":["../../../src/services/MongooseConnections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AACzD,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAE5D;;GAEG;AACH,yCAAyC;AACzC,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAMvE,SAAS,UAAU,CAAC,OAA4E;IAC9F,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,EAAE,CAAC;KACX;IAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACrB,MAAM,EAAC,GAAG,EAAE,iBAAiB,EAAC,GAAG,OAAO,IAAI,EAAE,CAAC;QAE/C,OAAO;YACL;gBACE,EAAE,EAAE,SAAS;gBACb,GAAG;gBACH,iBAAiB;aAClB;SACF,CAAC;KACH;IAED,OAAQ,OAAuC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC/D,OAAO;YACL,GAAG,QAAQ;YACX,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;SAC9C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,gBAAgB,CAAC;IACf,OAAO,EAAE,oBAAoB;IAC7B,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,CAAC,aAAa,EAAE,eAAe,CAAC;IACtC,KAAK,CAAC,eAAe,CAAC,aAA4B,EAAE,eAAgC;QAClF,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,CAA0D,UAAU,CAAC,CAAC,CAAC;QACpH,IAAI,SAAS,GAAG,IAAI,CAAC;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,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,iBAAiB,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC;YAEnG,SAAS,GAAG,KAAK,CAAC;SACnB;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {Configuration, registerProvider} from \"@tsed/di\";\nimport {isArray} from \"@tsed/core\";\nimport {MongooseConnectionOptions} from \"../interfaces/MongooseConnectionOptions\";\nimport {MongooseService} from \"../services/MongooseService\";\n\n/**\n * @ignore\n */\n// tslint:disable-next-line:variable-name\nexport const MONGOOSE_CONNECTIONS = Symbol.for(\"MONGOOSE_CONNECTIONS\");\n/**\n * @ignore\n */\nexport type MONGOOSE_CONNECTIONS = MongooseService;\n\nfunction mapOptions(options: Omit<MongooseConnectionOptions, \"id\"> | MongooseConnectionOptions[]): MongooseConnectionOptions[] {\n if (!options) {\n return [];\n }\n\n if (!isArray(options)) {\n const {url, connectionOptions} = options || {};\n\n return [\n {\n id: \"default\",\n url,\n connectionOptions\n }\n ];\n }\n\n return (options as MongooseConnectionOptions[]).map((settings) => {\n return {\n ...settings,\n connectionOptions: settings.connectionOptions\n };\n });\n}\n\nregisterProvider({\n provide: MONGOOSE_CONNECTIONS,\n injectable: false,\n deps: [Configuration, MongooseService],\n async useAsyncFactory(configuration: Configuration, mongooseService: MongooseService) {\n const settings = mapOptions(configuration.get<MongooseConnectionOptions | MongooseConnectionOptions[]>(\"mongoose\"));\n let isDefault = true;\n\n for (const current of settings) {\n await mongooseService.connect(current.id, current.url, current.connectionOptions || {}, isDefault);\n\n isDefault = false;\n }\n\n return mongooseService;\n }\n});\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ancestorsOf, nameOf, Store } from "@tsed/core";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
|
-
import { MONGOOSE_MODEL, MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA_OPTIONS } from "../constants";
|
|
4
|
-
import { MongooseModels } from "../registries/MongooseModels";
|
|
5
|
-
import { getSchemaToken } from "./createSchema";
|
|
3
|
+
import { MONGOOSE_MODEL, MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA_OPTIONS } from "../constants/constants.js";
|
|
4
|
+
import { MongooseModels } from "../registries/MongooseModels.js";
|
|
5
|
+
import { getSchemaToken } from "./createSchema.js";
|
|
6
6
|
export function getModelToken(target, options) {
|
|
7
7
|
const { collectionName, token } = getSchemaToken(target, options);
|
|
8
8
|
Store.from(target).set(MONGOOSE_MODEL_NAME, collectionName);
|
|
@@ -16,12 +16,12 @@ export function getModelToken(target, options) {
|
|
|
16
16
|
* @param {"mongoose".Schema} schema Schema that will be attached to the model.
|
|
17
17
|
* @param name model name
|
|
18
18
|
* @param collection (optional, induced from model name)
|
|
19
|
-
* @param
|
|
19
|
+
* @param overwriteModels
|
|
20
20
|
* @param connection
|
|
21
21
|
* @param discriminatorValue
|
|
22
22
|
* @returns {Model<T extends Document>}
|
|
23
23
|
*/
|
|
24
|
-
export function createModel(target, schema, name = nameOf(target), collection,
|
|
24
|
+
export function createModel(target, schema, name = nameOf(target), collection, overwriteModels, connection, discriminatorValue) {
|
|
25
25
|
// if ancestor has a discriminatorKey we need to link model with anscestor schema
|
|
26
26
|
const ancestor = ancestorsOf(target).find((ancestor) => {
|
|
27
27
|
const options = Store.from(ancestor).get(MONGOOSE_SCHEMA_OPTIONS) || {};
|
|
@@ -39,13 +39,9 @@ export function createModel(target, schema, name = nameOf(target), collection, s
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Store.from(target).set(MONGOOSE_MODEL, model);
|
|
46
|
-
return model;
|
|
47
|
-
}
|
|
48
|
-
const model = mongoose.model(name, schema, collection, skipInit);
|
|
42
|
+
const opts = overwriteModels ? { overwriteModels } : undefined;
|
|
43
|
+
const c = connection || mongoose;
|
|
44
|
+
const model = c.model(name, schema, collection, opts);
|
|
49
45
|
Store.from(target).set(MONGOOSE_MODEL, model);
|
|
50
46
|
return model;
|
|
51
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createModel.js","sourceRoot":"","sources":["../../../src/utils/createModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"createModel.js","sourceRoot":"","sources":["../../../src/utils/createModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAC5D,OAAO,QAAmE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAE,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AACpG,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,aAAa,CAAC,MAAiB,EAAE,OAAY;IAC3D,MAAM,EAAC,cAAc,EAAE,KAAK,EAAC,GAAG,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEhE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;IAC5D,cAAc,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAE3C,OAAO,EAAC,KAAK,EAAE,cAAc,EAAC,CAAC;AACjC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CACzB,MAAW,EACX,MAAuB,EACvB,OAAe,MAAM,CAAC,MAAM,CAAC,EAC7B,UAAmB,EACnB,eAAyB,EACzB,UAAuB,EACvB,kBAA2B;IAE3B,iFAAiF;IACjF,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QACrD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,EAAE,CAAC;QACxE,OAAO,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,IAAI,QAAQ,IAAI,QAAQ,KAAK,MAAM,EAAE;QACnC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,cAAc,CAA6C,CAAC;QAC3G,IAAI,aAAa,EAAE;YACjB,MAAM,iBAAiB,GAAG,kBAAkB,IAAI,IAAI,CAAC;YACrD,IAAI,aAAa,CAAC,cAAc,IAAI,aAAa,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE;gBACnF,OAAO,aAAa,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;aACxD;iBAAM;gBACL,OAAO,aAAa,CAAC,aAAa,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;aAC/D;SACF;KACF;IAED,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,EAAC,eAAe,EAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,MAAM,CAAC,GAAG,UAAU,IAAI,QAAQ,CAAC;IAEjC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACtD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAE9C,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import {ancestorsOf, nameOf, Store, Type} from \"@tsed/core\";\nimport mongoose, {CompileModelOptions, Connection, Model as MongooseModel} from \"mongoose\";\nimport {MONGOOSE_MODEL, MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\nimport {getSchemaToken} from \"./createSchema\";\n\nexport function getModelToken(target: Type<any>, options: any) {\n const {collectionName, token} = getSchemaToken(target, options);\n\n Store.from(target).set(MONGOOSE_MODEL_NAME, collectionName);\n MongooseModels.set(collectionName, target);\n\n return {token, collectionName};\n}\n\n/**\n * Create an instance of mongoose.model from a class.\n *\n * @param {Type<any>} target Class attached to the schema and model.\n * @param {\"mongoose\".Schema} schema Schema that will be attached to the model.\n * @param name model name\n * @param collection (optional, induced from model name)\n * @param overwriteModels\n * @param connection\n * @param discriminatorValue\n * @returns {Model<T extends Document>}\n */\nexport function createModel<T>(\n target: any,\n schema: mongoose.Schema,\n name: string = nameOf(target),\n collection?: string,\n overwriteModels?: boolean,\n connection?: Connection,\n discriminatorValue?: string\n) {\n // if ancestor has a discriminatorKey we need to link model with anscestor schema\n const ancestor = ancestorsOf(target).find((ancestor) => {\n const options = Store.from(ancestor).get(MONGOOSE_SCHEMA_OPTIONS) || {};\n return !!options.discriminatorKey;\n });\n\n if (ancestor && ancestor !== target) {\n const ancestorModel = Store.from(ancestor).get(MONGOOSE_MODEL) as MongooseModel<typeof target> | undefined;\n if (ancestorModel) {\n const discriminatorName = discriminatorValue || name;\n if (ancestorModel.discriminators && ancestorModel.discriminators[discriminatorName]) {\n return ancestorModel.discriminators[discriminatorName];\n } else {\n return ancestorModel.discriminator(discriminatorName, schema);\n }\n }\n }\n\n const opts = overwriteModels ? {overwriteModels} : undefined;\n const c = connection || mongoose;\n\n const model = c.model(name, schema, collection, opts);\n Store.from(target).set(MONGOOSE_MODEL, model);\n\n return model;\n}\n"]}
|
|
@@ -3,9 +3,9 @@ import { deserialize, serialize } from "@tsed/json-mapper";
|
|
|
3
3
|
import { getProperties } from "@tsed/schema";
|
|
4
4
|
import { pascalCase } from "change-case";
|
|
5
5
|
import mongoose from "mongoose";
|
|
6
|
-
import { MONGOOSE_SCHEMA, MONGOOSE_SCHEMA_OPTIONS } from "../constants";
|
|
7
|
-
import { resolveRefType } from "./resolveRefType";
|
|
8
|
-
import { schemaOptions } from "./schemaOptions";
|
|
6
|
+
import { MONGOOSE_SCHEMA, MONGOOSE_SCHEMA_OPTIONS } from "../constants/constants.js";
|
|
7
|
+
import { resolveRefType } from "./resolveRefType.js";
|
|
8
|
+
import { schemaOptions } from "./schemaOptions.js";
|
|
9
9
|
const MONGOOSE_RESERVED_KEYS = ["_id"];
|
|
10
10
|
/**
|
|
11
11
|
* @ignore
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSchema.js","sourceRoot":"","sources":["../../../src/utils/createSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,aAAa,EAAkB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,QAAsE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAC,eAAe,EAAE,uBAAuB,EAAC,MAAM,cAAc,CAAC;AAGtE,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,MAAM,sBAAsB,GAAG,CAAC,KAAK,CAAC,CAAC;AAOvC;;GAEG;AACH,SAAS,WAAW,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAyB,EAAE,OAAuB;IACtF,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5D,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;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cleanObject, nameOf, Store, Type} from \"@tsed/core\";\nimport {deserialize, serialize} from \"@tsed/json-mapper\";\nimport {getProperties, JsonEntityStore} from \"@tsed/schema\";\nimport {pascalCase} from \"change-case\";\nimport mongoose, {Schema, SchemaDefinition, SchemaOptions, SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA, MONGOOSE_SCHEMA_OPTIONS} from \"../constants\";\nimport {MongooseSchemaOptions} from \"../interfaces\";\nimport {MongooseVirtualRefOptions} from \"../interfaces/MongooseVirtualRefOptions\";\nimport {resolveRefType} from \"./resolveRefType\";\nimport {schemaOptions} from \"./schemaOptions\";\n\nconst MONGOOSE_RESERVED_KEYS = [\"_id\"];\n\nexport interface MongooseSchemaMetadata {\n schema: SchemaDefinition;\n virtuals: Map<string, MongooseVirtualRefOptions>;\n}\n\n/**\n * @ignore\n */\nfunction setUpSchema({schema, virtuals}: MongooseSchemaMetadata, options?: SchemaOptions) {\n const mongooseSchema = new mongoose.Schema(schema, options);\n\n for (const [key, options] of virtuals.entries()) {\n mongooseSchema.virtual(key, options);\n }\n\n return mongooseSchema;\n}\n\n/**\n * @ignore\n */\nfunction isVirtualRef(target: Partial<MongooseVirtualRefOptions>): target is MongooseVirtualRefOptions {\n return !!(target.ref && target.localField && target.foreignField);\n}\n\nfunction hasVersionField(schema: mongoose.Schema, versionKey?: string | boolean) {\n // Check if versioning was disabled explicitly\n if (!versionKey) return false;\n\n // Check for alternative version field in schema\n return (versionKey as string) in schema.paths;\n}\n\nexport function createSchema(target: Type<any>, options: MongooseSchemaOptions = {}): mongoose.Schema {\n const schemaOptionsFromStore = Store.from(target).get(MONGOOSE_SCHEMA_OPTIONS) || {};\n options.schemaOptions = {...options.schemaOptions, ...schemaOptionsFromStore};\n\n const schema = setUpSchema(buildMongooseSchema(target), options.schemaOptions);\n\n schemaOptions(target, options);\n\n const outputVersionKey = hasVersionField(schema, options.schemaOptions?.versionKey);\n\n schema.methods.toClass = function toClass() {\n return deserialize(\n this.toObject({\n versionKey: outputVersionKey,\n flattenMaps: true\n }),\n {\n type: target,\n useAlias: false,\n additionalProperties: true,\n groups: false\n }\n );\n };\n\n schema.methods.toJSON = function toJSON(options?: any) {\n return serialize((this as any).toClass(), options);\n };\n\n schema.loadClass(target);\n\n Store.from(target).set(MONGOOSE_SCHEMA, schema);\n\n return schema;\n}\n\n/**\n * Get a schema already created. If the schema doesn't exists in registry, it'll be created.\n * @param target\n * @param options\n */\nexport function getSchema(target: Type<any>, options: MongooseSchemaOptions = {}): Schema {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA)) {\n createSchema(target, options);\n }\n\n return store.get(MONGOOSE_SCHEMA);\n}\n\nexport function getSchemaToken(target: Type<any>, options?: any) {\n const collectionName = options.name || nameOf(target);\n const token = Symbol.for(pascalCase(`${collectionName}Schema`));\n\n return {token, collectionName};\n}\n\n/**\n * @ignore\n */\nexport function buildMongooseSchema(target: any): MongooseSchemaMetadata {\n const properties = getProperties(target, {withIgnoredProps: true, mongoose: true, groups: false});\n const schema: MongooseSchemaMetadata = {schema: {}, virtuals: new Map()};\n\n properties.forEach((propertyMetadata, key) => {\n if (MONGOOSE_RESERVED_KEYS.includes(key as string)) {\n return;\n }\n\n // Keeping the Mongoose Schema separate so it can overwrite everything once schema has been built.\n const schemaTypeOptions: any = propertyMetadata.store.get(MONGOOSE_SCHEMA) || {};\n\n if (schemaTypeOptions.schemaIgnore) {\n return;\n }\n\n if (schemaTypeOptions.ref) {\n schemaTypeOptions.ref = resolveRefType(schemaTypeOptions.ref as any);\n }\n\n if (isVirtualRef(schemaTypeOptions)) {\n schema.virtuals.set(key as string, schemaTypeOptions);\n\n return;\n }\n\n schema.schema[key as string] = createSchemaTypeOptions(propertyMetadata);\n });\n\n return schema;\n}\n\n/**\n * @ignore\n */\nexport function createSchemaTypeOptions<T = any>(propEntity: JsonEntityStore): SchemaTypeOptions<T> | SchemaTypeOptions<T>[] {\n const key = propEntity.propertyKey;\n const rawMongooseSchema = propEntity.store.get(MONGOOSE_SCHEMA) || {};\n\n let schemaTypeOptions: SchemaTypeOptions<T> = {\n required: propEntity.required\n ? function () {\n return propEntity.isRequired(this[key]);\n }\n : false\n };\n\n if (!propEntity.isClass) {\n const jsonSchema = propEntity.itemSchema.toJSON();\n const {minimum: min, maximum: max, minLength: minlength, maxLength: maxlength} = jsonSchema;\n\n let match: string | RegExp = jsonSchema.pattern;\n if (match) {\n match = new RegExp(match);\n }\n\n schemaTypeOptions = {\n ...schemaTypeOptions,\n type: propEntity.type,\n match: match as RegExp,\n min,\n max,\n minlength,\n maxlength,\n enum: jsonSchema[\"enum\"],\n default: jsonSchema[\"default\"]\n };\n } else if (!rawMongooseSchema.ref) {\n // References are handled by the final merge\n schemaTypeOptions = {...schemaTypeOptions, type: getSchema(propEntity.type) as any};\n }\n\n schemaTypeOptions = cleanObject({...schemaTypeOptions, ...rawMongooseSchema});\n\n if (propEntity.isCollection) {\n if (propEntity.isArray) {\n return [schemaTypeOptions];\n }\n // Can be a Map or a Set;\n // Mongoose implements only Map;\n if (propEntity.collectionType !== Map) {\n throw new Error(`Invalid collection type. ${nameOf(propEntity.collectionType)} is not supported.`);\n }\n\n return ({type: Map, of: schemaTypeOptions} as unknown) as SchemaTypeOptions<T>;\n }\n\n return schemaTypeOptions;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createSchema.js","sourceRoot":"","sources":["../../../src/utils/createSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAC,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAC,aAAa,EAAkB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,QAAsE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAC,eAAe,EAAE,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;A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AC,YAAY,EAAE;QAC3B,IAAI,UAAU,CAAC,OAAO,EAAE;YACtB,OAAO,CAAC,iBAAiB,CAAC,CAAC;SAC5B;QACD,yBAAyB;QACzB,gCAAgC;QAChC,IAAI,UAAU,CAAC,cAAc,KAAK,GAAG,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,4BAA4B,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;SACpG;QAED,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,iBAAiB,EAAoC,CAAC;KAC9E;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import {cleanObject, nameOf, Store, Type} from \"@tsed/core\";\nimport {deserialize, serialize} from \"@tsed/json-mapper\";\nimport {getProperties, JsonEntityStore} from \"@tsed/schema\";\nimport {pascalCase} from \"change-case\";\nimport mongoose, {Schema, SchemaDefinition, SchemaOptions, SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA, MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {MongooseSchemaOptions} from \"../interfaces/MongooseSchemaOptions\";\nimport {MongooseVirtualRefOptions} from \"../interfaces/MongooseVirtualRefOptions\";\nimport {resolveRefType} from \"./resolveRefType\";\nimport {schemaOptions} from \"./schemaOptions\";\n\nconst MONGOOSE_RESERVED_KEYS = [\"_id\"];\n\nexport interface MongooseSchemaMetadata {\n schema: SchemaDefinition;\n virtuals: Map<string, MongooseVirtualRefOptions>;\n}\n\n/**\n * @ignore\n */\nfunction setUpSchema({schema, virtuals}: MongooseSchemaMetadata, options?: SchemaOptions) {\n const mongooseSchema = new mongoose.Schema(schema, options);\n\n for (const [key, options] of virtuals.entries()) {\n mongooseSchema.virtual(key, options);\n }\n\n return mongooseSchema;\n}\n\n/**\n * @ignore\n */\nfunction isVirtualRef(target: Partial<MongooseVirtualRefOptions>): target is MongooseVirtualRefOptions {\n return !!(target.ref && target.localField && target.foreignField);\n}\n\nfunction hasVersionField(schema: mongoose.Schema, versionKey?: string | boolean) {\n // Check if versioning was disabled explicitly\n if (!versionKey) return false;\n\n // Check for alternative version field in schema\n return (versionKey as string) in schema.paths;\n}\n\nexport function createSchema(target: Type<any>, options: MongooseSchemaOptions = {}): mongoose.Schema {\n const schemaOptionsFromStore = Store.from(target).get(MONGOOSE_SCHEMA_OPTIONS) || {};\n options.schemaOptions = {...options.schemaOptions, ...schemaOptionsFromStore};\n\n const schema = setUpSchema(buildMongooseSchema(target), options.schemaOptions);\n\n schemaOptions(target, options);\n\n const outputVersionKey = hasVersionField(schema, options.schemaOptions?.versionKey);\n\n schema.methods.toClass = function toClass() {\n return deserialize(\n this.toObject({\n versionKey: outputVersionKey,\n flattenMaps: true\n }),\n {\n type: target,\n useAlias: false,\n additionalProperties: true,\n groups: false\n }\n );\n };\n\n schema.methods.toJSON = function toJSON(options?: any) {\n return serialize((this as any).toClass(), options);\n };\n\n schema.loadClass(target);\n\n Store.from(target).set(MONGOOSE_SCHEMA, schema);\n\n return schema;\n}\n\n/**\n * Get a schema already created. If the schema doesn't exists in registry, it'll be created.\n * @param target\n * @param options\n */\nexport function getSchema(target: Type<any>, options: MongooseSchemaOptions = {}): Schema {\n const store = Store.from(target);\n\n if (!store.has(MONGOOSE_SCHEMA)) {\n createSchema(target, options);\n }\n\n return store.get(MONGOOSE_SCHEMA);\n}\n\nexport function getSchemaToken(target: Type<any>, options?: any) {\n const collectionName = options.name || nameOf(target);\n const token = Symbol.for(pascalCase(`${collectionName}Schema`));\n\n return {token, collectionName};\n}\n\n/**\n * @ignore\n */\nexport function buildMongooseSchema(target: any): MongooseSchemaMetadata {\n const properties = getProperties(target, {withIgnoredProps: true, mongoose: true, groups: false});\n const schema: MongooseSchemaMetadata = {schema: {}, virtuals: new Map()};\n\n properties.forEach((propertyMetadata, key) => {\n if (MONGOOSE_RESERVED_KEYS.includes(key as string)) {\n return;\n }\n\n // Keeping the Mongoose Schema separate so it can overwrite everything once schema has been built.\n const schemaTypeOptions: any = propertyMetadata.store.get(MONGOOSE_SCHEMA) || {};\n\n if (schemaTypeOptions.schemaIgnore) {\n return;\n }\n\n if (schemaTypeOptions.ref) {\n schemaTypeOptions.ref = resolveRefType(schemaTypeOptions.ref as any);\n }\n\n if (isVirtualRef(schemaTypeOptions)) {\n schema.virtuals.set(key as string, schemaTypeOptions);\n\n return;\n }\n\n schema.schema[key as string] = createSchemaTypeOptions(propertyMetadata);\n });\n\n return schema;\n}\n\n/**\n * @ignore\n */\nexport function createSchemaTypeOptions<T = any>(propEntity: JsonEntityStore): SchemaTypeOptions<T> | SchemaTypeOptions<T>[] {\n const key = propEntity.propertyKey;\n const rawMongooseSchema = propEntity.store.get(MONGOOSE_SCHEMA) || {};\n\n let schemaTypeOptions: SchemaTypeOptions<T> = {\n required: propEntity.required\n ? function () {\n return propEntity.isRequired(this[key]);\n }\n : false\n };\n\n if (!propEntity.isClass) {\n const jsonSchema = propEntity.itemSchema.toJSON();\n const {minimum: min, maximum: max, minLength: minlength, maxLength: maxlength} = jsonSchema;\n\n let match: string | RegExp = jsonSchema.pattern;\n if (match) {\n match = new RegExp(match);\n }\n\n schemaTypeOptions = {\n ...schemaTypeOptions,\n type: propEntity.type,\n match: match as RegExp,\n min,\n max,\n minlength,\n maxlength,\n enum: jsonSchema[\"enum\"],\n default: jsonSchema[\"default\"]\n };\n } else if (!rawMongooseSchema.ref) {\n // References are handled by the final merge\n schemaTypeOptions = {...schemaTypeOptions, type: getSchema(propEntity.type) as any};\n }\n\n schemaTypeOptions = cleanObject({...schemaTypeOptions, ...rawMongooseSchema});\n\n if (propEntity.isCollection) {\n if (propEntity.isArray) {\n return [schemaTypeOptions];\n }\n // Can be a Map or a Set;\n // Mongoose implements only Map;\n if (propEntity.collectionType !== Map) {\n throw new Error(`Invalid collection type. ${nameOf(propEntity.collectionType)} is not supported.`);\n }\n\n return {type: Map, of: schemaTypeOptions} as unknown as SchemaTypeOptions<T>;\n }\n\n return schemaTypeOptions;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRefType.js","sourceRoot":"","sources":["../../../src/utils/resolveRefType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAClE,OAAO,EAAC,mBAAmB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"resolveRefType.js","sourceRoot":"","sources":["../../../src/utils/resolveRefType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAClE,OAAO,EAAC,mBAAmB,EAAC,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAA4C;IACzE,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAClB,IAAI,GAAI,IAAY,EAAE,CAAC;KACxB;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import {isClass, isString, nameOf, Store, Type} from \"@tsed/core\";\nimport {MONGOOSE_MODEL_NAME} from \"../constants/constants\";\n\n/**\n * @ignore\n */\nexport function resolveRefType(type: string | (() => Type<any>) | Type<any>): string {\n if (isString(type)) {\n return type;\n }\n\n if (!isClass(type)) {\n type = (type as any)();\n }\n\n return Store.from(type).get(MONGOOSE_MODEL_NAME) || nameOf(type);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":["../../../src/utils/schemaOptions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"schemaOptions.js","sourceRoot":"","sources":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H,MAAM,UAAU,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","sourcesContent":["import {deepMerge, Store} from \"@tsed/core\";\nimport {Schema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA_OPTIONS} from \"../constants/constants\";\nimport {MongooseNextCB, MongoosePostHook, MongoosePreHook, MongooseSchemaOptions} from \"../interfaces/MongooseSchemaOptions\";\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"]}
|
|
File without changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
1
2
|
/**
|
|
2
3
|
* Define a property as mongoose reference to other Model (decorated with @Model).
|
|
3
4
|
*
|
|
@@ -23,11 +24,12 @@
|
|
|
23
24
|
* }
|
|
24
25
|
* ```
|
|
25
26
|
*
|
|
26
|
-
* @param refPath
|
|
27
|
+
* @param refPath {String} the path to apply the correct model
|
|
28
|
+
* @param types {Type} the classes to generate the correct json schema
|
|
27
29
|
* @returns {Function}
|
|
28
30
|
* @decorator
|
|
29
31
|
* @mongoose
|
|
30
32
|
* @property
|
|
31
33
|
*/
|
|
32
|
-
export declare function DynamicRef(refPath: string): PropertyDecorator;
|
|
34
|
+
export declare function DynamicRef(refPath: string, ...types: Type<any>[]): PropertyDecorator;
|
|
33
35
|
export declare type DynamicRef<T> = T | string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StaticMethodDecorator } from "@tsed/core";
|
|
2
|
-
import { MongooseHookOptions, MongoosePostHookCB } from "../interfaces";
|
|
2
|
+
import { MongooseHookOptions, MongoosePostHookCB } from "../interfaces/MongooseSchemaOptions";
|
|
3
3
|
/**
|
|
4
4
|
* We can simply attach a `@PostHook` decorator to your model class and
|
|
5
5
|
* define the hook function like you normally would in Mongoose.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SchemaTypeOptions } from "mongoose";
|
|
2
|
-
import { MongooseSchemaOptions } from "../interfaces";
|
|
2
|
+
import { MongooseSchemaOptions } from "../interfaces/MongooseSchemaOptions";
|
|
3
3
|
/**
|
|
4
4
|
* Define a class as a Mongoose Schema ready to be used to compose other schemes and models.
|
|
5
5
|
*
|
|
@@ -9,10 +9,6 @@ import { MongooseVirtualRefOptions } from "../interfaces/MongooseVirtualRefOptio
|
|
|
9
9
|
* import in node.
|
|
10
10
|
* :::
|
|
11
11
|
*
|
|
12
|
-
* ### Example
|
|
13
|
-
*
|
|
14
|
-
* <<< @/tutorials/snippets/mongoose/virtual-references.ts
|
|
15
|
-
*
|
|
16
12
|
* @param ref
|
|
17
13
|
* @param foreignField
|
|
18
14
|
* @returns {Function}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
4
|
export * from "./MongooseModule";
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./decorators";
|
|
5
|
+
export * from "./constants/constants";
|
|
6
|
+
export * from "./decorators/auto";
|
|
7
|
+
export * from "./decorators/discriminatorKey";
|
|
8
|
+
export * from "./decorators/dynamicRef";
|
|
9
|
+
export * from "./decorators/excludeIndexes";
|
|
10
|
+
export * from "./decorators/expires";
|
|
11
|
+
export * from "./decorators/immutable";
|
|
12
|
+
export * from "./decorators/indexed";
|
|
13
|
+
export * from "./decorators/lowercase";
|
|
14
|
+
export * from "./decorators/model";
|
|
15
|
+
export * from "./decorators/mongooseIndex";
|
|
16
|
+
export * from "./decorators/mongooseIndexes";
|
|
17
|
+
export * from "./decorators/mongoosePlugin";
|
|
18
|
+
export * from "./decorators/numberDecimal";
|
|
19
|
+
export * from "./decorators/objectID";
|
|
20
|
+
export * from "./decorators/postHook";
|
|
21
|
+
export * from "./decorators/preHook";
|
|
22
|
+
export * from "./decorators/ref";
|
|
23
|
+
export * from "./decorators/schema";
|
|
24
|
+
export * from "./decorators/schemaIgnore";
|
|
25
|
+
export * from "./decorators/select";
|
|
26
|
+
export * from "./decorators/sparse";
|
|
27
|
+
export * from "./decorators/text";
|
|
28
|
+
export * from "./decorators/trim";
|
|
29
|
+
export * from "./decorators/unique";
|
|
30
|
+
export * from "./decorators/uppercase";
|
|
31
|
+
export * from "./decorators/versionKey";
|
|
32
|
+
export * from "./decorators/virtualRef";
|
|
33
|
+
export * from "./interfaces/MongooseConnectionOptions";
|
|
34
|
+
export * from "./interfaces/MongooseDocument";
|
|
35
|
+
export * from "./interfaces/MongooseModel";
|
|
36
|
+
export * from "./interfaces/MongooseModelOptions";
|
|
37
|
+
export * from "./interfaces/MongooseSchemaOptions";
|
|
38
|
+
export * from "./interfaces/MongooseSchemaTypes";
|
|
39
|
+
export * from "./interfaces/MongooseVirtualRefOptions";
|
|
40
|
+
export * from "./interfaces/interfaces";
|
|
41
|
+
export * from "./registries/MongooseModels";
|
|
42
|
+
export * from "./services/MongooseConnections";
|
|
43
|
+
export * from "./services/MongooseService";
|
|
44
|
+
export * from "./utils/createModel";
|
|
45
|
+
export * from "./utils/createSchema";
|
|
46
|
+
export * from "./utils/resolveRefType";
|
|
47
|
+
export * from "./utils/schemaOptions";
|
|
@@ -5,5 +5,4 @@ export declare type MongooseMergedDocument<T> = {
|
|
|
5
5
|
export interface MongooseDocumentMethods<T> {
|
|
6
6
|
toClass(): T;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
}
|
|
8
|
+
export declare type MongooseModel<T> = Model<MongooseMergedDocument<Document & T & MongooseDocumentMethods<T>>>;
|
|
@@ -23,7 +23,7 @@ export interface MongoosePluginOptions {
|
|
|
23
23
|
options?: Record<string, unknown>;
|
|
24
24
|
}
|
|
25
25
|
export interface MongooseIndexOptions {
|
|
26
|
-
fields:
|
|
26
|
+
fields: Record<any, any>;
|
|
27
27
|
options?: Record<string, unknown>;
|
|
28
28
|
}
|
|
29
29
|
export interface MongooseSchemaOptions {
|
|
@@ -6,9 +6,3 @@ declare global {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export * from "./MongooseConnectionOptions";
|
|
10
|
-
export * from "./MongooseDocument";
|
|
11
|
-
export * from "./MongooseModel";
|
|
12
|
-
export * from "./MongooseModelOptions";
|
|
13
|
-
export * from "./MongooseSchemaOptions";
|
|
14
|
-
export * from "./MongooseVirtualRefOptions";
|
|
@@ -11,9 +11,9 @@ export declare function getModelToken(target: Type<any>, options: any): {
|
|
|
11
11
|
* @param {"mongoose".Schema} schema Schema that will be attached to the model.
|
|
12
12
|
* @param name model name
|
|
13
13
|
* @param collection (optional, induced from model name)
|
|
14
|
-
* @param
|
|
14
|
+
* @param overwriteModels
|
|
15
15
|
* @param connection
|
|
16
16
|
* @param discriminatorValue
|
|
17
17
|
* @returns {Model<T extends Document>}
|
|
18
18
|
*/
|
|
19
|
-
export declare function createModel<T>(target: any, schema: mongoose.Schema, name?: string, collection?: string,
|
|
19
|
+
export declare function createModel<T>(target: any, schema: mongoose.Schema, name?: string, collection?: string, overwriteModels?: boolean, connection?: Connection, discriminatorValue?: string): mongoose.Model<any, any, any, any>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
import { JsonEntityStore } from "@tsed/schema";
|
|
3
3
|
import mongoose, { Schema, SchemaDefinition, SchemaTypeOptions } from "mongoose";
|
|
4
|
-
import { MongooseSchemaOptions } from "../interfaces";
|
|
4
|
+
import { MongooseSchemaOptions } from "../interfaces/MongooseSchemaOptions";
|
|
5
5
|
import { MongooseVirtualRefOptions } from "../interfaces/MongooseVirtualRefOptions";
|
|
6
6
|
export interface MongooseSchemaMetadata {
|
|
7
7
|
schema: SchemaDefinition;
|