ravendb
Version:
RavenDB client for Node.js
52 lines • 2.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsToFetchToken = void 0;
const QueryToken_js_1 = require("./QueryToken.js");
const index_js_1 = require("../../../Exceptions/index.js");
class FieldsToFetchToken extends QueryToken_js_1.QueryToken {
fieldsToFetch;
projections;
customFunction;
sourceAlias;
constructor(fieldsToFetch, projections, customFunction, sourceAlias) {
super();
this.fieldsToFetch = fieldsToFetch;
this.projections = projections;
this.customFunction = customFunction;
this.sourceAlias = sourceAlias;
}
static create(fieldsToFetch, projections, customFunction, sourceAlias) {
if (!fieldsToFetch || !fieldsToFetch.length) {
(0, index_js_1.throwError)("InvalidArgumentException", "fieldToFetch cannot be null");
}
if (!customFunction && projections && projections.length !== fieldsToFetch.length) {
(0, index_js_1.throwError)("InvalidArgumentException", "Length of projections must be the same as length of field to fetch");
}
return new FieldsToFetchToken(fieldsToFetch, projections, customFunction, sourceAlias);
}
writeTo(writer) {
for (let i = 0; i < this.fieldsToFetch.length; i++) {
const fieldToFetch = this.fieldsToFetch[i];
if (i > 0) {
writer.append(", ");
}
if (!fieldToFetch) {
writer.append("null");
}
else {
QueryToken_js_1.QueryToken.writeField(writer, fieldToFetch);
}
if (this.customFunction) {
continue;
}
const projection = this.projections ? this.projections[i] : null;
if (!projection || projection === fieldToFetch) {
continue;
}
writer.append(" as ");
writer.append(projection);
}
}
}
exports.FieldsToFetchToken = FieldsToFetchToken;
//# sourceMappingURL=FieldsToFetchToken.js.map