@skbkontur/cassandra-distributed-task-queue-ui
Version:
.NET library implementing distributed task queue machinery using Apache Cassandra
65 lines • 2.81 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryStringMappingBuilder = void 0;
const edi_ui_1 = require("@skbkontur/edi-ui");
const Mappers_1 = require("./Mappers");
const QueryStringMapping_1 = require("./QueryStringMapping");
class PropertyConfigurator {
constructor(propertyPicker, mapper) {
Object.defineProperty(this, "mapper", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "lens", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.lens = edi_ui_1.pathLens(propertyPicker);
this.mapper = mapper;
}
createParser() {
return (target, parsedQueryString) => this.lens.set(target, this.mapper.parse(parsedQueryString));
}
createStringifier() {
return (target, parsedQueryString) => this.mapper.stringify(parsedQueryString, this.lens.get(target));
}
}
class QueryStringMappingBuilder {
constructor() {
Object.defineProperty(this, "configurators", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
}
mapTo(propertyPicker, mapper) {
const result = new PropertyConfigurator(propertyPicker, mapper);
this.configurators.push(result);
return this;
}
mapToStringArray(propertyPicker, queryStringParameterName, defaultValue) {
return this.mapTo(propertyPicker, new Mappers_1.StringArrayMapper(queryStringParameterName, defaultValue));
}
mapToInteger(propertyPicker, queryStringParameterName, defaultValue) {
return this.mapTo(propertyPicker, new Mappers_1.IntegerMapper(queryStringParameterName, defaultValue));
}
mapToDateTimeRange(propertyPicker, queryStringParameterName, defaultValue = null) {
return this.mapTo(propertyPicker, new Mappers_1.DateTimeRangeMapper(queryStringParameterName, defaultValue));
}
mapToString(propertyPicker, queryStringParameterName, defaultValue) {
return this.mapTo(propertyPicker, new Mappers_1.StringMapper(queryStringParameterName, defaultValue));
}
mapToSet(propertyPicker, queryStringParameterName, enumValues, allowNegationOperator = false) {
return this.mapTo(propertyPicker, new Mappers_1.SetMapper(queryStringParameterName, enumValues, allowNegationOperator));
}
build() {
return new QueryStringMapping_1.QueryStringMapping(this.configurators.map(x => x.createParser()), this.configurators.map(x => x.createStringifier()));
}
}
exports.QueryStringMappingBuilder = QueryStringMappingBuilder;
//# sourceMappingURL=QueryStringMappingBuilder.js.map
;