@tsed/mongoose 6.69.1 → 6.69.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/.mocharc.js +5 -0
- package/.nycrc +26 -0
- package/lib/index.js +1402 -10
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +1362 -0
- package/lib/index.modern.js.map +1 -0
- package/package.json +19 -18
- package/lib/MongooseModule.js +0 -36
- package/lib/MongooseModule.js.map +0 -1
- package/lib/constants/index.js +0 -24
- package/lib/constants/index.js.map +0 -1
- package/lib/decorators/auto.js +0 -28
- package/lib/decorators/auto.js.map +0 -1
- package/lib/decorators/discriminatorKey.js +0 -12
- package/lib/decorators/discriminatorKey.js.map +0 -1
- package/lib/decorators/dynamicRef.js +0 -46
- package/lib/decorators/dynamicRef.js.map +0 -1
- package/lib/decorators/excludeIndexes.js +0 -28
- package/lib/decorators/excludeIndexes.js.map +0 -1
- package/lib/decorators/expires.js +0 -28
- package/lib/decorators/expires.js.map +0 -1
- package/lib/decorators/immutable.js +0 -30
- package/lib/decorators/immutable.js.map +0 -1
- package/lib/decorators/index.js +0 -30
- package/lib/decorators/index.js.map +0 -1
- package/lib/decorators/indexed.js +0 -26
- package/lib/decorators/indexed.js.map +0 -1
- package/lib/decorators/lowercase.js +0 -28
- package/lib/decorators/lowercase.js.map +0 -1
- package/lib/decorators/model.js +0 -67
- package/lib/decorators/model.js.map +0 -1
- package/lib/decorators/mongooseIndex.js +0 -39
- package/lib/decorators/mongooseIndex.js.map +0 -1
- package/lib/decorators/mongooseIndexes.d.ts +0 -32
- package/lib/decorators/mongooseIndexes.js +0 -39
- package/lib/decorators/mongooseIndexes.js.map +0 -1
- package/lib/decorators/mongoosePlugin.js +0 -22
- package/lib/decorators/mongoosePlugin.js.map +0 -1
- package/lib/decorators/numberDecimal.js +0 -75
- package/lib/decorators/numberDecimal.js.map +0 -1
- package/lib/decorators/objectID.js +0 -26
- package/lib/decorators/objectID.js.map +0 -1
- package/lib/decorators/postHook.js +0 -26
- package/lib/decorators/postHook.js.map +0 -1
- package/lib/decorators/preHook.js +0 -71
- package/lib/decorators/preHook.js.map +0 -1
- package/lib/decorators/ref.js +0 -65
- package/lib/decorators/ref.js.map +0 -1
- package/lib/decorators/schema.js +0 -32
- package/lib/decorators/schema.js.map +0 -1
- package/lib/decorators/schemaIgnore.js +0 -27
- package/lib/decorators/schemaIgnore.js.map +0 -1
- package/lib/decorators/select.js +0 -28
- package/lib/decorators/select.js.map +0 -1
- package/lib/decorators/sparse.js +0 -30
- package/lib/decorators/sparse.js.map +0 -1
- package/lib/decorators/text.js +0 -29
- package/lib/decorators/text.js.map +0 -1
- package/lib/decorators/trim.js +0 -27
- package/lib/decorators/trim.js.map +0 -1
- package/lib/decorators/unique.js +0 -27
- package/lib/decorators/unique.js.map +0 -1
- package/lib/decorators/uppercase.js +0 -28
- package/lib/decorators/uppercase.js.map +0 -1
- package/lib/decorators/versionKey.js +0 -12
- package/lib/decorators/versionKey.js.map +0 -1
- package/lib/decorators/virtualRef.js +0 -36
- package/lib/decorators/virtualRef.js.map +0 -1
- package/lib/interfaces/MongooseConnectionOptions.js +0 -3
- package/lib/interfaces/MongooseConnectionOptions.js.map +0 -1
- package/lib/interfaces/MongooseDocument.js +0 -3
- package/lib/interfaces/MongooseDocument.js.map +0 -1
- package/lib/interfaces/MongooseModel.js +0 -3
- package/lib/interfaces/MongooseModel.js.map +0 -1
- package/lib/interfaces/MongooseModelOptions.js +0 -3
- package/lib/interfaces/MongooseModelOptions.js.map +0 -1
- package/lib/interfaces/MongooseSchemaOptions.js +0 -3
- package/lib/interfaces/MongooseSchemaOptions.js.map +0 -1
- package/lib/interfaces/MongooseSchemaTypes.js +0 -10
- package/lib/interfaces/MongooseSchemaTypes.js.map +0 -1
- package/lib/interfaces/MongooseVirtualRefOptions.js +0 -3
- package/lib/interfaces/MongooseVirtualRefOptions.js.map +0 -1
- package/lib/interfaces/index.js +0 -10
- package/lib/interfaces/index.js.map +0 -1
- package/lib/registries/MongooseModels.js +0 -5
- package/lib/registries/MongooseModels.js.map +0 -1
- package/lib/services/MongooseConnections.js +0 -51
- package/lib/services/MongooseConnections.js.map +0 -1
- package/lib/services/MongooseService.js +0 -73
- package/lib/services/MongooseService.js.map +0 -1
- package/lib/utils/createModel.js +0 -57
- package/lib/utils/createModel.js.map +0 -1
- package/lib/utils/createSchema.js +0 -160
- package/lib/utils/createSchema.js.map +0 -1
- package/lib/utils/index.js +0 -6
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/resolveRefType.js +0 -19
- package/lib/utils/resolveRefType.js.map +0 -1
- package/lib/utils/schemaOptions.js +0 -60
- package/lib/utils/schemaOptions.js.map +0 -1
package/lib/decorators/model.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Model = void 0;
|
|
4
|
-
const di_1 = require("@tsed/di");
|
|
5
|
-
const MongooseConnections_1 = require("../services/MongooseConnections");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
8
|
-
/**
|
|
9
|
-
* Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with
|
|
10
|
-
* `@Inject` annotation.
|
|
11
|
-
*
|
|
12
|
-
* ### Example
|
|
13
|
-
*
|
|
14
|
-
* ```typescript
|
|
15
|
-
* @Model()
|
|
16
|
-
* export class EventModel {
|
|
17
|
-
* @Property()
|
|
18
|
-
* field: string;
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* Then inject the model into a service:
|
|
23
|
-
*
|
|
24
|
-
* ```typescript
|
|
25
|
-
* class MyService {
|
|
26
|
-
* constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {
|
|
27
|
-
* eventModel.findById().exec();
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* ### Options
|
|
33
|
-
*
|
|
34
|
-
* - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.
|
|
35
|
-
* - `name` (String): model name.
|
|
36
|
-
* - `collection` (String): collection (optional, induced from model name).
|
|
37
|
-
* - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).
|
|
38
|
-
*
|
|
39
|
-
* @param {MongooseModelOptions} options
|
|
40
|
-
* @returns {(target: any) => void}
|
|
41
|
-
* @decorator
|
|
42
|
-
* @mongoose
|
|
43
|
-
* @class
|
|
44
|
-
*/
|
|
45
|
-
function Model(options = {}) {
|
|
46
|
-
return (target) => {
|
|
47
|
-
const { token, collectionName } = utils_1.getModelToken(target, options);
|
|
48
|
-
di_1.registerProvider({
|
|
49
|
-
provide: token,
|
|
50
|
-
deps: [],
|
|
51
|
-
useFactory() {
|
|
52
|
-
return utils_1.getSchema(target, options);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
di_1.registerProvider({
|
|
56
|
-
provide: target,
|
|
57
|
-
type: "mongoose:model",
|
|
58
|
-
deps: [MongooseConnections_1.MONGOOSE_CONNECTIONS, token],
|
|
59
|
-
useFactory(connections, schema) {
|
|
60
|
-
schemaOptions_1.applySchemaOptions(schema, schemaOptions_1.schemaOptions(target));
|
|
61
|
-
return utils_1.createModel(target, schema, collectionName, options.collection, options.skipInit, connections.get(options.connection), options.discriminatorValue);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
exports.Model = Model;
|
|
67
|
-
//# sourceMappingURL=model.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/decorators/model.ts"],"names":[],"mappings":";;;AACA,iCAA0C;AAI1C,yEAAqE;AACrE,oCAA+D;AAC/D,0DAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,KAAK,CAAC,UAAgC,EAAE;IACtD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,EAAC,KAAK,EAAE,cAAc,EAAC,GAAG,qBAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE/D,qBAAgB,CAAC;YACf,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,EAAE;YACR,UAAU;gBACR,OAAO,iBAAS,CAAC,MAAM,EAAE,OAAc,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;QAEH,qBAAgB,CAAC;YACf,OAAO,EAAE,MAAM;YACf,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,CAAC,0CAAoB,EAAE,KAAK,CAAC;YACnC,UAAU,CAAC,WAAiC,EAAE,MAAc;gBAC1D,kCAAkB,CAAC,MAAM,EAAE,6BAAa,CAAC,MAAM,CAAC,CAAC,CAAC;gBAClD,OAAO,mBAAW,CAChB,MAAM,EACN,MAAM,EACN,cAAc,EACd,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,QAAQ,EAChB,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EACnC,OAAO,CAAC,kBAAkB,CAC3B,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA9BD,sBA8BC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {Schema} from \"mongoose\";\nimport {MONGOOSE_MODEL} from \"../constants\";\nimport {MongooseModelOptions} from \"../interfaces/MongooseModelOptions\";\nimport {MONGOOSE_CONNECTIONS} from \"../services/MongooseConnections\";\nimport {createModel, getModelToken, getSchema} from \"../utils\";\nimport {applySchemaOptions, schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with\n * `@Inject` annotation.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * Then inject the model into a service:\n *\n * ```typescript\n * class MyService {\n * constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {\n * eventModel.findById().exec();\n * }\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n * - `name` (String): model name.\n * - `collection` (String): collection (optional, induced from model name).\n * - `skipInit` (Boolean): skipInit whether to skip initialization (defaults to false).\n *\n * @param {MongooseModelOptions} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @class\n */\nexport function Model(options: MongooseModelOptions = {}) {\n return (target: any) => {\n const {token, collectionName} = getModelToken(target, options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(target, options as any);\n }\n });\n\n registerProvider({\n provide: target,\n type: \"mongoose:model\",\n deps: [MONGOOSE_CONNECTIONS, token],\n useFactory(connections: MONGOOSE_CONNECTIONS, schema: Schema) {\n applySchemaOptions(schema, schemaOptions(target));\n return createModel(\n target,\n schema,\n collectionName,\n options.collection,\n options.skipInit,\n connections.get(options.connection),\n options.discriminatorValue\n );\n }\n });\n };\n}\n"]}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongooseIndex = void 0;
|
|
4
|
-
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
5
|
-
/**
|
|
6
|
-
* Calls schema.index() to define an index (most likely compound) for the schema.
|
|
7
|
-
*
|
|
8
|
-
* ### Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @Model()
|
|
12
|
-
* @MongooseIndex({first: 1, second: 1}, {unique: 1})
|
|
13
|
-
* export class EventModel {
|
|
14
|
-
*
|
|
15
|
-
* @Property()
|
|
16
|
-
* first: string;
|
|
17
|
-
*
|
|
18
|
-
* @Property()
|
|
19
|
-
* second: string;
|
|
20
|
-
*
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @param fields
|
|
25
|
-
* @param options
|
|
26
|
-
* @returns {Function}
|
|
27
|
-
* @decorator
|
|
28
|
-
* @mongoose
|
|
29
|
-
* @class
|
|
30
|
-
*/
|
|
31
|
-
function MongooseIndex(fields, options) {
|
|
32
|
-
return (target) => {
|
|
33
|
-
schemaOptions_1.schemaOptions(target, {
|
|
34
|
-
indexes: [{ fields, options }]
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
exports.MongooseIndex = MongooseIndex;
|
|
39
|
-
//# sourceMappingURL=mongooseIndex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongooseIndex.js","sourceRoot":"","sources":["../../src/decorators/mongooseIndex.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,aAAa,CAAC,MAAc,EAAE,OAAa;IACzD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,6BAAa,CAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAND,sCAMC","sourcesContent":["import {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Calls schema.index() to define an index (most likely compound) for the schema.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @MongooseIndex({first: 1, second: 1}, {unique: 1})\n * export class EventModel {\n *\n * @Property()\n * first: string;\n *\n * @Property()\n * second: string;\n *\n * }\n * ```\n *\n * @param fields\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongooseIndex(fields: object, options?: any): Function {\n return (target: any) => {\n schemaOptions(target, {\n indexes: [{fields, options}]\n });\n };\n}\n"]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calls schema.index() to define multiple indexes (most likely compound) for the schema.
|
|
3
|
-
*
|
|
4
|
-
* ### Example
|
|
5
|
-
*
|
|
6
|
-
* ```typescript
|
|
7
|
-
* @Model()
|
|
8
|
-
* @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])
|
|
9
|
-
* export class EventModel {
|
|
10
|
-
*
|
|
11
|
-
* @Property()
|
|
12
|
-
* first: string;
|
|
13
|
-
*
|
|
14
|
-
* @Property()
|
|
15
|
-
* second: string;
|
|
16
|
-
*
|
|
17
|
-
* @Property()
|
|
18
|
-
* third: string;
|
|
19
|
-
*
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param indexes - define multiple mongoose indexes
|
|
24
|
-
* @returns {Function}
|
|
25
|
-
* @decorator
|
|
26
|
-
* @mongoose
|
|
27
|
-
* @class
|
|
28
|
-
*/
|
|
29
|
-
export declare function MongooseIndexes(indexes: Array<{
|
|
30
|
-
fields: object;
|
|
31
|
-
options?: any;
|
|
32
|
-
}>): Function;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongooseIndexes = void 0;
|
|
4
|
-
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
5
|
-
/**
|
|
6
|
-
* Calls schema.index() to define multiple indexes (most likely compound) for the schema.
|
|
7
|
-
*
|
|
8
|
-
* ### Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @Model()
|
|
12
|
-
* @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])
|
|
13
|
-
* export class EventModel {
|
|
14
|
-
*
|
|
15
|
-
* @Property()
|
|
16
|
-
* first: string;
|
|
17
|
-
*
|
|
18
|
-
* @Property()
|
|
19
|
-
* second: string;
|
|
20
|
-
*
|
|
21
|
-
* @Property()
|
|
22
|
-
* third: string;
|
|
23
|
-
*
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @param indexes - define multiple mongoose indexes
|
|
28
|
-
* @returns {Function}
|
|
29
|
-
* @decorator
|
|
30
|
-
* @mongoose
|
|
31
|
-
* @class
|
|
32
|
-
*/
|
|
33
|
-
function MongooseIndexes(indexes) {
|
|
34
|
-
return (target) => {
|
|
35
|
-
schemaOptions_1.schemaOptions(target, { indexes });
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
exports.MongooseIndexes = MongooseIndexes;
|
|
39
|
-
//# sourceMappingURL=mongooseIndexes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongooseIndexes.js","sourceRoot":"","sources":["../../src/decorators/mongooseIndexes.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,eAAe,CAAC,OAA+C;IAC7E,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,6BAAa,CAAC,MAAM,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC;AAJD,0CAIC","sourcesContent":["import {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * Calls schema.index() to define multiple indexes (most likely compound) for the schema.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @MongooseIndexes([{fields: {first: 1, second: 1}, options:{unique: 1}}, {fields: {first: 1, third: 1}, options:{unique: 1}}])\n * export class EventModel {\n *\n * @Property()\n * first: string;\n *\n * @Property()\n * second: string;\n *\n * @Property()\n * third: string;\n *\n * }\n * ```\n *\n * @param indexes - define multiple mongoose indexes\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongooseIndexes(indexes: Array<{fields: object; options?: any}>): Function {\n return (target: any) => {\n schemaOptions(target, {indexes});\n };\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongoosePlugin = void 0;
|
|
4
|
-
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {(schema: "mongoose".Schema, options?: any) => void} plugin
|
|
8
|
-
* @param options
|
|
9
|
-
* @returns {Function}
|
|
10
|
-
* @decorator
|
|
11
|
-
* @mongoose
|
|
12
|
-
* @class
|
|
13
|
-
*/
|
|
14
|
-
function MongoosePlugin(plugin, options) {
|
|
15
|
-
return (target) => {
|
|
16
|
-
schemaOptions_1.schemaOptions(target, {
|
|
17
|
-
plugins: [{ plugin, options }]
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
exports.MongoosePlugin = MongoosePlugin;
|
|
22
|
-
//# sourceMappingURL=mongoosePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mongoosePlugin.js","sourceRoot":"","sources":["../../src/decorators/mongoosePlugin.ts"],"names":[],"mappings":";;;AACA,0DAAqD;AAErD;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,MAAwD,EAAE,OAAa;IACpG,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,6BAAa,CAAC,MAAM,EAAE;YACpB,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC;SAC7B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAND,wCAMC","sourcesContent":["import mongoose from \"mongoose\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n *\n * @param {(schema: \"mongoose\".Schema, options?: any) => void} plugin\n * @param options\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function MongoosePlugin(plugin: (schema: mongoose.Schema, options?: any) => void, options?: any): Function {\n return (target: any) => {\n schemaOptions(target, {\n plugins: [{plugin, options}]\n });\n };\n}\n"]}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NumberDecimal = exports.DecimalFormat = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const ajv_1 = require("@tsed/ajv");
|
|
6
|
-
const core_1 = require("@tsed/core");
|
|
7
|
-
const json_mapper_1 = require("@tsed/json-mapper");
|
|
8
|
-
const schema_1 = require("@tsed/schema");
|
|
9
|
-
const mongoose_1 = require("mongoose");
|
|
10
|
-
const constants_1 = require("../constants");
|
|
11
|
-
let DecimalFormat = class DecimalFormat {
|
|
12
|
-
validate(num) {
|
|
13
|
-
return core_1.isString(num) || core_1.isNumber(num);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
DecimalFormat = tslib_1.__decorate([
|
|
17
|
-
ajv_1.Formats("decimal", { type: "number" })
|
|
18
|
-
], DecimalFormat);
|
|
19
|
-
exports.DecimalFormat = DecimalFormat;
|
|
20
|
-
function isDecimal(value) {
|
|
21
|
-
return value && value._bsontype === "Decimal128";
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Tell Mongoose whether to define an Decimal128 property.
|
|
25
|
-
* Will be serialized as `number` with format as `decimal`.
|
|
26
|
-
* ### Example
|
|
27
|
-
*
|
|
28
|
-
* ```typescript
|
|
29
|
-
* @Model()
|
|
30
|
-
* export class PriceModel {
|
|
31
|
-
* @NumberDecimal()
|
|
32
|
-
* price: Decimal128;
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
* Optionally using custom decimal type, such as `Big` from big.js
|
|
36
|
-
* ```typescript
|
|
37
|
-
* @Model()
|
|
38
|
-
* export class PriceModel {
|
|
39
|
-
* @NumberDecimal(Big)
|
|
40
|
-
* price: Big;
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
* @param type Optional decimal type constructor
|
|
44
|
-
* @decorator
|
|
45
|
-
* @mongoose
|
|
46
|
-
* @schema
|
|
47
|
-
*/
|
|
48
|
-
function NumberDecimal(type) {
|
|
49
|
-
const schema = {
|
|
50
|
-
type: mongoose_1.Schema.Types.Decimal128
|
|
51
|
-
};
|
|
52
|
-
if (type) {
|
|
53
|
-
// Define property getter to convert Decimal128 to custom type
|
|
54
|
-
schema.get = (value) => {
|
|
55
|
-
return isDecimal(value) ? new type(value) : value;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return core_1.useDecorators(schema_1.Property(Number), schema_1.Format("decimal"), schema_1.Example(12.34), core_1.StoreMerge(constants_1.MONGOOSE_SCHEMA, schema),
|
|
59
|
-
// Deserialize number value from JSON to Decimal128
|
|
60
|
-
json_mapper_1.OnDeserialize((value) => {
|
|
61
|
-
if (type) {
|
|
62
|
-
return new type(value);
|
|
63
|
-
}
|
|
64
|
-
if (core_1.isString(value)) {
|
|
65
|
-
return mongoose_1.Types.Decimal128.fromString(value);
|
|
66
|
-
}
|
|
67
|
-
return mongoose_1.Types.Decimal128.fromString(`${value}`);
|
|
68
|
-
}),
|
|
69
|
-
// Serialize decimal value to floating point number
|
|
70
|
-
json_mapper_1.OnSerialize((value, ctx) => {
|
|
71
|
-
return value && Number(value);
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
exports.NumberDecimal = NumberDecimal;
|
|
75
|
-
//# sourceMappingURL=numberDecimal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"numberDecimal.js","sourceRoot":"","sources":["../../src/decorators/numberDecimal.ts"],"names":[],"mappings":";;;;AAAA,mCAAkD;AAClD,qCAAyE;AACzE,mDAA6D;AAC7D,yCAAuD;AACvD,uCAA4E;AAC5E,4CAA6C;AAG7C,IAAa,aAAa,GAA1B,MAAa,aAAa;IACxB,QAAQ,CAAC,GAAoB;QAC3B,OAAO,eAAQ,CAAC,GAAG,CAAC,IAAI,eAAQ,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;CACF,CAAA;AAJY,aAAa;IADzB,aAAO,CAAC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC;GACxB,aAAa,CAIzB;AAJY,sCAAa;AAM1B,SAAS,SAAS,CAAC,KAA+B;IAChD,OAAO,KAAK,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,MAAM,MAAM,GAAkC;QAC5C,IAAI,EAAE,iBAAc,CAAC,KAAK,CAAC,UAAU;KACtC,CAAC;IAEF,IAAI,IAAI,EAAE;QACR,8DAA8D;QAC9D,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,EAAE,EAAE;YACrB,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACpD,CAAC,CAAC;KACH;IAED,OAAO,oBAAa,CAClB,iBAAQ,CAAC,MAAM,CAAC,EAChB,eAAM,CAAC,SAAS,CAAC,EACjB,gBAAO,CAAC,KAAK,CAAC,EACd,iBAAU,CAAC,2BAAe,EAAE,MAAM,CAAC;IAEnC,mDAAmD;IACnD,2BAAa,CAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;SACxB;QACD,IAAI,eAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,gBAAK,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SAC3C;QACD,OAAO,gBAAK,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;IAEF,mDAAmD;IACnD,yBAAW,CAAC,CAAC,KAAU,EAAE,GAAG,EAAE,EAAE;QAC9B,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAlCD,sCAkCC","sourcesContent":["import {Formats, FormatsMethods} from \"@tsed/ajv\";\nimport {isNumber, isString, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize} from \"@tsed/json-mapper\";\nimport {Example, Format, Property} from \"@tsed/schema\";\nimport {Types, Schema as MongooseSchema, SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\n\n@Formats(\"decimal\", {type: \"number\"})\nexport class DecimalFormat implements FormatsMethods<string | number> {\n validate(num: string | number): boolean {\n return isString(num) || isNumber(num);\n }\n}\n\nfunction isDecimal(value: undefined | number | any) {\n return value && value._bsontype === \"Decimal128\";\n}\n\n/**\n * Tell Mongoose whether to define an Decimal128 property.\n * Will be serialized as `number` with format as `decimal`.\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal()\n * price: Decimal128;\n * }\n * ```\n * Optionally using custom decimal type, such as `Big` from big.js\n * ```typescript\n * @Model()\n * export class PriceModel {\n * @NumberDecimal(Big)\n * price: Big;\n * }\n * ```\n * @param type Optional decimal type constructor\n * @decorator\n * @mongoose\n * @schema\n */\nexport function NumberDecimal(type?: any) {\n const schema: SchemaTypeOptions<Decimal128> = {\n type: MongooseSchema.Types.Decimal128\n };\n\n if (type) {\n // Define property getter to convert Decimal128 to custom type\n schema.get = (value) => {\n return isDecimal(value) ? new type(value) : value;\n };\n }\n\n return useDecorators(\n Property(Number),\n Format(\"decimal\"),\n Example(12.34),\n StoreMerge(MONGOOSE_SCHEMA, schema),\n\n // Deserialize number value from JSON to Decimal128\n OnDeserialize((value) => {\n if (type) {\n return new type(value);\n }\n if (isString(value)) {\n return Types.Decimal128.fromString(value);\n }\n return Types.Decimal128.fromString(`${value}`);\n }),\n\n // Serialize decimal value to floating point number\n OnSerialize((value: any, ctx) => {\n return value && Number(value);\n })\n );\n}\n\nexport type Decimal128 = Types.Decimal128;\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObjectID = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
5
|
-
const schema_1 = require("@tsed/schema");
|
|
6
|
-
/**
|
|
7
|
-
* Tell Mongoose whether to define an ObjectId property.
|
|
8
|
-
* ### Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @Model()
|
|
12
|
-
* export class EventModel {
|
|
13
|
-
* @ObjectId('id')
|
|
14
|
-
* _id: string;
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
* @param name
|
|
18
|
-
* @decorator
|
|
19
|
-
* @mongoose
|
|
20
|
-
* @schema
|
|
21
|
-
*/
|
|
22
|
-
function ObjectID(name) {
|
|
23
|
-
return core_1.useDecorators(name && schema_1.Name(name), schema_1.Pattern(/^[0-9a-fA-F]{24}$/), schema_1.Description("Mongoose ObjectId"), schema_1.Example("5ce7ad3028890bd71749d477"));
|
|
24
|
-
}
|
|
25
|
-
exports.ObjectID = ObjectID;
|
|
26
|
-
//# sourceMappingURL=objectID.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,oBAAa,CAClB,IAAI,IAAI,aAAI,CAAC,IAAI,CAAC,EAClB,gBAAO,CAAC,mBAAmB,CAAC,EAC5B,oBAAW,CAAC,mBAAmB,CAAC,EAChC,gBAAO,CAAC,0BAA0B,CAAC,CACpC,CAAC;AACJ,CAAC;AAPD,4BAOC","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(\n name && Name(name),\n Pattern(/^[0-9a-fA-F]{24}$/),\n Description(\"Mongoose ObjectId\"),\n Example(\"5ce7ad3028890bd71749d477\")\n );\n}\n\nexport type ObjectID = Types.ObjectId;\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostHook = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
5
|
-
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
6
|
-
function PostHook(method, ...params) {
|
|
7
|
-
return ((...args) => {
|
|
8
|
-
let options = params[1];
|
|
9
|
-
let fn = params[0];
|
|
10
|
-
if (core_1.decoratorTypeOf(args) === core_1.DecoratorTypes.METHOD_STC) {
|
|
11
|
-
options = params[0];
|
|
12
|
-
fn = args[0][args[1]].bind(args[0]);
|
|
13
|
-
}
|
|
14
|
-
schemaOptions_1.schemaOptions(args[0], {
|
|
15
|
-
post: [
|
|
16
|
-
{
|
|
17
|
-
method,
|
|
18
|
-
fn,
|
|
19
|
-
options
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
exports.PostHook = PostHook;
|
|
26
|
-
//# sourceMappingURL=postHook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postHook.js","sourceRoot":"","sources":["../../src/decorators/postHook.ts"],"names":[],"mappings":";;;AAAA,qCAAkF;AAElF,0DAAqD;AAgDrD,SAAgB,QAAQ,CAAU,MAAc,EAAE,GAAG,MAAa;IAChE,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,GAAwB,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,EAAE,GAA0B,MAAM,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,sBAAe,CAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACpB,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,6BAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,IAAI,EAAE;gBACJ;oBACE,MAAM;oBACN,EAAE;oBACF,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAQ,CAAC;AACZ,CAAC;AApBD,4BAoBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, StaticMethodDecorator} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePostHookCB} from \"../interfaces\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n * We can simply attach a `@PostHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PostHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PostHook(\"save\", (car: CarModel) => {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * })\n * export class CarModel {\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PostHook(\"save\")\n * static postSave(car: CarModel) {\n * if (car.topSpeedInKmH > 300) {\n * console.log(car.model, 'is fast!');\n * }\n * }\n * }\n * ```\n *\n * This will execute the post-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>): ClassDecorator;\nexport function PostHook<T = any>(method: string, fn: MongoosePostHookCB<T>, options: MongooseHookOptions): ClassDecorator;\nexport function PostHook<T = any>(method: string, options: MongooseHookOptions): StaticMethodDecorator;\nexport function PostHook<T = any>(method: string, ...params: any[]): Function {\n return ((...args: any[]) => {\n let options: MongooseHookOptions = params[1];\n let fn: MongoosePostHookCB<T> = params[0];\n\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = params[0];\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n post: [\n {\n method,\n fn,\n options\n }\n ]\n });\n }) as any;\n}\n"]}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PreHook = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
5
|
-
const schemaOptions_1 = require("../utils/schemaOptions");
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* We can simply attach a `@PreHook` decorator to your model class and
|
|
9
|
-
* define the hook function like you normally would in Mongoose.
|
|
10
|
-
*
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import {Ignore, Required} from "@tsed/common";
|
|
13
|
-
* import {PreHook, Model} from "@tsed/mongoose";
|
|
14
|
-
*
|
|
15
|
-
* @Model()
|
|
16
|
-
* @PreHook("save", (car: CarModel, next) => {
|
|
17
|
-
* if (car.model === 'Tesla') {
|
|
18
|
-
* car.isFast = true;
|
|
19
|
-
* }
|
|
20
|
-
* next();
|
|
21
|
-
*})
|
|
22
|
-
* export class CarModel {
|
|
23
|
-
*
|
|
24
|
-
* @Ignore()
|
|
25
|
-
* _id: string;
|
|
26
|
-
*
|
|
27
|
-
* @Required()
|
|
28
|
-
* model: string;
|
|
29
|
-
*
|
|
30
|
-
* @Required()
|
|
31
|
-
* isFast: boolean;
|
|
32
|
-
*
|
|
33
|
-
* // or Prehook on static method
|
|
34
|
-
* @PreHook("save")
|
|
35
|
-
* static preSave(car: CarModel, next) {
|
|
36
|
-
* if (car.model === 'Tesla') {
|
|
37
|
-
* car.isFast = true;
|
|
38
|
-
* }
|
|
39
|
-
* next();
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* This will execute the pre-save hook each time a `CarModel` document is saved.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} method
|
|
47
|
-
* @param fn
|
|
48
|
-
* @param options
|
|
49
|
-
* @returns {Function}
|
|
50
|
-
* @decorator
|
|
51
|
-
* @class
|
|
52
|
-
*/
|
|
53
|
-
function PreHook(method, fn, options) {
|
|
54
|
-
return (...args) => {
|
|
55
|
-
if (core_1.decoratorTypeOf(args) === core_1.DecoratorTypes.METHOD_STC) {
|
|
56
|
-
options = fn;
|
|
57
|
-
fn = args[0][args[1]].bind(args[0]);
|
|
58
|
-
}
|
|
59
|
-
schemaOptions_1.schemaOptions(args[0], {
|
|
60
|
-
pre: [
|
|
61
|
-
{
|
|
62
|
-
method,
|
|
63
|
-
fn: fn,
|
|
64
|
-
options
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
exports.PreHook = PreHook;
|
|
71
|
-
//# sourceMappingURL=preHook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preHook.js","sourceRoot":"","sources":["../../src/decorators/preHook.ts"],"names":[],"mappings":";;;AAAA,qCAA2D;AAE3D,0DAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,SAAgB,OAAO,CAAU,MAAc,EAAE,EAA+C,EAAE,OAA6B;IAC7H,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,sBAAe,CAAC,IAAI,CAAC,KAAK,qBAAc,CAAC,UAAU,EAAE;YACvD,OAAO,GAAG,EAAyB,CAAC;YACpC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACrC;QAED,6BAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YACrB,GAAG,EAAE;gBACH;oBACE,MAAM;oBACN,EAAE,EAAE,EAA0B;oBAC9B,OAAO;iBACR;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAjBD,0BAiBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes} from \"@tsed/core\";\nimport {MongooseHookOptions, MongoosePreHookCB} from \"../interfaces\";\nimport {schemaOptions} from \"../utils/schemaOptions\";\n\n/**\n *\n * We can simply attach a `@PreHook` decorator to your model class and\n * define the hook function like you normally would in Mongoose.\n *\n * ```typescript\n * import {Ignore, Required} from \"@tsed/common\";\n * import {PreHook, Model} from \"@tsed/mongoose\";\n *\n * @Model()\n * @PreHook(\"save\", (car: CarModel, next) => {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n *})\n * export class CarModel {\n *\n * @Ignore()\n * _id: string;\n *\n * @Required()\n * model: string;\n *\n * @Required()\n * isFast: boolean;\n *\n * // or Prehook on static method\n * @PreHook(\"save\")\n * static preSave(car: CarModel, next) {\n * if (car.model === 'Tesla') {\n * car.isFast = true;\n * }\n * next();\n * }\n * }\n * ```\n *\n * This will execute the pre-save hook each time a `CarModel` document is saved.\n *\n * @param {string} method\n * @param fn\n * @param options\n * @returns {Function}\n * @decorator\n * @class\n */\nexport function PreHook<T = any>(method: string, fn?: MongoosePreHookCB<T> | MongooseHookOptions, options?: MongooseHookOptions): Function {\n return (...args: any[]) => {\n if (decoratorTypeOf(args) === DecoratorTypes.METHOD_STC) {\n options = fn as MongooseHookOptions;\n fn = args[0][args[1]].bind(args[0]);\n }\n\n schemaOptions(args[0], {\n pre: [\n {\n method,\n fn: fn as MongoosePreHookCB<T>,\n options\n }\n ]\n });\n };\n}\n"]}
|
package/lib/decorators/ref.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Ref = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
5
|
-
const json_mapper_1 = require("@tsed/json-mapper");
|
|
6
|
-
const schema_1 = require("@tsed/schema");
|
|
7
|
-
const mongoose_1 = require("mongoose");
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
|
-
const MongooseSchemaTypes_1 = require("../interfaces/MongooseSchemaTypes");
|
|
10
|
-
const MongooseModels_1 = require("../registries/MongooseModels");
|
|
11
|
-
function isRef(value) {
|
|
12
|
-
return (value && value._bsontype) || core_1.isString(value);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Define a property as mongoose reference to other Model (decorated with @Model).
|
|
16
|
-
*
|
|
17
|
-
* ### Example
|
|
18
|
-
*
|
|
19
|
-
* ```typescript
|
|
20
|
-
*
|
|
21
|
-
* @Model()
|
|
22
|
-
* class FooModel {
|
|
23
|
-
*
|
|
24
|
-
* @Ref(Foo2Model)
|
|
25
|
-
* field: Ref<Foo2Model>
|
|
26
|
-
*
|
|
27
|
-
* @Ref(Foo2Model)
|
|
28
|
-
* list: Ref<Foo2Model>[]
|
|
29
|
-
* }
|
|
30
|
-
*
|
|
31
|
-
* @Model()
|
|
32
|
-
* class Foo2Model {
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @param model
|
|
37
|
-
* @param type
|
|
38
|
-
* @returns {Function}
|
|
39
|
-
* @decorator
|
|
40
|
-
* @mongoose
|
|
41
|
-
* @property
|
|
42
|
-
*/
|
|
43
|
-
function Ref(model, type = MongooseSchemaTypes_1.MongooseSchemaTypes.OBJECT_ID) {
|
|
44
|
-
const getType = () => (core_1.isString(model) ? MongooseModels_1.MongooseModels.get(model) : core_1.isArrowFn(model) ? model() : model);
|
|
45
|
-
return core_1.useDecorators(schema_1.Property(Object), core_1.StoreMerge(constants_1.MONGOOSE_SCHEMA, {
|
|
46
|
-
type: mongoose_1.Schema.Types[type],
|
|
47
|
-
ref: model
|
|
48
|
-
}), json_mapper_1.OnDeserialize((value) => {
|
|
49
|
-
if (isRef(value)) {
|
|
50
|
-
return value.toString();
|
|
51
|
-
}
|
|
52
|
-
return value;
|
|
53
|
-
}), json_mapper_1.OnSerialize((value, ctx) => {
|
|
54
|
-
if (isRef(value)) {
|
|
55
|
-
return value.toString();
|
|
56
|
-
}
|
|
57
|
-
const type = getType();
|
|
58
|
-
return json_mapper_1.serialize(value, { ...ctx, type });
|
|
59
|
-
}), schema_1.JsonEntityFn(async (store) => {
|
|
60
|
-
store.itemSchema.oneOf([schema_1.string().example("5ce7ad3028890bd71749d477").description("Mongoose Ref ObjectId"), schema_1.lazyRef(getType)]);
|
|
61
|
-
store.type = Object;
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
exports.Ref = Ref;
|
|
65
|
-
//# sourceMappingURL=ref.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/decorators/ref.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAChF,mDAAwE;AACxE,yCAAqE;AACrE,uCAAkD;AAClD,4CAA6C;AAC7C,2EAAsE;AACtE,iEAA4D;AAE5D,SAAS,KAAK,CAAC,KAA+B;IAC5C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,eAAQ,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,GAAG,CAAC,KAAkC,EAAE,OAA4B,yCAAmB,CAAC,SAAS;IAC/G,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,eAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,+BAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAEzG,OAAO,oBAAa,CAClB,iBAAQ,CAAC,MAAM,CAAC,EAChB,iBAAU,CAAC,2BAAe,EAAE;QAC1B,IAAI,EAAE,iBAAc,CAAC,KAAK,CAAC,IAAI,CAAC;QAChC,GAAG,EAAE,KAAK;KACX,CAAC,EACF,2BAAa,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,yBAAW,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,uBAAS,CAAC,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,EACF,qBAAY,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC3B,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,eAAM,EAAE,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,gBAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAE9H,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC;IACtB,CAAC,CAAC,CACkB,CAAC;AACzB,CAAC;AA9BD,kBA8BC","sourcesContent":["import {isArrowFn, isString, StoreMerge, Type, useDecorators} from \"@tsed/core\";\nimport {OnDeserialize, OnSerialize, serialize} from \"@tsed/json-mapper\";\nimport {JsonEntityFn, lazyRef, Property, string} from \"@tsed/schema\";\nimport {Schema as MongooseSchema} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\nimport {MongooseSchemaTypes} from \"../interfaces/MongooseSchemaTypes\";\nimport {MongooseModels} from \"../registries/MongooseModels\";\n\nfunction isRef(value: undefined | string | any) {\n return (value && value._bsontype) || isString(value);\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 type\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Ref(model: string | (() => Type) | any, type: MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID): PropertyDecorator {\n const getType = () => (isString(model) ? MongooseModels.get(model) : isArrowFn(model) ? model() : model);\n\n return useDecorators(\n Property(Object),\n StoreMerge(MONGOOSE_SCHEMA, {\n type: MongooseSchema.Types[type],\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 JsonEntityFn(async (store) => {\n store.itemSchema.oneOf([string().example(\"5ce7ad3028890bd71749d477\").description(\"Mongoose Ref ObjectId\"), lazyRef(getType)]);\n\n store.type = Object;\n })\n ) as PropertyDecorator;\n}\n\nexport type Ref<T> = T | string;\n"]}
|
package/lib/decorators/schema.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongooseSchema = exports.Schema = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
5
|
-
const di_1 = require("@tsed/di");
|
|
6
|
-
const schema_1 = require("@tsed/schema");
|
|
7
|
-
const constants_1 = require("../constants");
|
|
8
|
-
const createSchema_1 = require("../utils/createSchema");
|
|
9
|
-
function Schema(options = {}) {
|
|
10
|
-
return (...parameters) => {
|
|
11
|
-
switch (core_1.decoratorTypeOf(parameters)) {
|
|
12
|
-
case "property":
|
|
13
|
-
return core_1.useDecorators(schema_1.Property(), core_1.StoreMerge(constants_1.MONGOOSE_SCHEMA, options))(parameters[0], parameters[1], parameters[2]);
|
|
14
|
-
case "class":
|
|
15
|
-
const { token } = createSchema_1.getSchemaToken(parameters[0], options);
|
|
16
|
-
di_1.registerProvider({
|
|
17
|
-
provide: token,
|
|
18
|
-
deps: [],
|
|
19
|
-
useFactory() {
|
|
20
|
-
return createSchema_1.getSchema(parameters[0], options);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
exports.Schema = Schema;
|
|
28
|
-
function MongooseSchema(options = {}) {
|
|
29
|
-
return Schema(options);
|
|
30
|
-
}
|
|
31
|
-
exports.MongooseSchema = MongooseSchema;
|
|
32
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/decorators/schema.ts"],"names":[],"mappings":";;;AAAA,qCAAsE;AACtE,iCAA0C;AAC1C,yCAAsC;AAEtC,4CAA6C;AAE7C,wDAAgE;AA4BhE,SAAgB,MAAM,CAAC,UAA0D,EAAE;IACjF,OAAO,CAAC,GAAG,UAAiB,EAAE,EAAE;QAC9B,QAAQ,sBAAe,CAAC,UAAU,CAAC,EAAE;YACnC,KAAK,UAAU;gBACb,OAAO,oBAAa,CAAC,iBAAQ,EAAE,EAAE,iBAAU,CAAC,2BAAe,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtH,KAAK,OAAO;gBACV,MAAM,EAAC,KAAK,EAAC,GAAG,6BAAc,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBAEvD,qBAAgB,CAAC;oBACf,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,EAAE;oBACR,UAAU;wBACR,OAAO,wBAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAc,CAAC,CAAC;oBAClD,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;SACT;IACH,CAAC,CAAC;AACJ,CAAC;AAnBD,wBAmBC;AA4BD,SAAgB,cAAc,CAAC,UAA0D,EAAE;IACzF,OAAO,MAAM,CAAC,OAAc,CAAC,CAAC;AAChC,CAAC;AAFD,wCAEC","sourcesContent":["import {decoratorTypeOf, StoreMerge, useDecorators} from \"@tsed/core\";\nimport {registerProvider} from \"@tsed/di\";\nimport {Property} from \"@tsed/schema\";\nimport {SchemaTypeOptions} from \"mongoose\";\nimport {MONGOOSE_SCHEMA} from \"../constants\";\nimport {MongooseSchemaOptions} from \"../interfaces\";\nimport {getSchema, getSchemaToken} from \"../utils/createSchema\";\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function Schema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function Schema(definition: SchemaTypeOptions<any>): Function;\nexport function Schema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return (...parameters: any[]) => {\n switch (decoratorTypeOf(parameters)) {\n case \"property\":\n return useDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(parameters[0], parameters[1], parameters[2]);\n\n case \"class\":\n const {token} = getSchemaToken(parameters[0], options);\n\n registerProvider({\n provide: token,\n deps: [],\n useFactory() {\n return getSchema(parameters[0], options as any);\n }\n });\n break;\n }\n };\n}\n\n/**\n * Define a class as a Mongoose Schema ready to be used to compose other schemes and models.\n *\n * ### Example\n *\n * ```typescript\n * @MongooseSchema()\n * export class EventSchema {\n * @Property()\n * field: string;\n * }\n * ```\n *\n * ### Options\n *\n * - `schemaOptions` (mongoose.SchemaOptions): Option to configure the schema behavior.\n *\n * @param {MongooseSchemaOptions | undefined} options\n * @returns {(target: any) => void}\n * @decorator\n * @mongoose\n * @property\n * @class\n */\nexport function MongooseSchema(options?: MongooseSchemaOptions): (target: any) => void;\nexport function MongooseSchema(definition: SchemaTypeOptions<any>): Function;\nexport function MongooseSchema(options: MongooseSchemaOptions | SchemaTypeOptions<any> = {}) {\n return Schema(options as any);\n}\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaIgnore = void 0;
|
|
4
|
-
const schema_1 = require("./schema");
|
|
5
|
-
/**
|
|
6
|
-
* Do not apply this property to schema (create virtual property)
|
|
7
|
-
*
|
|
8
|
-
* ### Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @Model()
|
|
12
|
-
* @SchemaIgnore()
|
|
13
|
-
* @Property()
|
|
14
|
-
* kind: string;
|
|
15
|
-
*
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @returns {Function}
|
|
19
|
-
* @decorator
|
|
20
|
-
* @mongoose
|
|
21
|
-
* @class
|
|
22
|
-
*/
|
|
23
|
-
function SchemaIgnore() {
|
|
24
|
-
return schema_1.MongooseSchema({ schemaIgnore: true });
|
|
25
|
-
}
|
|
26
|
-
exports.SchemaIgnore = SchemaIgnore;
|
|
27
|
-
//# sourceMappingURL=schemaIgnore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schemaIgnore.js","sourceRoot":"","sources":["../../src/decorators/schemaIgnore.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AAEH,SAAgB,YAAY;IAC1B,OAAO,uBAAc,CAAC,EAAC,YAAY,EAAE,IAAI,EAAQ,CAAC,CAAC;AACrD,CAAC;AAFD,oCAEC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Do not apply this property to schema (create virtual property)\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * @SchemaIgnore()\n * @Property()\n * kind: string;\n *\n * ```\n *\n * @returns {Function}\n * @decorator\n * @mongoose\n * @class\n */\n\nexport function SchemaIgnore(): Function {\n return MongooseSchema({schemaIgnore: true} as any);\n}\n"]}
|
package/lib/decorators/select.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Select = void 0;
|
|
4
|
-
const schema_1 = require("./schema");
|
|
5
|
-
/**
|
|
6
|
-
* Tell Mongoose to set default select() behavior for this path.
|
|
7
|
-
*
|
|
8
|
-
* ### Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @Model()
|
|
12
|
-
* export class EventModel {
|
|
13
|
-
* @Select()
|
|
14
|
-
* field: string;
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @param {boolean | any} select
|
|
19
|
-
* @returns {Function}
|
|
20
|
-
* @decorator
|
|
21
|
-
* @mongoose
|
|
22
|
-
* @property
|
|
23
|
-
*/
|
|
24
|
-
function Select(select = true) {
|
|
25
|
-
return schema_1.MongooseSchema({ select });
|
|
26
|
-
}
|
|
27
|
-
exports.Select = Select;
|
|
28
|
-
//# sourceMappingURL=select.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/decorators/select.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,MAAM,CAAC,SAAwB,IAAI;IACjD,OAAO,uBAAc,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","sourcesContent":["import {MongooseSchema} from \"./schema\";\n\n/**\n * Tell Mongoose to set default select() behavior for this path.\n *\n * ### Example\n *\n * ```typescript\n * @Model()\n * export class EventModel {\n * @Select()\n * field: string;\n * }\n * ```\n *\n * @param {boolean | any} select\n * @returns {Function}\n * @decorator\n * @mongoose\n * @property\n */\nexport function Select(select: boolean | any = true) {\n return MongooseSchema({select});\n}\n"]}
|