@statezero/core
Version:
The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate
73 lines (72 loc) • 2.64 kB
JavaScript
/**
* 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 './deepmodellevel1.schema.json';
/**
* Model-specific QuerySet implementation
*/
export class DeepModelLevel1QuerySet extends QuerySet {
}
/**
* Model-specific Manager implementation
*/
export class DeepModelLevel1Manager extends Manager {
constructor(ModelClass) {
super(ModelClass, DeepModelLevel1QuerySet);
}
newQuerySet() {
return new DeepModelLevel1QuerySet(this.ModelClass);
}
}
/**
* Implementation of the DeepModelLevel1 model
*/
export class DeepModelLevel1 extends Model {
constructor(data) {
DeepModelLevel1.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
DeepModelLevel1.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
DeepModelLevel1.configKey = 'default';
DeepModelLevel1.modelName = 'django_app.deepmodellevel1';
DeepModelLevel1.primaryKeyField = 'id';
DeepModelLevel1.objects = new DeepModelLevel1Manager(DeepModelLevel1);
DeepModelLevel1.fields = ['id', 'name', 'level2', 'comprehensive_models'];
DeepModelLevel1.schema = schemaData;
DeepModelLevel1.relationshipFields = new Map([
['level2', { 'ModelClass': () => getModelClass('django_app.deepmodellevel2', 'default'), 'relationshipType': 'foreign-key' }],
['comprehensive_models', { 'ModelClass': () => getModelClass('django_app.comprehensivemodel', 'default'), 'relationshipType': 'many-to-many' }]
]);