UNPKG

@statezero/core

Version:

The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate

72 lines (71 loc) 2.41 kB
/** * This file was auto-generated. Do not make direct changes to the file. */ import { Model, Manager, QuerySet, getModelClass } from '../../../../src'; import { wrapReactiveModel } from '../../../../src'; import schemaData from './product.schema.json'; /** * Model-specific QuerySet implementation */ export class ProductQuerySet extends QuerySet { } /** * Model-specific Manager implementation */ export class ProductManager extends Manager { constructor(ModelClass) { super(ModelClass, ProductQuerySet); } newQuerySet() { return new ProductQuerySet(this.ModelClass); } } /** * Implementation of the Product model */ export class Product extends Model { constructor(data) { Product.validateFields(data); super(data); // Define getters and setters for all fields this._defineProperties(); return wrapReactiveModel(this); } /** * Define property getters and setters for all model fields * @private */ _defineProperties() { // For each field, define a property that gets/sets from internal storage Product.fields.forEach(field => { Object.defineProperty(this, field, { get: function () { return this.getField(field); }, set: function (value) { this.setField(field, value); }, enumerable: true, // Make sure fields are enumerable for serialization configurable: true }); }); // Add a special read-only getter for the repr field Object.defineProperty(this, 'repr', { get: function () { return this.getField('repr'); }, enumerable: true, // Make sure repr is enumerable configurable: true }); } } // Bind this model to its backend Product.configKey = 'default'; Product.modelName = 'django_app.product'; Product.primaryKeyField = 'id'; Product.objects = new ProductManager(Product); Product.fields = ['id', 'name', 'description', 'price', 'category', 'in_stock', 'created_at', 'created_by', 'price_with_tax', 'display_name']; Product.schema = schemaData; Product.relationshipFields = new Map([ ['category', { 'ModelClass': () => getModelClass('django_app.productcategory', 'default'), 'relationshipType': 'foreign-key' }] ]);