slim-ef
Version:
An implementation of basic entity framework functionnalities in typescript
53 lines • 1.72 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DbContextModelBuilder = void 0;
const GlobalMapKey = {
name: Symbol('GlobalMapKey')
};
class DbContextModelBuilder {
constructor() {
this._modelsFilterMap = new WeakMap();
this._currentType = void 0;
}
entity(type) {
this._currentType = type;
return this;
}
hasQueryFilter(query) {
let expMap = [];
if (this._modelsFilterMap.has(this._currentType)) {
expMap = this._modelsFilterMap.get(this._currentType);
}
expMap.push(query);
this._modelsFilterMap.delete(this._currentType);
this._modelsFilterMap.set(this._currentType, expMap);
this._currentType = void 0;
return this;
}
hasGlobalQueryFilter(query) {
const oldType = this._currentType;
this._currentType = GlobalMapKey;
this.hasQueryFilter(query);
this._currentType = oldType;
}
resetAllFilters() {
this._currentType = void 0;
this._modelsFilterMap = new WeakMap();
}
resetFilterFor(type) {
this._modelsFilterMap.delete(this._currentType);
this._currentType = void 0;
}
getFilters(type) {
const filters = [];
if (this._modelsFilterMap.has(type)) {
filters.push(...this._modelsFilterMap.get(type));
}
if (this._modelsFilterMap.has(GlobalMapKey)) {
filters.push(...this._modelsFilterMap.get(GlobalMapKey));
}
return filters;
}
}
exports.DbContextModelBuilder = DbContextModelBuilder;
//# sourceMappingURL=model-builder.js.map