UNPKG

@omnia/tooling-composers

Version:

Provide tooling to work with manifest things.

111 lines (110 loc) 5.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResourcesComposer = exports.ReOpenedResourceComposer = void 0; const ResourceRegistry_1 = require("./ResourceRegistry"); const LoadableManifestRegistry_1 = require("./LoadableManifestRegistry"); const DependencyComposer_1 = require("./DependencyComposer"); const CombinableRuleComposer_1 = require("./CombinableRuleComposer"); const Enums_1 = require("./models/Enums"); const LocalizationComposer_1 = require("./LocalizationComposer"); const ComposerBase_1 = require("./ComposerBase"); //Use another class to ensure it's not casted to expose other things class ReOpenedResourceComposer { constructor(manifestId) { this.manifest = null; this.registerResource = (resourcesOptions) => { ResourceRegistry_1.ResourceRegistry.registerResource(this.manifest, resourcesOptions); return this; }; this.orderUsing = (orderOption) => { ResourceRegistry_1.ResourceRegistry.addOrdering(this.manifest, orderOption); }; this.registerLocalization = (localizationOptions) => { return new LocalizationComposer_1.Localization(localizationOptions, this.manifestId); }; this.manifestId = manifestId; this.manifest = LoadableManifestRegistry_1.LoadableManifestRegistry.getRegisteredManifest(manifestId); if (this.manifest == null) { this.manifest = { manifestType: Enums_1.ClientManifestTypes.Resource, resourceId: manifestId }; LoadableManifestRegistry_1.LoadableManifestRegistry.registerManifest(this.manifest); } } } exports.ReOpenedResourceComposer = ReOpenedResourceComposer; class ResourcesComposer extends ComposerBase_1.ComposerBase { constructor(manifestId, manifestName) { super(); this.manifestName = manifestName; //private manifest: ResourceManifest = null; this.ruleComposer = null; this.registerResource = (resourcesOptions) => { ResourceRegistry_1.ResourceRegistry.registerResource(this.manifest, resourcesOptions); return this; }; this.withLoadRules = () => { this.ruleComposer = new CombinableRuleComposer_1.CombinableRuleComposer(this.persistCombinedRules, this); return this.ruleComposer; }; //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<IResourcesComposer>) => 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; //} 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) => { ResourceRegistry_1.ResourceRegistry.newCombinedRules(this.manifest, rules); }; this.manifest = LoadableManifestRegistry_1.LoadableManifestRegistry.getRegisteredManifest(manifestId); if (this.manifest == null) { this.manifest = { manifestType: Enums_1.ClientManifestTypes.Resource, resourceId: manifestId, resourceName: manifestName }; LoadableManifestRegistry_1.LoadableManifestRegistry.registerManifest(this.manifest); } else if (manifestName) { this.manifest.resourceName = manifestName; } } } exports.ResourcesComposer = ResourcesComposer;