nestjs-meili
Version:
Seamless and declarative integration of [MeiliSearch](https://www.meilisearch.com/) into [NestJS](https://nestjs.com/). Use decorators to configure indexes and inject `MeiliSearch` with type safety and zero boilerplate.
70 lines (69 loc) • 2.81 kB
JavaScript
import "reflect-metadata";
import { MEILI_INDEX_FILTERABLE, MEILI_INDEX_SEARCHABLE, MEILI_INDEX_SORTABLE, MEILI_INDEX, MEILI_INDEX_DISPLAYED, MEILI_INDEX_DISTINCT, MEILI_INDEX_FACETING, MEILI_INDEX_PAGINATION, MEILI_INDEX_RANKING_RULES, MEILI_INDEX_STOP_WORDS, MEILI_INDEX_SYNONYMS, MEILI_PRIMARY_KEY, } from "./watermarks";
export function MeiliIndex(index) {
return (target) => {
Reflect.defineMetadata(MEILI_INDEX, index, target);
};
}
export function Searchable() {
return (target, propertyKey) => {
const searchableProps = Reflect.getMetadata(MEILI_INDEX_SEARCHABLE, target.constructor) || [];
searchableProps.push(propertyKey.toString());
Reflect.defineMetadata(MEILI_INDEX_SEARCHABLE, searchableProps, target.constructor);
};
}
export function Filterable() {
return (target, propertyKey) => {
const filterableProps = Reflect.getMetadata(MEILI_INDEX_FILTERABLE, target.constructor) || [];
filterableProps.push(propertyKey.toString());
Reflect.defineMetadata(MEILI_INDEX_FILTERABLE, filterableProps, target.constructor);
};
}
export function Sortable() {
return (target, propertyKey) => {
const sortableProps = Reflect.getMetadata(MEILI_INDEX_SORTABLE, target.constructor) || [];
sortableProps.push(propertyKey.toString());
Reflect.defineMetadata(MEILI_INDEX_SORTABLE, sortableProps, target.constructor);
};
}
export function RankingRules(rules) {
return (target) => {
Reflect.defineMetadata(MEILI_INDEX_RANKING_RULES, rules, target);
};
}
export function StopWords(words) {
return (target) => {
Reflect.defineMetadata(MEILI_INDEX_STOP_WORDS, words, target);
};
}
export function Synonyms(map) {
return (target) => {
Reflect.defineMetadata(MEILI_INDEX_SYNONYMS, map, target);
};
}
export function Pagination(maxTotalHits) {
return (target) => {
Reflect.defineMetadata(MEILI_INDEX_PAGINATION, maxTotalHits, target);
};
}
export function Faceting(maxValuesPerFacet) {
return (target) => {
Reflect.defineMetadata(MEILI_INDEX_FACETING, maxValuesPerFacet, target);
};
}
export function Displayed() {
return (target, propertyKey) => {
const existing = Reflect.getMetadata(MEILI_INDEX_DISPLAYED, target.constructor) || [];
Reflect.defineMetadata(MEILI_INDEX_DISPLAYED, [...new Set([...existing, propertyKey.toString()])], target.constructor);
};
}
export function Distinct() {
return (target, propertyKey) => {
Reflect.defineMetadata(MEILI_INDEX_DISTINCT, propertyKey.toString(), target.constructor);
};
}
export function PrimaryKey() {
return (target, propertyKey) => {
Reflect.defineMetadata(MEILI_PRIMARY_KEY, propertyKey.toString(), target.constructor);
};
}