ps2census
Version:
Client to connect to the PS2 Event Stream websocket.
115 lines • 3.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetQuery = void 0;
const census_response_1 = require("./utils/census-response");
class GetQuery {
constructor(census, collection) {
this.census = census;
this.collection = collection;
this.params = {};
}
case(x) {
return this.clone().set('c:case', x);
}
distinct(path) {
return this.clone().set('c:distinct', path);
}
exactMatchFirst(x) {
return this.clone().set('c:exactMatchFirst', x);
}
has(path) {
return this.clone().set('c:has', path);
}
hide(...paths) {
return this.clone().set('c:hide', paths.join(','));
}
includeNull(x) {
return this.clone().set('c:includeNull', x);
}
join(...joins) {
return this.clone().set('c:join', this.joinToString(joins));
}
lang(x) {
return this.clone().set('c:lang', x);
}
limit(x) {
return this.clone().set('c:limit', x);
}
limitPerDB(x) {
return this.clone().set('c:limitPerDB', x);
}
resolve(...resolve) {
return this.clone().set('c:resolve', resolve
.map(s => (Array.isArray(s) ? `${s[0]}(${s[1].join(',')})` : s))
.join(','));
}
retry(x) {
return this.clone().set('c:retry', x);
}
show(...paths) {
return this.clone().set('c:show', paths.join(','));
}
sort(...x) {
return this.clone().set('c:sort', x.map(s => (Array.isArray(s) ? `${s[0]}:${s[1]}` : s)).join(','));
}
start(x) {
return this.clone().set('c:start', x);
}
timing(x) {
return this.clone().set('c:timing', x);
}
tree(tree) {
let str = tree.field;
if (tree.list)
str += `^list:${tree.list}`;
if (tree.prefix)
str += `^prefix:${tree.prefix}`;
if (tree.start)
str += `^start:${tree.start}`;
return this.clone().set('c:tree', str);
}
async get(query) {
return new census_response_1.CensusResponse(this.collection, await this.census.get(this.collection, Object.assign({}, this.params, query)));
}
set(key, value) {
this.params[key] = value;
return this;
}
clone() {
return Object.assign(new GetQuery(this.census, this.collection), {
params: this.params,
});
}
joinToString(joins) {
return joins
.map(join => {
let str = join.type;
if (join.on)
str += `^on:${join.on}`;
if (join.to)
str += `^to:${join.to}`;
if (join.list)
str += `^list:${join.list}`;
if (join.inject_at)
str += `^inject_at:${join.inject_at}`;
if (join.terms)
str += `^terms:${Object.entries(join.terms)
.map(([k, v]) => Array.isArray(v)
? v.map(sv => `${k}=${sv}`).join('`')
: `${k}=${v}`)
.join('`')}`;
if (join.outer)
str += `^outer:${join.outer}`;
if (join.show)
str += `^show:${join.show.join("'")}`;
else if (join.hide)
str += `^hide:${join.hide.join("'")}`;
if (join.nested && join.nested.length > 0)
str += `(${this.joinToString(join.nested)})`;
return str;
})
.join(',');
}
}
exports.GetQuery = GetQuery;
//# sourceMappingURL=get.query.js.map