@vulcan-sql/core
Version:
Core package of VulcanSQL
54 lines • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NunjucksExecutionMetadata = exports.ReservedContextKeys = void 0;
exports.ReservedContextKeys = {
CurrentProfileName: 'RESERVED_CURRENT_PROFILE_NAME',
};
/** A helper class to manage metadata while executing templates, e.g. parameters, profile ...etc. */
class NunjucksExecutionMetadata {
constructor({ parameters = {}, profileName, user, req, headers, }) {
this.parameters = parameters;
this.profileName = profileName;
this.userInfo = user;
this.req = req;
this.headers = headers;
}
/** Load from nunjucks context */
static load(context) {
var _a, _b, _c, _d;
return new NunjucksExecutionMetadata({
parameters: ((_a = context.lookup('context')) === null || _a === void 0 ? void 0 : _a.params) || {},
user: ((_b = context.lookup('context')) === null || _b === void 0 ? void 0 : _b.user) || {},
req: ((_c = context.lookup('context')) === null || _c === void 0 ? void 0 : _c.req) || {},
headers: ((_d = context.lookup('context')) === null || _d === void 0 ? void 0 : _d.headers) || {},
profileName: context.lookup(exports.ReservedContextKeys.CurrentProfileName),
});
}
/** Dump to a pure object */
dump() {
return {
context: {
params: this.parameters,
user: this.userInfo,
req: this.req,
profile: this.profileName,
headers: this.headers,
},
[exports.ReservedContextKeys.CurrentProfileName]: this.profileName,
};
}
getProfileName() {
return this.profileName;
}
getUserInfo() {
return this.userInfo;
}
getRequest() {
return this.req;
}
getHeaders() {
return this.headers;
}
}
exports.NunjucksExecutionMetadata = NunjucksExecutionMetadata;
//# sourceMappingURL=nunjucksExecutionMetadata.js.map