@sprucelabs/spruce-templates
Version:
Templates used for code generation in skills!
38 lines (37 loc) • 2.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const schema_1 = require("@sprucelabs/schema");
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
const handlebars_1 = __importDefault(require("handlebars"));
/* The type for the value of a field. the special case is if the field is of type schema, then we get the target's interface */
handlebars_1.default.registerHelper('valueTypeLiteral', function (namespace, nameCamel, version, fieldName, renderAs, options) {
var _a, _b, _c, _d;
if (!namespace) {
throw new Error('valueTypeLiteral needs namespace as 1st argument');
}
if (!nameCamel) {
throw new Error('valueTypeLiteral needs nameCamel as 2st argument');
}
if (!fieldName) {
throw new Error('valueTypeLiteral needs fieldName as 3st argument');
}
if (renderAs !== schema_1.TemplateRenderAs.Value &&
renderAs !== schema_1.TemplateRenderAs.Type &&
renderAs !== schema_1.TemplateRenderAs.SchemaType) {
throw new Error('valueTypeLiteral helper needs renderAs to be "TemplateRenderAs.Type" or "TemplateRenderAs.Value" or "TemplateRenderAs.schemaType"');
}
const { data: { root }, } = options;
const valueTypes = root === null || root === void 0 ? void 0 : root.valueTypes;
if (!valueTypes) {
throw new Error('valueTypeLiteral helper needs a valuesTypes in the root context');
}
const v = version ? version : spruce_skill_utils_1.SCHEMA_VERSION_FALLBACK;
const valueType = (_d = (_c = (_b = (_a = valueTypes[namespace]) === null || _a === void 0 ? void 0 : _a[nameCamel]) === null || _b === void 0 ? void 0 : _b[v]) === null || _c === void 0 ? void 0 : _c[fieldName]) === null || _d === void 0 ? void 0 : _d.valueTypes[renderAs];
if (!valueType) {
throw new Error(`Unable to render value type for field "${namespace}.${nameCamel}.${v}.${fieldName}"`);
}
return valueType;
});