@maximai/maxim-js
Version:
Maxim AI JS SDK. Visit https://getmaxim.ai for more info.
57 lines • 1.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryBuilder = exports.QueryRuleType = void 0;
var QueryRuleType;
(function (QueryRuleType) {
QueryRuleType["DeploymentVar"] = "deploymentVar";
QueryRuleType["Tag"] = "tag";
})(QueryRuleType || (exports.QueryRuleType = QueryRuleType = {}));
class QueryBuilder {
constructor() {
this.scopes = {};
this.isExactMatch = false;
this.query = "";
this.operator = "AND";
}
and() {
this.operator = "AND";
return this;
}
or() {
this.operator = "OR";
return this;
}
folder(folderId) {
this.scopes["folder"] = folderId;
return this;
}
exactMatch() {
this.isExactMatch = true;
return this;
}
deploymentVar(key, value, enforce = true) {
if (this.query.length > 0)
this.query += ",";
this.query += `${enforce ? "!!" : ""}${key}=${value}`;
return this;
}
tag(key, value, enforce = false) {
if (this.query.length > 0)
this.query += ",";
this.query += `${enforce ? "!!" : ""}${key}=${value}`;
return this;
}
build() {
if (this.query.trim().length === 0) {
throw new Error("Cannot build an empty query. Please add at least one rule (deploymentVar or tag).");
}
return {
query: this.query,
operator: this.operator,
exactMatch: this.isExactMatch,
scopes: this.scopes,
};
}
}
exports.QueryBuilder = QueryBuilder;
//# sourceMappingURL=queryBuilder.js.map