UNPKG

@omnia/tooling-composers

Version:

Provide tooling to work with manifest things.

138 lines (137 loc) 7.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ComponentComposer = void 0; const tslib_1 = require("tslib"); const deep_extend_1 = tslib_1.__importDefault(require("deep-extend")); const ComponentRegistry_1 = require("./ComponentRegistry"); const DependencyComposer_1 = require("./DependencyComposer"); const LoadableManifestRegistry_1 = require("./LoadableManifestRegistry"); const CombinableRuleComposer_1 = require("./CombinableRuleComposer"); const Enums_1 = require("./models/Enums"); const Utils_1 = require("./Utils"); const ComposerBase_1 = require("./ComposerBase"); class ComponentComposer extends ComposerBase_1.ComposerBase { constructor(manifestId, manifestName) { super(); this.ruleComposer = null; //public readonly manifest: ResourceManifest; //public registerApi = (exp: ((extend: IExtend) => Promise<any>)) => { // if (typeof exp === "string") { // this.manifest.api = this.manifest.api || []; // this.manifest.api.push(exp); // this.manifest.api = Array.from(new Set<string>(this.manifest.api)); // } else { // this.manifest.api = Array.from(new Set<string>((this.manifest.api || []).concat(Utils.getPropertyPathInExpression(exp as any)))); // } // LoadableManifestRegistry.registerManifest(this.manifest); // return this; //} //public extendApi = (exp: ((extend: IExtendApiManifest) => ApiPath), expRules?: (builder: ICombinableRuleComposer<IWebComponentComposer>) => void) => { // if (expRules) { // expRules(new CombinableRuleComposer((rules: Array<ClientResolvableLoadRule>) => { // ResourceRegistry.addExtendApiRules(this.manifest, rules); // }, this)) // } // if (typeof exp === "string") { // this.manifest.extendApi = this.manifest.extendApi || []; // this.manifest.extendApi.push(exp); // this.manifest.extendApi = Array.from(new Set<string>(this.manifest.extendApi)); // } else { // const apiResult = Utils.getPropertyPathAndConfigurationInExpression(exp as any) // this.manifest.extendApi = Array.from(new Set<string>((this.manifest.extendApi || []).concat(apiResult[0]))); // if (apiResult[1]) { // this.manifest.extendApiConfiguration = this.manifest.extendApiConfiguration || Object.create(null) // this.manifest.extendApiConfiguration[apiResult[0]] = apiResult[1] // } // } // LoadableManifestRegistry.registerManifest(this.manifest); // return this; //} //public registerApi = (exp: ((extend: IExtend) => Promise<any> | Promise<any>[])) => { // if (typeof exp === "string") { // this.manifest.api = this.manifest.api || []; // this.manifest.api.push(exp); // this.manifest.api = Array.from(new Set<string>(this.manifest.api)); // } else { // this.manifest.api = Array.from(new Set<string>((this.manifest.api || []).concat(Utils.getPropertyPathInExpression(exp as any)))); // } // LoadableManifestRegistry.registerManifest(this.manifest); // return this; //} //public extendApi = (exp: ((extend: IExtend) => Promise<any> | Promise<any>[])) => { // if (typeof exp === "string") { // this.manifest.extendApi = this.manifest.extendApi || []; // this.manifest.extendApi.push(exp); // this.manifest.extendApi = Array.from(new Set<string>(this.manifest.extendApi)); // } else { // this.manifest.extendApi = Array.from(new Set<string>((this.manifest.extendApi || []).concat(Utils.getPropertyPathInExpression(exp as any)))); // } // LoadableManifestRegistry.registerManifest(this.manifest); // return this; //} this.withDefinition = (definition) => { var currentDefinition = ComponentRegistry_1.ComponentRegistry.getComponentDefinition(this.manifest) || {}; ComponentRegistry_1.ComponentRegistry.addComponentDefinition(this.manifest, (0, deep_extend_1.default)(currentDefinition, definition)); //return new WebComponentSupportDefinition(this, this.manifest); return this; }; this.registerComponent = (componentOptions) => { ComponentRegistry_1.ComponentRegistry.registerComponent(this.manifest, componentOptions); return this; }; this.withLoadRules = () => { this.ruleComposer = new CombinableRuleComposer_1.CombinableRuleComposer(this.persistCombinedRules, this); return this.ruleComposer; }; this.registerOmniaBlock = (options) => { let definition = ComponentRegistry_1.ComponentRegistry.getComponentDefinition(this.manifest) || {}; if (options && options.layoutDependencyProviders && typeof options.layoutDependencyProviders === "function") { options.layoutDependencyProviders = Utils_1.Utils.getPropertyPathInExpression(options.layoutDependencyProviders); } ComponentRegistry_1.ComponentRegistry.addComponentDefinition(this.manifest, (0, deep_extend_1.default)(definition, Object.assign({ showInOmniaBlock: true }, options || {}))); return this; }; //TODO: Add back when we implement support for it //public withDefinition = (definition: WebComponentDefinition): IWebComponentComposer => { // ComponentRegistry.addComponentDefinition(this.manifest, definition); // return this; //}; //public loadByUrlRule = (loadRule: ILoadByUrlRule) => { // ComponentRegistry.loadByUrl(this.manifest, loadRule); // return this; //} //public loadByElementRule = (elementRule: IElementSelectorRule) => { // ComponentRegistry.loadByElementRule(this.manifest, elementRule); // return this; //} this.withNoDependency = () => { return new DependencyComposer_1.DependencyComposer(this.manifest.resourceId, this).withNoDependency(); }; this.withDependency = (manifestId) => { //Validate if dependency if needed, and add if ok return new DependencyComposer_1.DependencyComposer(this.manifest.resourceId, this).withDependency(manifestId); }; this.withExternalDependency = (omniaServiceId, manifestId) => { return new DependencyComposer_1.DependencyComposer(this.manifest.resourceId, this).withExternalDependency(omniaServiceId, manifestId); }; this.persistCombinedRules = (rules) => { ComponentRegistry_1.ComponentRegistry.newCombinedRules(this.manifest, rules); }; this.manifest = LoadableManifestRegistry_1.LoadableManifestRegistry.getRegisteredManifest(manifestId); if (this.manifest == null) { this.manifest = { manifestType: Enums_1.ClientManifestTypes.Component, resourceId: manifestId, resourceName: manifestName, }; LoadableManifestRegistry_1.LoadableManifestRegistry.registerManifest(this.manifest); } else if (manifestName) { this.manifest.resourceName = manifestName; } } } exports.ComponentComposer = ComponentComposer;