@joktec/mongo
Version:
JokTec - Mongo Service
37 lines • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Schema = void 0;
const core_1 = require("@joktec/core");
const utils_1 = require("@joktec/utils");
const typegoose_1 = require("@typegoose/typegoose");
const lodash_1 = require("lodash");
const helpers_1 = require("../helpers");
const Schema = (options = {}) => {
return (target) => {
const className = target.name;
const opts = {
...options,
collection: options?.collection || (0, lodash_1.snakeCase)((0, utils_1.toPlural)(className)),
schemaOptions: {
strict: true,
strictQuery: true,
id: true,
minimize: true,
toObject: { virtuals: true },
toJSON: { virtuals: true },
...options?.schemaOptions,
},
customOptions: { allowMixed: typegoose_1.Severity.ALLOW, ...options?.customOptions },
};
const decorators = (0, lodash_1.union)([
(0, core_1.SetMetadata)(className, opts),
(0, typegoose_1.modelOptions)({
schemaOptions: { ...opts.schemaOptions, collection: opts.collection },
options: { ...opts.customOptions },
}),
], (0, helpers_1.buildQueryMethod)(), (0, helpers_1.buildPlugin)(options), (0, helpers_1.buildIndex)(options));
(0, core_1.applyDecorators)(...decorators)(target);
};
};
exports.Schema = Schema;
//# sourceMappingURL=scheme.decorator.js.map