@tsed/mongoose 6.116.0 → 6.116.3
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/dynamicRef.js +2 -2
- package/lib/cjs/decorators/dynamicRef.js.map +1 -1
- package/lib/cjs/decorators/objectID.js +1 -1
- package/lib/cjs/decorators/objectID.js.map +1 -1
- package/lib/cjs/decorators/ref.js +1 -1
- package/lib/cjs/decorators/ref.js.map +1 -1
- package/lib/esm/decorators/dynamicRef.js +2 -2
- package/lib/esm/decorators/dynamicRef.js.map +1 -1
- package/lib/esm/decorators/objectID.js +1 -1
- package/lib/esm/decorators/objectID.js.map +1 -1
- package/lib/esm/decorators/ref.js +1 -1
- package/lib/esm/decorators/ref.js.map +1 -1
- package/package.json +11 -11
|
@@ -46,7 +46,7 @@ function getType(refPath, ctx) {
|
|
|
46
46
|
* @property
|
|
47
47
|
*/
|
|
48
48
|
function DynamicRef(refPath, ...types) {
|
|
49
|
-
return (0, core_1.useDecorators)((0, schema_1.Property)(Object), (0, schema_1.Example)("5ce7ad3028890bd71749d477"), (0, schema_1.Description)("
|
|
49
|
+
return (0, core_1.useDecorators)((0, schema_1.Property)(Object), (0, schema_1.Example)("5ce7ad3028890bd71749d477"), (0, schema_1.Description)("A reference ObjectID"), (0, core_1.StoreMerge)(constants_1.MONGOOSE_SCHEMA, {
|
|
50
50
|
type: mongoose_1.Schema.Types.ObjectId,
|
|
51
51
|
refPath
|
|
52
52
|
}), (0, json_mapper_1.OnDeserialize)((value, ctx) => {
|
|
@@ -59,7 +59,7 @@ function DynamicRef(refPath, ...types) {
|
|
|
59
59
|
return value.toString();
|
|
60
60
|
}
|
|
61
61
|
return (0, json_mapper_1.serialize)(value, { ...ctx, type: getType(refPath, ctx) });
|
|
62
|
-
}), (0, schema_1.OneOf)((0, schema_1.string)().example("5ce7ad3028890bd71749d477").description("
|
|
62
|
+
}), (0, schema_1.OneOf)((0, schema_1.string)().example("5ce7ad3028890bd71749d477").description("A reference ObjectID"), ...types));
|
|
63
63
|
}
|
|
64
64
|
exports.DynamicRef = DynamicRef;
|
|
65
65
|
//# sourceMappingURL=dynamicRef.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":";;;AAAA,qCAAyF;AACzF,yCAA4F;AAC5F,uCAAkD;AAClD,sDAAuD;AACvD,mDAAqF;AACrF,iEAA4D;AAE5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,OAAO,CAAC,OAAe,EAAE,GAAoB;IACpD,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,+BAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAW,CAAC,CAAC,IAAI,MAAM,CAAC;AAC3F,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAgB,UAAU,CAAC,OAAe,EAAE,GAAG,KAAkB;IAC/D,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAChB,IAAA,gBAAO,EAAC,0BAA0B,CAAC,EACnC,IAAA,oBAAW,EAAC,
|
|
1
|
+
{"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":";;;AAAA,qCAAyF;AACzF,yCAA4F;AAC5F,uCAAkD;AAClD,sDAAuD;AACvD,mDAAqF;AACrF,iEAA4D;AAE5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,O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AC,WAAW,CAAC,sBAAsB,CAAC,EAAE,GAAG,KAAK,CAAC,CAC7E,CAAC;AACzB,CAAC;AAzBD,gCAyBC","sourcesContent":["import {classOf, isArrowFn, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {Description, Example, JsonHookContext, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {deserialize, OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction getType(refPath: string, ctx: JsonHookContext) {\n return (ctx?.self[refPath] && MongooseModels.get(ctx.self[refPath] as string)) || Object;\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * class FooModel {\n *\n * @DynamicRef('type')\n * field: DynamicRef<OtherFooModel | OtherModel>\n *\n * @Enum(['OtherFooModel', 'OtherModel'])\n * type: string\n * }\n *\n * @Model()\n * class OtherFooModel {\n * }\n *\n * @Model()\n * class OtherModel {\n * }\n * ```\n *\n * @param refPath {String} the path to apply the correct model\n * @param types {Type} the classes to generate the correct json schema\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function DynamicRef(refPath: string, ...types: Type<any>[]): PropertyDecorator {\n return useDecorators(\n Property(Object),\n Example(\"5ce7ad3028890bd71749d477\"),\n Description(\"A reference ObjectID\"),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types.ObjectId,\n refPath\n }),\n OnDeserialize((value, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return deserialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return serialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"A reference ObjectID\"), ...types)\n ) as PropertyDecorator;\n}\n\nexport type DynamicRef<T> = T | string;\n"]}
|
|
@@ -20,7 +20,7 @@ const schema_1 = require("@tsed/schema");
|
|
|
20
20
|
* @schema
|
|
21
21
|
*/
|
|
22
22
|
function ObjectID(name) {
|
|
23
|
-
return (0, core_1.useDecorators)(name && (0, schema_1.Name)(name), (0, schema_1.Pattern)(/^[0-9a-fA-F]{24}$/), (0, schema_1.Description)("
|
|
23
|
+
return (0, core_1.useDecorators)(name && (0, schema_1.Name)(name), (0, schema_1.Pattern)(/^[0-9a-fA-F]{24}$/), (0, schema_1.Description)("An ObjectID"), (0, schema_1.Example)("5ce7ad3028890bd71749d477"));
|
|
24
24
|
}
|
|
25
25
|
exports.ObjectID = ObjectID;
|
|
26
26
|
//# sourceMappingURL=objectID.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectID.js","sourceRoot":"","sources":["../../../src/decorators/objectID.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,yCAAiE;AAGjE;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CAAC,IAAa;IACpC,OAAO,IAAA,oBAAa,
|
|
1
|
+
{"version":3,"file":"objectID.js","sourceRoot":"","sources":["../../../src/decorators/objectID.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,yCAAiE;AAGjE;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CAAC,IAAa;IACpC,OAAO,IAAA,oBAAa,EAAC,IAAI,IAAI,IAAA,aAAI,EAAC,IAAI,CAAC,EAAE,IAAA,gBAAO,EAAC,mBAAmB,CAAC,EAAE,IAAA,oBAAW,EAAC,aAAa,CAAC,EAAE,IAAA,gBAAO,EAAC,0BAA0B,CAAC,CAAC,CAAC;AAC1I,CAAC;AAFD,4BAEC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {Description, Example, Name, Pattern} from \"@tsed/schema\";\nimport {Types} from \"mongoose\";\n\n/**\n * Tell Mongoose whether to define an ObjectId property.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @ObjectId('id')\n * _id: string;\n * }\n * ```\n * @param name\n * @decorator\n * @mongoose\n * @schema\n */\nexport function ObjectID(name?: string) {\n return useDecorators(name && Name(name), Pattern(/^[0-9a-fA-F]{24}$/), Description(\"An ObjectID\"), Example(\"5ce7ad3028890bd71749d477\"));\n}\n\nexport type ObjectID = Types.ObjectId;\n"]}
|
|
@@ -72,7 +72,7 @@ function Ref(model, options = MongooseSchemaTypes_1.MongooseSchemaTypes.OBJECT_I
|
|
|
72
72
|
}
|
|
73
73
|
const type = getType();
|
|
74
74
|
return (0, json_mapper_1.serialize)(value, { ...ctx, type });
|
|
75
|
-
}), (0, schema_1.OneOf)((0, schema_1.string)().example("5ce7ad3028890bd71749d477").description("
|
|
75
|
+
}), (0, schema_1.OneOf)((0, schema_1.string)().example("5ce7ad3028890bd71749d477").description("A reference ObjectID"), (0, schema_1.lazyRef)(getType)), populatedGroups.length && PopulateGroups(populatedGroups));
|
|
76
76
|
}
|
|
77
77
|
exports.Ref = Ref;
|
|
78
78
|
//# sourceMappingURL=ref.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/decorators/ref.ts"],"names":[],"mappings":";;;AAAA,qCAA0F;AAC1F,mDAAwE;AACxE,yCAAwG;AACxG,uCAAkD;AAClD,sDAAuD;AACvD,2EAAsE;AACtE,iEAA4D;AAO5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,cAAc,CAAC,eAAyB;IAC/C,OAAO,IAAA,oBAAa,EAClB,IAAA,sBAAa,EAAC,IAAI,CAAC,EACnB,IAAA,qBAAY,EAAC,CAAC,KAAK,E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,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACvG,GAAG,EAAE,KAAK;KACX,CAAC,EACF,IAAA,2BAAa,EAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,EACF,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QACD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;QAEvB,OAAO,IAAA,uBAAS,EAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,IAAA,cAAK,EAAC,IAAA,eAAM,GAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,sBAAsB,CAAC,EAAE,IAAA,gBAAO,EAAC,OAAO,CAAC,CAAC,EACzG,eAAe,CAAC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,CACrC,CAAC;AACzB,CAAC;AArCD,kBAqCC","sourcesContent":["import {isArrowFn, isObject, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {ForwardGroups, JsonEntityFn, lazyRef, matchGroups, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseSchemaTypes} from \"../interfaces/MongooseSchemaTypes\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\ninterface RefOptions {\n type?: MongooseSchemaTypes;\n populatedGroups?: string[];\n}\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction PopulateGroups(populatedGroups: string[]) {\n return useDecorators(\n ForwardGroups(true),\n JsonEntityFn((store) => {\n store.schema.$hooks.on(\"oneOf\", (obj: any[], givenGroups: string[]) => {\n if (matchGroups(populatedGroups, givenGroups)) {\n return obj.filter((x) => x.type === \"string\"); // keep the object id;\n } else {\n return obj.filter((x) => x.type !== \"string\"); // keep the ref definition\n }\n });\n })\n );\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n *\n * @Model()\n * class FooModel {\n *\n * @Ref(Foo2Model)\n * field: Ref<Foo2Model>\n *\n * @Ref(Foo2Model)\n * list: Ref<Foo2Model>[]\n * }\n *\n * @Model()\n * class Foo2Model {\n * }\n * ```\n *\n * @param model\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Ref(\n model: string | (() => Type) | any,\n options: RefOptions | MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID\n): PropertyDecorator {\n if (!model) {\n throw new Error(\n \"A model is required on `@Ref(model)` decorator. Please give a model or wrap it inside an arrow function if you have a circular reference.\"\n );\n }\n\n const getType = () => (isString(model) ? MongooseModels.get(model) : isArrowFn(model) ? model() : model);\n const populatedGroups = (isObject(options) && options.populatedGroups) || [];\n\n return useDecorators(\n Property(Object),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types[isObject(options) ? options.type || MongooseSchemaTypes.OBJECT_ID : options],\n ref: model\n }),\n OnDeserialize((value) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return value;\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n const type = getType();\n\n return serialize(value, {...ctx, type});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"A reference ObjectID\"), lazyRef(getType)),\n populatedGroups.length && PopulateGroups(populatedGroups)\n ) as PropertyDecorator;\n}\n\nexport type Ref<T> = T | string;\n"]}
|
|
@@ -43,7 +43,7 @@ function getType(refPath, ctx) {
|
|
|
43
43
|
* @property
|
|
44
44
|
*/
|
|
45
45
|
export function DynamicRef(refPath, ...types) {
|
|
46
|
-
return useDecorators(Property(Object), Example("5ce7ad3028890bd71749d477"), Description("
|
|
46
|
+
return useDecorators(Property(Object), Example("5ce7ad3028890bd71749d477"), Description("A reference ObjectID"), StoreMerge(MONGOOSE_SCHEMA, {
|
|
47
47
|
type: MongooseSchema.Types.ObjectId,
|
|
48
48
|
refPath
|
|
49
49
|
}), OnDeserialize((value, ctx) => {
|
|
@@ -56,6 +56,6 @@ export function DynamicRef(refPath, ...types) {
|
|
|
56
56
|
return value.toString();
|
|
57
57
|
}
|
|
58
58
|
return serialize(value, { ...ctx, type: getType(refPath, ctx) });
|
|
59
|
-
}), OneOf(string().example("5ce7ad3028890bd71749d477").description("
|
|
59
|
+
}), OneOf(string().example("5ce7ad3028890bd71749d477").description("A reference ObjectID"), ...types));
|
|
60
60
|
}
|
|
61
61
|
//# sourceMappingURL=dynamicRef.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../src/decorators/dynamicRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,UAAU,EAAQ,aAAa,EAAC,MAAM,YAAY,CAAC;AACzF,OAAO,EAAC,WAAW,EAAE,OAAO,EAAmB,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,UAAU,CAAC;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAE5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KA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cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAW,CAAC,CAAC,IAAI,MAAM,CAAC;AAC3F,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,GAAG,KAAkB;IAC/D,OAAO,aAAa,CAClB,QAAQ,CAAC,MAAM,CAAC,EAChB,OAAO,CAAC,0BAA0B,CAAC,EACnC,WAAW,CAAC,sBAAsB,CAAC,EACnC,UAAU,CAAC,eAAe,EAAE;QAC1B,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ;QACnC,OAAO;KACR,CAAC,EACF,aAAa,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC3B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,WAAW,CAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAC,CAAC,CAAC;IACnE,CAAC,CAAC,EACF,WAAW,CAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,SAAS,CAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAC,CAAC,CAAC;IACjE,CAAC,CAAC,EACF,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,sBAAsB,CAAC,EAAE,GAAG,KAAK,CAAC,CAC7E,CAAC;AACzB,CAAC","sourcesContent":["import {classOf, isArrowFn, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {Description, Example, JsonHookContext, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {deserialize, OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction getType(refPath: string, ctx: JsonHookContext) {\n return (ctx?.self[refPath] && MongooseModels.get(ctx.self[refPath] as string)) || Object;\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * class FooModel {\n *\n * @DynamicRef('type')\n * field: DynamicRef<OtherFooModel | OtherModel>\n *\n * @Enum(['OtherFooModel', 'OtherModel'])\n * type: string\n * }\n *\n * @Model()\n * class OtherFooModel {\n * }\n *\n * @Model()\n * class OtherModel {\n * }\n * ```\n *\n * @param refPath {String} the path to apply the correct model\n * @param types {Type} the classes to generate the correct json schema\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function DynamicRef(refPath: string, ...types: Type<any>[]): PropertyDecorator {\n return useDecorators(\n Property(Object),\n Example(\"5ce7ad3028890bd71749d477\"),\n Description(\"A reference ObjectID\"),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types.ObjectId,\n refPath\n }),\n OnDeserialize((value, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return deserialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return serialize(value, {...ctx, type: getType(refPath, ctx)});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"A reference ObjectID\"), ...types)\n ) as PropertyDecorator;\n}\n\nexport type DynamicRef<T> = T | string;\n"]}
|
|
@@ -17,6 +17,6 @@ import { Description, Example, Name, Pattern } from "@tsed/schema";
|
|
|
17
17
|
* @schema
|
|
18
18
|
*/
|
|
19
19
|
export function ObjectID(name) {
|
|
20
|
-
return useDecorators(name && Name(name), Pattern(/^[0-9a-fA-F]{24}$/), Description("
|
|
20
|
+
return useDecorators(name && Name(name), Pattern(/^[0-9a-fA-F]{24}$/), Description("An ObjectID"), Example("5ce7ad3028890bd71749d477"));
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=objectID.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectID.js","sourceRoot":"","sources":["../../../src/decorators/objectID.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAGjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAa;IACpC,OAAO,aAAa,
|
|
1
|
+
{"version":3,"file":"objectID.js","sourceRoot":"","sources":["../../../src/decorators/objectID.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAGjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAa;IACpC,OAAO,aAAa,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC;AAC1I,CAAC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {Description, Example, Name, Pattern} from \"@tsed/schema\";\nimport {Types} from \"mongoose\";\n\n/**\n * Tell Mongoose whether to define an ObjectId property.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @ObjectId('id')\n * _id: string;\n * }\n * ```\n * @param name\n * @decorator\n * @mongoose\n * @schema\n */\nexport function ObjectID(name?: string) {\n return useDecorators(name && Name(name), Pattern(/^[0-9a-fA-F]{24}$/), Description(\"An ObjectID\"), Example(\"5ce7ad3028890bd71749d477\"));\n}\n\nexport type ObjectID = Types.ObjectId;\n"]}
|
|
@@ -69,6 +69,6 @@ export function Ref(model, options = MongooseSchemaTypes.OBJECT_ID) {
|
|
|
69
69
|
}
|
|
70
70
|
const type = getType();
|
|
71
71
|
return serialize(value, { ...ctx, type });
|
|
72
|
-
}), OneOf(string().example("5ce7ad3028890bd71749d477").description("
|
|
72
|
+
}), OneOf(string().example("5ce7ad3028890bd71749d477").description("A reference ObjectID"), lazyRef(getType)), populatedGroups.length && PopulateGroups(populatedGroups));
|
|
73
73
|
}
|
|
74
74
|
//# sourceMappingURL=ref.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/decorators/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAQ,aAAa,EAAC,MAAM,YAAY,CAAC;AAC1F,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAC,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,cAAc,CAAC;AACxG,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,UAAU,CAAC;AAClD,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAO5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,KAAK,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CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzG,MAAM,eAAe,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAE7E,OAAO,aAAa,CAClB,QAAQ,CAAC,MAAM,CAAC,EAChB,UAAU,CAAC,eAAe,EAAE;QAC1B,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACvG,GAAG,EAAE,KAAK;KACX,CAAC,EACF,aAAa,CAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,EACF,WAAW,CAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;SACzB;QACD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;QAEvB,OAAO,SAAS,CAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,EACzG,eAAe,CAAC,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,CACrC,CAAC;AACzB,CAAC","sourcesContent":["import {isArrowFn, isObject, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {ForwardGroups, JsonEntityFn, lazyRef, matchGroups, OneOf, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants/constants\";\nimport {MongooseSchemaTypes} from \"../interfaces/MongooseSchemaTypes\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\ninterface RefOptions {\n type?: MongooseSchemaTypes;\n populatedGroups?: string[];\n}\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\n}\n\nfunction PopulateGroups(populatedGroups: string[]) {\n return useDecorators(\n ForwardGroups(true),\n JsonEntityFn((store) => {\n store.schema.$hooks.on(\"oneOf\", (obj: any[], givenGroups: string[]) => {\n if (matchGroups(populatedGroups, givenGroups)) {\n return obj.filter((x) => x.type === \"string\"); // keep the object id;\n } else {\n return obj.filter((x) => x.type !== \"string\"); // keep the ref definition\n }\n });\n })\n );\n}\n\n/**\n * Define a property as mongoose reference to other Model (decorated with @Model).\n *\n * ### Example\n *\n * ```typescript\n *\n * @Model()\n * class FooModel {\n *\n * @Ref(Foo2Model)\n * field: Ref<Foo2Model>\n *\n * @Ref(Foo2Model)\n * list: Ref<Foo2Model>[]\n * }\n *\n * @Model()\n * class Foo2Model {\n * }\n * ```\n *\n * @param model\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Ref(\n model: string | (() => Type) | any,\n options: RefOptions | MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID\n): PropertyDecorator {\n if (!model) {\n throw new Error(\n \"A model is required on `@Ref(model)` decorator. Please give a model or wrap it inside an arrow function if you have a circular reference.\"\n );\n }\n\n const getType = () => (isString(model) ? MongooseModels.get(model) : isArrowFn(model) ? model() : model);\n const populatedGroups = (isObject(options) && options.populatedGroups) || [];\n\n return useDecorators(\n Property(Object),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types[isObject(options) ? options.type || MongooseSchemaTypes.OBJECT_ID : options],\n ref: model\n }),\n OnDeserialize((value) => {\n if (isRef(value)) {\n return value.toString();\n }\n\n return value;\n }),\n OnSerialize((value: any, ctx) => {\n if (isRef(value)) {\n return value.toString();\n }\n const type = getType();\n\n return serialize(value, {...ctx, type});\n }),\n OneOf(string().example(\"5ce7ad3028890bd71749d477\").description(\"A reference ObjectID\"), lazyRef(getType)),\n populatedGroups.length && PopulateGroups(populatedGroups)\n ) as PropertyDecorator;\n}\n\nexport type Ref<T> = T | string;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/mongoose",
|
|
3
|
-
"version": "6.116.
|
|
3
|
+
"version": "6.116.3",
|
|
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": "6.116.
|
|
36
|
-
"@tsed/core": "6.116.
|
|
37
|
-
"@tsed/di": "6.116.
|
|
38
|
-
"@tsed/json-mapper": "6.116.
|
|
35
|
+
"@tsed/ajv": "6.116.3",
|
|
36
|
+
"@tsed/core": "6.116.3",
|
|
37
|
+
"@tsed/di": "6.116.3",
|
|
38
|
+
"@tsed/json-mapper": "6.116.3",
|
|
39
39
|
"@tsed/logger": ">=6.1.4",
|
|
40
|
-
"@tsed/schema": "6.116.
|
|
40
|
+
"@tsed/schema": "6.116.3",
|
|
41
41
|
"mongoose": "^6.1.7"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@tsed/ajv": "^6.116.
|
|
45
|
-
"@tsed/core": "^6.116.
|
|
46
|
-
"@tsed/di": "^6.116.
|
|
47
|
-
"@tsed/json-mapper": "^6.116.
|
|
44
|
+
"@tsed/ajv": "^6.116.3",
|
|
45
|
+
"@tsed/core": "^6.116.3",
|
|
46
|
+
"@tsed/di": "^6.116.3",
|
|
47
|
+
"@tsed/json-mapper": "^6.116.3",
|
|
48
48
|
"@tsed/logger": ">=6.1.4",
|
|
49
|
-
"@tsed/schema": "^6.116.
|
|
49
|
+
"@tsed/schema": "^6.116.3",
|
|
50
50
|
"mongoose": ">=6.0.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": "https://github.com/tsedio/tsed",
|