UNPKG

@aws-amplify/graphql-transformer-core

Version:

A framework to transform from GraphQL SDL to AWS CloudFormation.

86 lines 6.02 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _TransformerResourceHelper_modelNameMap, _TransformerResourceHelper_modelFieldMaps; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransformerResourceHelper = void 0; const aws_cdk_lib_1 = require("aws-cdk-lib"); const graphql_transformer_common_1 = require("graphql-transformer-common"); const md5_1 = __importDefault(require("md5")); const model_field_map_1 = require("./model-field-map"); class TransformerResourceHelper { constructor(synthParameters) { this.synthParameters = synthParameters; this.exclusionSet = new Set(); _TransformerResourceHelper_modelNameMap.set(this, new Map()); _TransformerResourceHelper_modelFieldMaps.set(this, new Map()); this.generateTableName = (modelName) => { var _a; if (!this.api) { throw new Error('API not initialized'); } const env = this.synthParameters.amplifyEnvironmentName; const { apiId } = this.api; const baseName = (_a = __classPrivateFieldGet(this, _TransformerResourceHelper_modelNameMap, "f").get(modelName)) !== null && _a !== void 0 ? _a : modelName; return `${baseName}-${apiId}-${env}`; }; this.generateIAMRoleName = (name) => { if (!this.api) { throw new Error('API not initialized'); } const env = this.synthParameters.amplifyEnvironmentName; const { apiId } = this.api; const shortName = `${aws_cdk_lib_1.Token.isUnresolved(name) ? name : name.slice(0, 64 - 38 - 6)}${(0, md5_1.default)(name).slice(0, 6)}`; return `${shortName}-${apiId}-${env}`; }; this.setModelNameMapping = (modelName, mappedName) => { __classPrivateFieldGet(this, _TransformerResourceHelper_modelNameMap, "f").set(modelName, mappedName); }; this.getModelNameMapping = (modelName) => { var _a; return (_a = __classPrivateFieldGet(this, _TransformerResourceHelper_modelNameMap, "f").get(modelName)) !== null && _a !== void 0 ? _a : modelName; }; this.isModelRenamed = (modelName) => this.getModelNameMapping(modelName) !== modelName; this.getModelFieldMap = (modelName) => { if (!__classPrivateFieldGet(this, _TransformerResourceHelper_modelFieldMaps, "f").has(modelName)) { __classPrivateFieldGet(this, _TransformerResourceHelper_modelFieldMaps, "f").set(modelName, new model_field_map_1.ModelFieldMapImpl()); } return __classPrivateFieldGet(this, _TransformerResourceHelper_modelFieldMaps, "f").get(modelName); }; this.getFieldNameMapping = (modelName, fieldName) => { var _a, _b; if (!__classPrivateFieldGet(this, _TransformerResourceHelper_modelFieldMaps, "f").has(modelName)) { return fieldName; } return (((_b = (_a = __classPrivateFieldGet(this, _TransformerResourceHelper_modelFieldMaps, "f") .get(modelName)) === null || _a === void 0 ? void 0 : _a.getMappedFields().find((entry) => entry.currentFieldName === fieldName)) === null || _b === void 0 ? void 0 : _b.originalFieldName) || fieldName); }; this.getModelFieldMapKeys = () => [...__classPrivateFieldGet(this, _TransformerResourceHelper_modelFieldMaps, "f").keys()]; this.addDirectiveConfigExclusion = (object, field, directive) => { this.exclusionSet.add(this.convertDirectiveConfigToKey(object, field, directive)); }; this.isDirectiveConfigExcluded = (object, field, directive) => { return this.exclusionSet.has(this.convertDirectiveConfigToKey(object, field, directive)); }; this.convertDirectiveConfigToKey = (object, field, directive) => { var _a, _b, _c, _d; const argString = (_b = (_a = directive === null || directive === void 0 ? void 0 : directive.arguments) === null || _a === void 0 ? void 0 : _a.map((arg) => { var _a, _b, _c, _d; return `${(_a = arg === null || arg === void 0 ? void 0 : arg.name) === null || _a === void 0 ? void 0 : _a.value}|${((_b = arg === null || arg === void 0 ? void 0 : arg.value) === null || _b === void 0 ? void 0 : _b.kind) === 'StringValue' || ((_c = arg === null || arg === void 0 ? void 0 : arg.value) === null || _c === void 0 ? void 0 : _c.kind) === 'IntValue' || ((_d = arg === null || arg === void 0 ? void 0 : arg.value) === null || _d === void 0 ? void 0 : _d.kind) === 'FloatValue' ? arg.value.value : 'NullValue'}`; })) === null || _b === void 0 ? void 0 : _b.join('-'); return `${object.name.value}/${(_d = (_c = field === null || field === void 0 ? void 0 : field.name) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 'NullField'}/${directive.name.value}/${argString}`; }; graphql_transformer_common_1.ModelResourceIDs.setModelNameMap(__classPrivateFieldGet(this, _TransformerResourceHelper_modelNameMap, "f")); } bind(api) { this.api = api; } } exports.TransformerResourceHelper = TransformerResourceHelper; _TransformerResourceHelper_modelNameMap = new WeakMap(), _TransformerResourceHelper_modelFieldMaps = new WeakMap(); //# sourceMappingURL=resource-helper.js.map