UNPKG

@entity-factory/core

Version:

Create entities on the fly for mocking and testing

50 lines (49 loc) 1.8 kB
"use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BlueprintLoader = void 0; var Blueprint_1 = require("./Blueprint"); var BlueprintLoader = (function () { function BlueprintLoader(fixtureProfiles) { this.fixtureProfiles = fixtureProfiles; } BlueprintLoader.prototype.getProfiles = function () { return __spreadArray([], this.resolveClasses(this.fixtureProfiles), true); }; BlueprintLoader.prototype.resolveClasses = function (cls) { var _this = this; var profiles = []; this.getClasses(cls).forEach(function (c) { var instance = _this.createFactoryProfileInstance(c); if (instance) { profiles.push(instance); } }); return profiles; }; BlueprintLoader.prototype.getClasses = function (values) { return values.filter(function (v) { return typeof v !== 'string'; }); }; BlueprintLoader.prototype.createFactoryProfileInstance = function (cls) { if (cls instanceof Blueprint_1.Blueprint) { return cls; } if (cls instanceof Function) { var created = new cls(); if (created instanceof Blueprint_1.Blueprint) { return created; } } return undefined; }; return BlueprintLoader; }()); exports.BlueprintLoader = BlueprintLoader;