type-dexie
Version:
class oriented schema building tool for dexie.js
58 lines • 2.39 kB
JavaScript
;
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compileSchema = void 0;
var column_1 = require("../decorator/column");
var entity_1 = require("../decorator/entity");
var assert_1 = require("./assert");
var entity_compiler_1 = require("./entity-compiler");
var naming_1 = require("./naming");
var multiple_implementations_error_1 = require("../error/multiple-implementations.error");
var SchemaCompiler = /** @class */ (function () {
function SchemaCompiler(entities) {
this.schema = {};
this.entities = __spreadArrays(entities);
}
SchemaCompiler.compile = function () {
var entities = [];
for (var _i = 0; _i < arguments.length; _i++) {
entities[_i] = arguments[_i];
}
return new SchemaCompiler(entities).compile();
};
SchemaCompiler.prototype.compile = function () {
for (var _i = 0, _a = this.entities; _i < _a.length; _i++) {
var entity = _a[_i];
this._compile(entity);
}
return this.schema;
};
SchemaCompiler.prototype._compile = function (target, parent, propertyKey) {
var _this = this;
assert_1.default.isEntity(target);
var $name = naming_1.default.table(target);
var $def = entity_compiler_1.compileEntity(target, parent, propertyKey);
if ($name in this.schema) {
if ($def !== this.schema[$name]) {
throw new multiple_implementations_error_1.MultipleImplementationsError($name);
}
}
else {
this.schema[$name] = $def;
}
column_1.Column.getMetadata(target)
.filter(function (column) { return entity_1.Entity.isEntity(column.type); })
.forEach(function (column) {
_this._compile(column.type, target, column.propertyKey);
});
};
return SchemaCompiler;
}());
exports.compileSchema = SchemaCompiler.compile;
//# sourceMappingURL=schema-compiler.js.map