@websolute/faker.ts
Version:
Easy to Use, Powered by Decorators, Faker.js TypeScript Wrapper
56 lines • 2.53 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayValueHandler = void 0;
var primitive_handler_abstract_1 = require("./primitive-handler-abstract");
// TODO: refactor (2nd phase). All other fixture options should be wrapped with 'multiple' functionality
var ArrayValueHandler = /** @class */ (function (_super) {
__extends(ArrayValueHandler, _super);
function ArrayValueHandler(faker, classProcessor) {
var _this = _super.call(this, faker) || this;
_this.faker = faker;
_this.classProcessor = classProcessor;
return _this;
}
ArrayValueHandler.hasTypeKey = function (propertyDto) {
var value = propertyDto.value;
return Object.prototype.hasOwnProperty.call(value, 'type');
};
ArrayValueHandler.prototype.shouldHandle = function (propertyDto) {
return propertyDto.type === 'object' && ArrayValueHandler.hasTypeKey(propertyDto);
};
ArrayValueHandler.prototype.produceValue = function (propertyDto) {
var value = propertyDto.value;
if (value === null) {
return value;
}
var count = value.count, type = value.type;
if (primitive_handler_abstract_1.PrimitiveHandlerAbstract.PRIMITIVES.includes(type.name)) {
var instances_1 = new Array(count);
for (var index = 0; index < count; index++) {
instances_1[index] = _super.prototype.generateRandomValueFromPrimitive.call(this, type.name);
}
return instances_1;
}
var instances = new Array(count);
for (var index = 0; index < count; index++) {
instances[index] = this.classProcessor.process(type);
}
return instances;
};
return ArrayValueHandler;
}(primitive_handler_abstract_1.PrimitiveHandlerAbstract));
exports.ArrayValueHandler = ArrayValueHandler;
//# sourceMappingURL=array-value-handler.js.map