@tsed/mongoose 6.97.2 → 7.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/decorators/virtualRef.js +3 -3
- package/lib/cjs/decorators/virtualRef.js.map +1 -1
- package/lib/cjs/interfaces/MongooseVirtualRefOptions.js.map +1 -1
- package/lib/esm/decorators/virtualRef.js +3 -3
- package/lib/esm/decorators/virtualRef.js.map +1 -1
- package/lib/esm/interfaces/MongooseVirtualRefOptions.js.map +1 -1
- package/lib/types/decorators/virtualRef.d.ts +2 -2
- package/lib/types/interfaces/MongooseVirtualRefOptions.d.ts +0 -4
- package/package.json +12 -12
|
@@ -6,15 +6,15 @@ const schema_1 = require("@tsed/schema");
|
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
7
|
const MongooseModels_1 = require("../registries/MongooseModels");
|
|
8
8
|
function getRef(opts) {
|
|
9
|
-
const ref = opts.ref
|
|
9
|
+
const ref = opts.ref;
|
|
10
10
|
return (0, core_1.isString)(ref) ? ref : core_1.Store.from(ref).get(constants_1.MONGOOSE_MODEL_NAME);
|
|
11
11
|
}
|
|
12
12
|
function getType(opts) {
|
|
13
|
-
const ref = opts.ref
|
|
13
|
+
const ref = opts.ref;
|
|
14
14
|
return !(0, core_1.isString)(ref) ? ref : MongooseModels_1.MongooseModels.get(ref) || (() => MongooseModels_1.MongooseModels.get(ref) || Object);
|
|
15
15
|
}
|
|
16
16
|
function getInitialOpts(options, foreignField) {
|
|
17
|
-
return (0, core_1.isPlainObject)(options) ? options : {
|
|
17
|
+
return (0, core_1.isPlainObject)(options) ? options : { ref: options, foreignField };
|
|
18
18
|
}
|
|
19
19
|
function mapToSchema(opts) {
|
|
20
20
|
const ref = getRef(opts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[],"mappings":";;;AAAA,qCAAqF;AACrF,yC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AI,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;AA0BD,SAAgB,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,IAAA,oBAAa,EAClB,IAAA,iBAAU,EAAC,2BAAe,EAAE,MAAM,CAAC,EACnC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,iBAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC,CACjG,CAAC;AACJ,CAAC;AATD,gCASC","sourcesContent":["import {isPlainObject, isString, Store, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {CollectionOf, Property} from \"@tsed/schema\";\nimport {MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA} from \"../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 * ### Example\n *\n * <<< @/tutorials/snippets/mongoose/virtual-references.ts\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongooseVirtualRefOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseVirtualRefOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\n\nexport interface MongooseVirtualRefOptions {\n
|
|
1
|
+
{"version":3,"file":"MongooseVirtualRefOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseVirtualRefOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\n\nexport interface MongooseVirtualRefOptions {\n ref?: string | Type<any> | (() => Type<any>);\n foreignField?: string;\n localField?: string;\n justOne?: boolean;\n count?: boolean;\n options?: object;\n}\n"]}
|
|
@@ -3,15 +3,15 @@ import { CollectionOf, Property } from "@tsed/schema";
|
|
|
3
3
|
import { MONGOOSE_MODEL_NAME, MONGOOSE_SCHEMA } from "../constants";
|
|
4
4
|
import { MongooseModels } from "../registries/MongooseModels";
|
|
5
5
|
function getRef(opts) {
|
|
6
|
-
const ref = opts.ref
|
|
6
|
+
const ref = opts.ref;
|
|
7
7
|
return isString(ref) ? ref : Store.from(ref).get(MONGOOSE_MODEL_NAME);
|
|
8
8
|
}
|
|
9
9
|
function getType(opts) {
|
|
10
|
-
const ref = opts.ref
|
|
10
|
+
const ref = opts.ref;
|
|
11
11
|
return !isString(ref) ? ref : MongooseModels.get(ref) || (() => MongooseModels.get(ref) || Object);
|
|
12
12
|
}
|
|
13
13
|
function getInitialOpts(options, foreignField) {
|
|
14
|
-
return isPlainObject(options) ? options : {
|
|
14
|
+
return isPlainObject(options) ? options : { ref: options, foreignField };
|
|
15
15
|
}
|
|
16
16
|
function mapToSchema(opts) {
|
|
17
17
|
const ref = getRef(opts);
|
|
@@ -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,cAAc,CAAC;AAElE,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAE5D,SAAS,MAAM,CAAC,IAAS;IACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"virtualRef.js","sourceRoot":"","sources":["../../../src/decorators/virtualRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,QA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AK,EAAE,IAAI,CAAC,KAAK,IAAI,KAAK;QAC1B,OAAO,EAAE,IAAI,CAAC,OAAO;KACtB,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AA0BD,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\";\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 * ### Example\n *\n * <<< @/tutorials/snippets/mongoose/virtual-references.ts\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongooseVirtualRefOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseVirtualRefOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\n\nexport interface MongooseVirtualRefOptions {\n
|
|
1
|
+
{"version":3,"file":"MongooseVirtualRefOptions.js","sourceRoot":"","sources":["../../../src/interfaces/MongooseVirtualRefOptions.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\n\nexport interface MongooseVirtualRefOptions {\n ref?: string | Type<any> | (() => Type<any>);\n foreignField?: string;\n localField?: string;\n justOne?: boolean;\n count?: boolean;\n options?: object;\n}\n"]}
|
|
@@ -13,14 +13,14 @@ import { MongooseVirtualRefOptions } from "../interfaces/MongooseVirtualRefOptio
|
|
|
13
13
|
*
|
|
14
14
|
* <<< @/tutorials/snippets/mongoose/virtual-references.ts
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
16
|
+
* @param ref
|
|
17
17
|
* @param foreignField
|
|
18
18
|
* @returns {Function}
|
|
19
19
|
* @decorator
|
|
20
20
|
* @mongoose
|
|
21
21
|
* @property
|
|
22
22
|
*/
|
|
23
|
-
export declare function VirtualRef(
|
|
23
|
+
export declare function VirtualRef(ref: string, foreignField: string): Function;
|
|
24
24
|
export declare function VirtualRef(options: MongooseVirtualRefOptions): Function;
|
|
25
25
|
export declare function VirtualRef(options: string | MongooseVirtualRefOptions, foreignField?: string): Function;
|
|
26
26
|
export declare type VirtualRef<T> = T | null;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
export interface MongooseVirtualRefOptions {
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Since v6. Use ref instead.
|
|
5
|
-
*/
|
|
6
|
-
type?: string | Type<any> | (() => Type<any>);
|
|
7
3
|
ref?: string | Type<any> | (() => Type<any>);
|
|
8
4
|
foreignField?: string;
|
|
9
5
|
localField?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/mongoose",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-beta.2",
|
|
4
4
|
"description": "Mongoose package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -30,28 +30,28 @@
|
|
|
30
30
|
"tslib": "2.2.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@tsed/ajv": "
|
|
34
|
-
"@tsed/core": "
|
|
35
|
-
"@tsed/di": "
|
|
36
|
-
"@tsed/json-mapper": "
|
|
33
|
+
"@tsed/ajv": "7.0.0-beta.2",
|
|
34
|
+
"@tsed/core": "7.0.0-beta.2",
|
|
35
|
+
"@tsed/di": "7.0.0-beta.2",
|
|
36
|
+
"@tsed/json-mapper": "7.0.0-beta.2",
|
|
37
37
|
"@tsed/logger": "^6.0.0",
|
|
38
|
-
"@tsed/schema": "
|
|
38
|
+
"@tsed/schema": "7.0.0-beta.2",
|
|
39
39
|
"mongoose": "^5.12.2"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@tsed/ajv": "^
|
|
43
|
-
"@tsed/core": "^
|
|
44
|
-
"@tsed/di": "^
|
|
45
|
-
"@tsed/json-mapper": "^
|
|
42
|
+
"@tsed/ajv": "^7.0.0-beta.2",
|
|
43
|
+
"@tsed/core": "^7.0.0-beta.2",
|
|
44
|
+
"@tsed/di": "^7.0.0-beta.2",
|
|
45
|
+
"@tsed/json-mapper": "^7.0.0-beta.2",
|
|
46
46
|
"@tsed/logger": ">=6.0.0",
|
|
47
|
-
"@tsed/schema": "^
|
|
47
|
+
"@tsed/schema": "^7.0.0-beta.2",
|
|
48
48
|
"mongoose": ">=5.12.2"
|
|
49
49
|
},
|
|
50
50
|
"repository": "https://github.com/tsedio/tsed",
|
|
51
51
|
"bugs": {
|
|
52
52
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
53
53
|
},
|
|
54
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
54
|
+
"homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/orm/mongoose",
|
|
55
55
|
"author": "Romain Lenzotti",
|
|
56
56
|
"license": "MIT"
|
|
57
57
|
}
|