UNPKG

@rest-api/react-models

Version:

[![npm version](https://img.shields.io/npm/v/@rest-api/react-models)](https://www.npmjs.com/package/@rest-api/react-models) [![codecov](https://codecov.io/gh/hector7/rest-api-react-models/branch/master/graph/badge.svg)](https://codecov.io/gh/hector7/rest-

37 lines (36 loc) 1.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Schema_1 = require("./Schema"); const BasicRestModel_1 = __importDefault(require("./restmodels/basic/BasicRestModel")); class ModelConstructor { constructor(getItemsStructure, getItems, getMetaData) { this.itemStructure = getItemsStructure; } getItemsStructure(schema) { if (this.itemStructure) { return this.itemStructure(schema); } return undefined; } getItems() { if (this.items) return this.items; return undefined; } getMetaData() { if (this.metaData) return this.metaData; return undefined; } get routeOpts() { return {}; } getModel(schema, idKey, url) { return new BasicRestModel_1.default(schema, idKey, url, this.getItemsStructure(schema), this.getItems(), this.getMetaData(), this.routeOpts); } } exports.default = ModelConstructor; const model = new ModelConstructor().getModel(Schema_1.Schema.getSchema({ id: { type: Number, required: true } }), 'id', '');