UNPKG

@omnia/tooling-composers

Version:

Provide tooling to work with manifest things.

142 lines (141 loc) • 8.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ManifestGroupRegistry = exports.ManifestGroupRegistration = void 0; const LoadableManifestRegistry_1 = require("./LoadableManifestRegistry"); const ManifestRegistry_1 = require("./ManifestRegistry"); //import { ResourceBuildOptions, WebComponentDefinition, WebComponentOptions, LoadIfManifestLoaded, ClientResolvableLoadRule, ManifestGroupOptions, GroupedBundleManifest, ServerManifest } from "./models/index"; const Utils_1 = require("./Utils"); const Enums_1 = require("./models/Enums"); class ManifestGroupRegistration { constructor(manifestGroupOptions, manifestPath, manifest) { this.manifestGroupOptions = manifestGroupOptions; this.manifestPath = manifestPath; this.manifest = manifest; this.loadRules = []; } } exports.ManifestGroupRegistration = ManifestGroupRegistration; class ManifestGroupRegistry { constructor() { ///Todo handle method hiding, shoud be only be visible to ManifestRegistry, i.e. as provider this.getClientLoadableManifests = (currentServiceId) => { let manifests = []; for (let key in ManifestGroupRegistry.ManifestGroupRegistrations) { let groupRegistration = ManifestGroupRegistry.ManifestGroupRegistrations[key]; let componentManifest = { manifestIdsInGroup: groupRegistration.manifestGroupOptions.webComponentManifestIds.concat(groupRegistration.manifestGroupOptions.resourceManifestIds), manifestType: Enums_1.ClientManifestTypes.ManifestGroup, resourceId: groupRegistration.manifest.resourceId, resourceName: groupRegistration.manifest.resourceName, omniaServiceId: currentServiceId, dependingOnManifests: LoadableManifestRegistry_1.LoadableManifestRegistry.getManifestDependencies(key, currentServiceId), version: LoadableManifestRegistry_1.LoadableManifestRegistry.getManifestVersion(key), combinedLoadRules: groupRegistration.loadRules, availableBundleTargetTypes: LoadableManifestRegistry_1.LoadableManifestRegistry.getManifestBundleTypes(key), authDisabled: groupRegistration.manifest.authDisabled, }; manifests.push(componentManifest); } return manifests; }; this.clearState = () => { ManifestGroupRegistry.ManifestGroupRegistrations = {}; ManifestGroupRegistry._registeredManifestProvider = false; }; } } exports.ManifestGroupRegistry = ManifestGroupRegistry; ManifestGroupRegistry.ManifestGroupRegistrations = {}; ManifestGroupRegistry._registeredManifestProvider = false; ManifestGroupRegistry.registerManifestGroup = (manifest, groupOptions) => { ManifestGroupRegistry.ensureCorrectManifest(manifest); if (!groupOptions) { throw new Error("Can't register component with missing groupOptions"); } if (!groupOptions.webComponentManifestIds) { groupOptions.webComponentManifestIds = []; } if (!groupOptions.resourceManifestIds) { groupOptions.resourceManifestIds = []; } if (groupOptions.webComponentManifestIds.length <= 0 && groupOptions.resourceManifestIds.length <= 0) { throw new Error("Can't register manifest group with missing mandatory attributes, select either webcomponents or resources to include in group: " + JSON.stringify(groupOptions)); } if (ManifestGroupRegistry.ManifestGroupRegistrations[manifest.resourceId]) { throw new Error("Can't re-register resource manifest group on manifest with id: " + manifest.resourceId + " current info: " + JSON.stringify(ManifestGroupRegistry.ManifestGroupRegistrations[manifest.resourceId])); } try { ManifestGroupRegistry.ManifestGroupRegistrations[manifest.resourceId] = new ManifestGroupRegistration(groupOptions, ManifestRegistry_1.ManifestRegistry.getCurrentManifestPath(), manifest); } catch (e) { ManifestGroupRegistry.ManifestGroupRegistrations[manifest.resourceId] = null; } }; ManifestGroupRegistry.newCombinedRules = (manifest, rules) => { if (rules) { ManifestGroupRegistry.ensureCorrectManifest(manifest); Utils_1.Utils.validateSupportedLoadRuleTypes(rules); let registration = ManifestGroupRegistry.ManifestGroupRegistrations[manifest.resourceId]; if (registration != null) { registration.loadRules = rules; } else { throw new Error("Can't add load rules for component group manifest with id: " + manifest.resourceId + " a component group has not been registered"); } } }; ManifestGroupRegistry.getManifestGroupRegistrations = () => { let registrations = {}; for (let key in ManifestGroupRegistry.ManifestGroupRegistrations) { registrations[key] = ManifestGroupRegistry.ManifestGroupRegistrations[key]; } return registrations; }; ManifestGroupRegistry.getRegistrations = () => { let groupRegistrations = []; for (let key in ManifestGroupRegistry.ManifestGroupRegistrations) { let groupRegistration = ManifestGroupRegistry.ManifestGroupRegistrations[key]; for (let webComponentManifestIdToInclude of groupRegistration.manifestGroupOptions.webComponentManifestIds) { let registeredManifest = LoadableManifestRegistry_1.LoadableManifestRegistry.getRegisteredManifest(webComponentManifestIdToInclude); if (!registeredManifest) { throw new Error("Error, manifest: " + groupRegistration.manifestPath + " is referencing manifest id: " + webComponentManifestIdToInclude + " which has not been registered."); } if (registeredManifest.manifestType != Enums_1.ClientManifestTypes.Component) { throw new Error("Error, manifest: " + groupRegistration.manifestPath + " is adding manifest id: " + webComponentManifestIdToInclude + " as a web component to group manifest, but it's not of webcomponent type."); } } for (let resourceManifestIdToInclude of groupRegistration.manifestGroupOptions.resourceManifestIds) { let registeredManifest = LoadableManifestRegistry_1.LoadableManifestRegistry.getRegisteredManifest(resourceManifestIdToInclude); if (!registeredManifest) { throw new Error("Error, manifest: " + groupRegistration.manifestPath + " is referencing manifest id: " + resourceManifestIdToInclude + " which has not been registered."); } if (registeredManifest.manifestType != Enums_1.ClientManifestTypes.Resource) { throw new Error("Error, manifest: " + groupRegistration.manifestPath + " is adding manifest id: " + resourceManifestIdToInclude + " as a resource to group manifest, but it's not of rescource type."); } } groupRegistrations.push({ resourceId: groupRegistration.manifest.resourceId, resourceName: groupRegistration.manifest.resourceName, manifestIdsInGroup: groupRegistration.manifestGroupOptions.webComponentManifestIds.concat(groupRegistration.manifestGroupOptions.resourceManifestIds), }); } if (!ManifestGroupRegistry._registeredManifestProvider) { ManifestGroupRegistry._registeredManifestProvider = true; LoadableManifestRegistry_1.LoadableManifestRegistry.registerManifestProvider(new ManifestGroupRegistry()); } return groupRegistrations; }; ManifestGroupRegistry.ensureCorrectManifest = (manifest) => { if (!manifest || !manifest.manifestType || manifest.manifestType !== Enums_1.ClientManifestTypes.ManifestGroup) { throw new Error("Manifest :" + JSON.stringify(manifest) + " can't be used as component manifest. Mandatory properties maybe missing or the manifest is not of component type"); } manifest.resourceId = Utils_1.Utils.ensureValidManifestId(manifest.resourceId); }; ManifestGroupRegistry.clearManifestGroupRegistrations = () => { ManifestGroupRegistry.ManifestGroupRegistrations = {}; }; ManifestGroupRegistry.ServerSubscription = ManifestRegistry_1.ManifestRegistry.registerServerManifestProvider(new ManifestRegistry_1.StaticServerManifestProviderProxy(() => { return new Array(); }, ManifestGroupRegistry.clearManifestGroupRegistrations));