@tsed/mongoose 7.12.0 → 7.13.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.
|
@@ -31,7 +31,8 @@ function createModel(target, schema, name = (0, core_1.nameOf)(target), collecti
|
|
|
31
31
|
if (entity.isDiscriminatorChild) {
|
|
32
32
|
const discriminatorName = entity.discriminatorAncestor.schema.discriminator().getDefaultValue(target);
|
|
33
33
|
const ancestorModel = entity.discriminatorAncestor.get(constants_1.MONGOOSE_MODEL);
|
|
34
|
-
|
|
34
|
+
// check if discriminator is already registered on model before creating it
|
|
35
|
+
return ancestorModel.discriminators?.[discriminatorName] || ancestorModel.discriminator(discriminatorName, schema);
|
|
35
36
|
}
|
|
36
37
|
const opts = overwriteModels ? { overwriteModels } : undefined;
|
|
37
38
|
const c = connection || mongoose_1.default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createModel.js","sourceRoot":"","sources":["../../../src/utils/createModel.ts"],"names":[],"mappings":";;;;AAAA,qCAA+C;AAC/C,yCAA6C;AAC7C,gEAA8C;AAC9C,sDAA2E;AAC3E,iEAA4D;AAC5D,iDAA8C;AAE9C,SAAgB,aAAa,CAAC,MAAiB,EAAE,OAAY;IAC3D,MAAM,EAAC,cAAc,EAAE,KAAK,EAAC,GAAG,IAAA,6BAAc,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEhE,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,+BAAmB,EAAE,cAAc,CAAC,CAAC;IAC5D,+BAAc,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAE3C,OAAO,EAAC,KAAK,EAAE,cAAc,EAAC,CAAC;AACjC,CAAC;AAPD,sCAOC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CACzB,MAAW,EACX,MAAuB,EACvB,OAAe,IAAA,aAAM,EAAC,MAAM,CAAC,EAC7B,UAAmB,EACnB,e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;QAExE,2EAA2E;QAC3E,OAAO,aAAa,CAAC,cAAc,EAAE,CAAC,iBAAiB,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;KACpH;IAED,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,EAAC,eAAe,EAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,MAAM,CAAC,GAAG,UAAU,IAAI,kBAAQ,CAAC;IAEjC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACtD,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,0BAAc,EAAE,KAAK,CAAC,CAAC;IAE9C,OAAO,KAAK,CAAC;AACf,CAAC;AAzBD,kCAyBC","sourcesContent":["import {nameOf, Store, Type} from \"@tsed/core\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport mongoose, {Connection} from \"mongoose\";\nimport {MONGOOSE_MODEL, MONGOOSE_MODEL_NAME} 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 * @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) {\n const entity = JsonEntityStore.from(target);\n\n if (entity.isDiscriminatorChild) {\n const discriminatorName = entity.discriminatorAncestor!.schema.discriminator().getDefaultValue(target)!;\n const ancestorModel = entity.discriminatorAncestor!.get(MONGOOSE_MODEL);\n\n // check if discriminator is already registered on model before creating it\n return ancestorModel.discriminators?.[discriminatorName] || ancestorModel.discriminator(discriminatorName, schema);\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"]}
|
|
@@ -26,7 +26,8 @@ export function createModel(target, schema, name = nameOf(target), collection, o
|
|
|
26
26
|
if (entity.isDiscriminatorChild) {
|
|
27
27
|
const discriminatorName = entity.discriminatorAncestor.schema.discriminator().getDefaultValue(target);
|
|
28
28
|
const ancestorModel = entity.discriminatorAncestor.get(MONGOOSE_MODEL);
|
|
29
|
-
|
|
29
|
+
// check if discriminator is already registered on model before creating it
|
|
30
|
+
return ancestorModel.discriminators?.[discriminatorName] || ancestorModel.discriminator(discriminatorName, schema);
|
|
30
31
|
}
|
|
31
32
|
const opts = overwriteModels ? { overwriteModels } : undefined;
|
|
32
33
|
const c = connection || mongoose;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createModel.js","sourceRoot":"","sources":["../../../src/utils/createModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAC7C,OAAO,QAAsB,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,wBAAwB,CAAC;AAC3E,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,MAA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IAC5D,cAAc,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAE3C,OAAO,EAAC,KAAK,EAAE,cAAc,EAAC,CAAC;AACjC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CACzB,MAAW,EACX,MAAuB,EACvB,OAAe,MAAM,CAAC,MAAM,CAAC,EAC7B,UAAmB,EACnB,eAAyB,EACzB,UAAuB;IAEvB,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,IAAI,MAAM,CAAC,oBAAoB,EAAE;QAC/B,MAAM,iBAAiB,GAAG,MAAM,CAAC,qBAAsB,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,eAAe,CAAC,MAAM,CAAE,CAAC;QACxG,MAAM,aAAa,GAAG,MAAM,CAAC,qBAAsB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAExE,2EAA2E;QAC3E,OAAO,aAAa,CAAC,cAAc,EAAE,CAAC,iBAAiB,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;KACpH;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 {nameOf, Store, Type} from \"@tsed/core\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport mongoose, {Connection} from \"mongoose\";\nimport {MONGOOSE_MODEL, MONGOOSE_MODEL_NAME} 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 * @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) {\n const entity = JsonEntityStore.from(target);\n\n if (entity.isDiscriminatorChild) {\n const discriminatorName = entity.discriminatorAncestor!.schema.discriminator().getDefaultValue(target)!;\n const ancestorModel = entity.discriminatorAncestor!.get(MONGOOSE_MODEL);\n\n // check if discriminator is already registered on model before creating it\n return ancestorModel.discriminators?.[discriminatorName] || ancestorModel.discriminator(discriminatorName, schema);\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/mongoose",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.1",
|
|
4
4
|
"description": "Mongoose package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -32,21 +32,21 @@
|
|
|
32
32
|
"tslib": "2.4.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tsed/ajv": "7.
|
|
36
|
-
"@tsed/core": "7.
|
|
37
|
-
"@tsed/di": "7.
|
|
38
|
-
"@tsed/json-mapper": "7.
|
|
35
|
+
"@tsed/ajv": "7.13.1",
|
|
36
|
+
"@tsed/core": "7.13.1",
|
|
37
|
+
"@tsed/di": "7.13.1",
|
|
38
|
+
"@tsed/json-mapper": "7.13.1",
|
|
39
39
|
"@tsed/logger": ">=6.2.2",
|
|
40
|
-
"@tsed/schema": "7.
|
|
40
|
+
"@tsed/schema": "7.13.1",
|
|
41
41
|
"mongoose": "6.5.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@tsed/ajv": "^7.
|
|
45
|
-
"@tsed/core": "^7.
|
|
46
|
-
"@tsed/di": "^7.
|
|
47
|
-
"@tsed/json-mapper": "^7.
|
|
44
|
+
"@tsed/ajv": "^7.13.1",
|
|
45
|
+
"@tsed/core": "^7.13.1",
|
|
46
|
+
"@tsed/di": "^7.13.1",
|
|
47
|
+
"@tsed/json-mapper": "^7.13.1",
|
|
48
48
|
"@tsed/logger": ">=6.2.2",
|
|
49
|
-
"@tsed/schema": "^7.
|
|
49
|
+
"@tsed/schema": "^7.13.1",
|
|
50
50
|
"mongoose": ">=6.0.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": "https://github.com/tsedio/tsed",
|