Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private addModifier(modifier: string) {
if (this.currentModifer) {
warn(
// prettier-ignore
`You have called \`${this.currentModifer}()\` after \`${modifier}()\`. Your current query was not modified.`
);
return this;
}
this.commit();
if (this.q === "") {
warn(
`You have called \`${modifier}()\` without calling another method to modify your query first. Try calling \`match()\` first.`
);
return this;
}
this.currentModifer = modifier;
private addModifier(modifier: string) {
if (this.currentModifer) {
warn(
// prettier-ignore
`You have called \`${this.currentModifer}()\` after \`${modifier}()\`. Your current query was not modified.`
);
return this;
}
this.commit();
if (this.q === "") {
warn(
`You have called \`${modifier}()\` without calling another method to modify your query first. Try calling \`match()\` first.`
);
return this;
}
this.currentModifer = modifier;
this.q += ` ${modifier.toUpperCase()} `;
return this;
}
public in(this: SearchQueryBuilder, field?: string) {
const fn = `\`in(${field ? `"${field}"` : ""})\``;
if (!this.hasRange && !this.hasTerms) {
warn(
// prettier-ignore
`${fn} was called with no call to \`match(...)\` or \`from(...)\`/\`to(...)\`. Your query was not modified.`
);
return this;
}
if (field && field !== "*") {
this.q += `${field}: `;
}
return this.commit();
}
public to(this: SearchQueryBuilder, term: any) {
if (this.hasTerms) {
warn(
// prettier-ignore
`\`to(...)\` is not allowed after \`match(...)\` try using \`.from(...).to(...).in(...)\`. Your query was not modified.`
);
return this;
}
this.rangeStack[1] = term;
return this;
}
public from(this: SearchQueryBuilder, term: number | string | Date) {
if (this.hasTerms) {
warn(
// prettier-ignore
`\`from(...)\` is not allowed after \`match(...)\` try using \`.from(...).to(...).in(...)\`. Your query was not modified.`
);
return this;
}
this.rangeStack[0] = term;
return this;
}
private cleanup() {
// end a group if we have started one
if (this.openGroups > 0) {
warn(
// prettier-ignore
`Automatically closing ${this.openGroups} group(s). You can use \`endGroup(...)\` to remove this warning.`
);
while (this.openGroups > 0) {
this.q += ")";
this.openGroups--;
}
}
const oldQ = this.q;
this.q = oldQ.replace(/( AND ?| NOT ?| OR ?)*$/, "");
if (oldQ !== this.q) {
warn(
`\`startGroup(...)\` was called without calling \`endGroup(...)\` first. Your query was not modified.`
warn(
// prettier-ignore
`Automatically closing ${this.openGroups} group(s). You can use \`endGroup(...)\` to remove this warning.`
);
while (this.openGroups > 0) {
this.q += ")";
this.openGroups--;
}
}
const oldQ = this.q;
this.q = oldQ.replace(/( AND ?| NOT ?| OR ?)*$/, "");
if (oldQ !== this.q) {
warn(
`\`startGroup(...)\` was called without calling \`endGroup(...)\` first. Your query was not modified.`
);
}
// clear empty groups
this.q = this.q.replace(/(\(\))*/, "");
}
}
public endGroup(this: SearchQueryBuilder) {
if (this.openGroups <= 0) {
warn(
`\`endGroup(...)\` was called without calling \`startGroup(...)\` first. Your query was not modified.`
);
return this;
}
this.openGroups--;
this.q += ")";
return this.commit();
}
export function serviceInfo(
requestOptions?: IEndpointRequestOptions
): Promise {
warn(
"serviceInfo() will be deprecated in the next major release. please use getGeocoderServiceInfo() instead."
);
return getGeocodeService(requestOptions);
}