ravendb
Version:
RavenDB client for Node.js
43 lines • 1.41 kB
JavaScript
import { SuggestionWithTerm } from "./SuggestionWithTerm.js";
import { SuggestionWithTerms } from "./SuggestionWithTerms.js";
import { throwError } from "../../../Exceptions/index.js";
import { TypeUtil } from "../../../Utility/TypeUtil.js";
export class SuggestionBuilder {
_term;
_terms;
withDisplayName(displayName) {
this.suggestion.displayField = displayName;
return this;
}
byField(fieldName, termOrTerms) {
if (!fieldName) {
throwError("InvalidArgumentException", "fieldName cannot be null");
}
if (!termOrTerms) {
throwError("InvalidArgumentException", "term cannot be null");
}
if (TypeUtil.isArray(termOrTerms)) {
if (!termOrTerms.length) {
throwError("InvalidArgumentException", "Terms cannot be an empty collection");
}
this._terms = new SuggestionWithTerms(fieldName);
this._terms.terms = termOrTerms;
}
else {
this._term = new SuggestionWithTerm(fieldName);
this._term.term = termOrTerms;
}
return this;
}
withOptions(options) {
this.suggestion.options = options;
return this;
}
get suggestion() {
if (this._term) {
return this._term;
}
return this._terms;
}
}
//# sourceMappingURL=SuggestionBuilder.js.map