UNPKG

angular-odata

Version:

Client side OData typescript library for Angular

169 lines 7.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Package = void 0; const base_1 = require("./base"); const module_1 = require("./module"); const api_config_1 = require("./api-config"); const enum_1 = require("./enum"); const entity_1 = require("./entity"); const model_1 = require("./model"); const collection_1 = require("./collection"); const service_1 = require("./service"); class Package { constructor(options, meta) { var _a, _b, _c, _d, _e, _f; this.options = options; this.enums = []; this.entities = []; this.services = []; this.models = []; this.collections = []; this.functions = []; this.actions = []; this.metadata = new base_1.Metadata(this, options, meta); this.module = new module_1.Module(this, options); this.config = new api_config_1.ApiConfig(this, options); this.index = new base_1.Index(this, options); this.index.addDependency(this.module); this.index.addDependency(this.config); for (let s of meta.Schemas) { const namespace = s.Namespace; // Enum for (const enumType of (_a = s.EnumType) !== null && _a !== void 0 ? _a : []) { const enu = new enum_1.Enum(this, options, enumType); this.enums.push(enu); this.index.addDependency(enu); } // Entity for (let entityType of (_b = s.EntityType) !== null && _b !== void 0 ? _b : []) { const entity = new entity_1.Entity(this, options, entityType); this.entities.push(entity); this.index.addDependency(entity); if (options.models) { const model = new model_1.Model(this, options, entityType, entity); this.index.addDependency(model); this.models.push(model); const collection = new collection_1.Collection(this, options, entityType, entity, model); this.index.addDependency(collection); this.collections.push(collection); } } // Complex for (let complexType of (_c = s.ComplexType) !== null && _c !== void 0 ? _c : []) { const entity = new entity_1.Entity(this, options, complexType); this.index.addDependency(entity); this.entities.push(entity); if (options.models) { const model = new model_1.Model(this, options, complexType, entity); this.index.addDependency(model); this.models.push(model); const collection = new collection_1.Collection(this, options, complexType, entity, model); this.index.addDependency(collection); this.collections.push(collection); } } // Container for (let entityContainer of (_d = s.EntityContainer) !== null && _d !== void 0 ? _d : []) { const service = new service_1.Service(this, options, entityContainer); this.module.addService(service); this.index.addDependency(service); this.services.push(service); for (let entitySet of (_e = entityContainer.EntitySet) !== null && _e !== void 0 ? _e : []) { const service = new service_1.Service(this, options, entitySet); this.module.addService(service); this.index.addDependency(service); this.services.push(service); } for (let singleton of (_f = entityContainer.Singleton) !== null && _f !== void 0 ? _f : []) { const service = new service_1.Service(this, options, singleton); this.module.addService(service); this.index.addDependency(service); this.services.push(service); } } } this.functions = meta.functions().reduce((callables, f) => { const callable = callables.find((c) => c.name() == f.Name); if (callable !== undefined) { callable.addOverload(f); } else { callables.push(new base_1.Callable(f)); } return callables; }, []); this.actions = meta.actions().reduce((callables, a) => { const callable = callables.find((c) => c.name() == a.Name); if (callable !== undefined) { callable.addOverload(a); } else { callables.push(new base_1.Callable(a)); } return callables; }, []); this.services.forEach((s) => { s.addCallables(this.functions.filter((f) => { var _a; return f.isBound() && ((_a = f.bindingParameter()) === null || _a === void 0 ? void 0 : _a.Type) === s.entityType(); })); s.addCallables(this.actions.filter((f) => { var _a; return f.isBound() && ((_a = f.bindingParameter()) === null || _a === void 0 ? void 0 : _a.Type) === s.entityType(); })); }); this.models .forEach((m) => { m.addCallables(this.functions.filter((f) => { var _a; return f.isBound() && ((_a = f.bindingParameter()) === null || _a === void 0 ? void 0 : _a.Type) === m.entityType(); })); m.addCallables(this.actions.filter((f) => { var _a; return f.isBound() && ((_a = f.bindingParameter()) === null || _a === void 0 ? void 0 : _a.Type) === m.entityType(); })); }); this.collections .forEach((c) => { c.addCallables(this.functions.filter((f) => { var _a; return f.isBound() && ((_a = f.bindingParameter()) === null || _a === void 0 ? void 0 : _a.Type) === c.entityType(); })); c.addCallables(this.actions.filter((f) => { var _a; return f.isBound() && ((_a = f.bindingParameter()) === null || _a === void 0 ? void 0 : _a.Type) === c.entityType(); })); }); } resolveImports() { const sources = this.sources(); sources.forEach((s) => { for (let t of s.importTypes()) { s.addDependencies(sources.filter((s) => s.fullName() === t)); } s.cleanImportedNames(); }); } sources() { const sources = [ this.metadata, this.index, this.module, this.config, ...this.enums, ...this.entities, ...this.models, ...this.collections, ...this.services, ]; return sources; } findEnum(fullName) { return this.enums.find((e) => e.fullName() === fullName); } findEnumType(fullName) { return this.metadata.findEnumType(fullName); } findEntity(fullName) { return this.entities.find((e) => e.fullName() === fullName); } findEntityType(fullName) { return this.metadata.findEntityType(fullName); } findEntitySet(fullName) { return this.metadata.findEntitySet(fullName); } findComplexType(fullName) { return this.metadata.findComplexType(fullName); } findModel(fullName) { return this.models.find((m) => m.entityType() === fullName); } findCollection(fullName) { return this.collections.find((c) => c.entityType() === fullName); } } exports.Package = Package; //# sourceMappingURL=package.js.map