UNPKG

ph-dev-tools

Version:
77 lines (74 loc) 2.62 kB
"use strict"; const QPropertyBuilder_1 = require("./QPropertyBuilder"); const QRelationBuilder_1 = require("./QRelationBuilder"); class QEntityBuilder { constructor(entity, fullGenerationPath, workingDirPath, fileBuilder) { this.entity = entity; this.fullGenerationPath = fullGenerationPath; this.workingDirPath = workingDirPath; this.fileBuilder = fileBuilder; this.propertyBuilders = []; this.relationBuilders = []; entity.docEntry.properties.forEach((property) => { if (property.primitive) { let propertyBuilder = new QPropertyBuilder_1.QPropertyBuilder(this, property); this.propertyBuilders.push(propertyBuilder); } else { if (property.entity) { let relationBuilder = new QRelationBuilder_1.QRelationBuilder(this, property); this.relationBuilders.push(relationBuilder); } else { throw `Unexpected PropertyDocEntry: ${property.name}`; } } }); } addImport(importString) { this.fileBuilder.addImport(importString); } build() { let properties = ``; let staticProperties = ``; let qName = `Q${this.entity.docEntry.name}`; this.propertyBuilders.forEach((builder) => { properties += ` ${builder.build()}\n`; let propertyName = builder.propertyDocEntry.name; staticProperties += ` static ${propertyName} = ${qName}.q.${propertyName};\n`; }); let relations = ``; let staticRelations = ``; this.relationBuilders.forEach((builder) => { relations += ` ${builder.build()}\n`; let relationName = builder.entityProperty.name; staticRelations += ` static ${relationName} = ${qName}.q.${relationName};\n`; }); let classSource = `// Entity Query Implementation export class ${qName} extends QEntity<${qName}> implements I${qName} { static q = new ${qName}(true); // Static Field accessors ${staticProperties} // Static Relation accessors ${staticRelations} // Fields ${properties} // Relations ${relations} constructor( isTemplate:boolean = false ) { super(${this.entity.type}, '${this.entity.type}', isTemplate); } toJSON():any { throw 'Not Implemented'; } } `; return classSource; } } exports.QEntityBuilder = QEntityBuilder; //# sourceMappingURL=QEntityBuilder.js.map