@omnia/tooling-composers
Version:
Provide tooling to work with manifest things.
58 lines (57 loc) • 2.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComposerBase = void 0;
const CombinableRuleComposer_1 = require("./CombinableRuleComposer");
const LoadableManifestRegistry_1 = require("./LoadableManifestRegistry");
const ResourceRegistry_1 = require("./ResourceRegistry");
const Utils_1 = require("./Utils");
class ComposerBase {
constructor() {
this.registerApi = (exp, configuration) => {
let apiPath = null;
if (typeof exp === "string") {
apiPath = exp;
this.manifest.api = this.manifest.api || [];
this.manifest.api.push(exp);
this.manifest.api = Array.from(new Set(this.manifest.api));
}
else {
apiPath = Utils_1.Utils.getPropertyPathInExpression(exp)[0];
this.manifest.api = Array.from(new Set((this.manifest.api || []).concat([apiPath])));
}
if (configuration) {
this.manifest.registerApiConfiguration = this.manifest.registerApiConfiguration || Object.create(null);
this.manifest.registerApiConfiguration[apiPath] = configuration;
}
LoadableManifestRegistry_1.LoadableManifestRegistry.registerManifest(this.manifest);
return this;
};
this.extendApi = (exp, expRules) => {
if (expRules) {
expRules(new CombinableRuleComposer_1.CombinableRuleComposer((rules) => {
ResourceRegistry_1.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(this.manifest.extendApi));
}
else {
const apiResult = Utils_1.Utils.getPropertyPathAndConfigurationInExpression(exp);
this.manifest.extendApi = Array.from(new Set((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_1.LoadableManifestRegistry.registerManifest(this.manifest);
return this;
};
this.disableAuth = () => {
this.manifest.authDisabled = true;
return this;
};
}
}
exports.ComposerBase = ComposerBase;