UNPKG

@typegoose/typegoose

Version:

Define Mongoose models using TypeScript classes

28 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SearchIndex = exports.searchIndex = void 0; const constants_1 = require("./internal/constants"); const utils_1 = require("./internal/utils"); const logSettings_1 = require("./logSettings"); /** * Defines a search index for this Class which will then be added to the Schema. * * @param description - The description of the search index to add. * @example Example: * ```ts * @searchIndex({ name: 'descriptionIndex', definition: { mappings: { dynamic: true }}}) * class ClassName {} * ``` * @remarks Search indices are only supported when connected to MongoDB Atlas. */ function searchIndex(description) { return (target) => { logSettings_1.logger.info('Adding "%o" Search Indexes to %s', description, (0, utils_1.getName)(target)); const searchIndices = Array.from(Reflect.getOwnMetadata(constants_1.DecoratorKeys.SearchIndex, target) ?? []); searchIndices.push(description); Reflect.defineMetadata(constants_1.DecoratorKeys.SearchIndex, searchIndices, target); }; } exports.searchIndex = searchIndex; exports.SearchIndex = searchIndex; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VhcmNoSW5kZXhlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9zZWFyY2hJbmRleGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLG9EQUFxRDtBQUNyRCw0Q0FBMkM7QUFDM0MsK0NBQXVDO0FBR3ZDOzs7Ozs7Ozs7O0dBVUc7QUFDSCxTQUFnQixXQUFXLENBQUMsV0FBbUM7SUFDN0QsT0FBTyxDQUFDLE1BQVcsRUFBRSxFQUFFO1FBQ3JCLG9CQUFNLENBQUMsSUFBSSxDQUFDLGtDQUFrQyxFQUFFLFdBQVcsRUFBRSxJQUFBLGVBQU8sRUFBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO1FBQzlFLE1BQU0sYUFBYSxHQUE2QixLQUFLLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxjQUFjLENBQUMseUJBQWEsQ0FBQyxXQUFXLEVBQUUsTUFBTSxDQUFDLElBQUksRUFBRSxDQUFDLENBQUM7UUFDNUgsYUFBYSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUNoQyxPQUFPLENBQUMsY0FBYyxDQUFDLHlCQUFhLENBQUMsV0FBVyxFQUFFLGFBQWEsRUFBRSxNQUFNLENBQUMsQ0FBQztJQUMzRSxDQUFDLENBQUM7QUFDSixDQUFDO0FBUEQsa0NBT0M7QUFHdUIsa0NBQVcifQ==