UNPKG

faker-api

Version:

A fully customizible rest api faking package that allows you to mock , clone and fake Rest API with fake yet realistic data

61 lines 2.4 kB
"use strict"; 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractModel = exports.Model = void 0; var fields_1 = require("./fields"); var abstract_model_1 = __importDefault(require("./abstract-model")); exports.AbstractModel = abstract_model_1.default; var Model = /** @class */ (function (_super) { __extends(Model, _super); function Model(fields) { var _this = _super.call(this) || this; _this.fields = {}; _this.fields = fields; return _this; } Model.prototype.generate = function (request, params) { // Get the keys of the fields var keys = Object.keys(this.fields); var build = {}; for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; var field = this.fields[key]; if (typeof field === "string" || typeof field === "number") { build[key] = field; } else if (typeof field === "function") { build[key] = field(request, params); } else if (field instanceof fields_1.Field) { build[key] = field.generate(); } else if (field instanceof Array) { build[key] = field; } else { build[key] = field; } } return build; }; return Model; }(abstract_model_1.default)); exports.Model = Model; //# sourceMappingURL=index.js.map