@aws-amplify/appsync-modelgen-plugin
Version:
51 lines • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.containsGenerationDirective = exports.containsConversationDirective = exports.getModelPrimaryKeyComponentFields = exports.getOtherSideBelongsToField = exports.toCamelCase = exports.getDirectives = exports.getDirective = exports.removeFieldFromModel = exports.addFieldToModel = void 0;
const constants_1 = require("./constants");
function addFieldToModel(model, field) {
const existingField = model.fields.find(f => f.name === field.name);
if (!existingField) {
model.fields.push(field);
}
}
exports.addFieldToModel = addFieldToModel;
function removeFieldFromModel(model, fieldName) {
model.fields = model.fields.filter(field => field.name !== fieldName);
}
exports.removeFieldFromModel = removeFieldFromModel;
const getDirective = (fieldOrModel) => (directiveName) => fieldOrModel.directives.find(d => d.name === directiveName);
exports.getDirective = getDirective;
const getDirectives = (fieldOrModel) => (directiveName) => fieldOrModel.directives.filter(d => d.name === directiveName);
exports.getDirectives = getDirectives;
function toCamelCase(words) {
const formatted = words.map((w, i) => (i === 0 ? w.charAt(0).toLowerCase() + w.slice(1) : w.charAt(0).toUpperCase() + w.slice(1)));
return formatted.join('');
}
exports.toCamelCase = toCamelCase;
function getOtherSideBelongsToField(type, otherSideModel) {
return otherSideModel.fields.filter(f => f.type === type).find(f => f.directives.find(d => d.name === constants_1.TransformerV2DirectiveName.BELONGS_TO));
}
exports.getOtherSideBelongsToField = getOtherSideBelongsToField;
function getModelPrimaryKeyComponentFields(model) {
var _a;
const primaryKeyField = model.fields.find(field => field.primaryKeyInfo);
const keyFields = [];
if (primaryKeyField) {
keyFields.push(primaryKeyField);
if ((_a = primaryKeyField === null || primaryKeyField === void 0 ? void 0 : primaryKeyField.primaryKeyInfo) === null || _a === void 0 ? void 0 : _a.sortKeyFields) {
keyFields.push(...primaryKeyField.primaryKeyInfo.sortKeyFields);
}
;
}
return keyFields;
}
exports.getModelPrimaryKeyComponentFields = getModelPrimaryKeyComponentFields;
function containsConversationDirective(queryField) {
return queryField.directives.some((directive) => directive.name === constants_1.TransformerV2DirectiveName.CONVERSATION);
}
exports.containsConversationDirective = containsConversationDirective;
function containsGenerationDirective(queryField) {
return queryField.directives.some((directive) => directive.name === constants_1.TransformerV2DirectiveName.GENERATION);
}
exports.containsGenerationDirective = containsGenerationDirective;
//# sourceMappingURL=fieldUtils.js.map