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