text: "use strict";
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
      if (k2 === undefined) k2 = k;
      Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  }) : (function(o, m, k, k2) {
      if (k2 === undefined) k2 = k;
      o[k2] = m[k];
  }));
  var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
      Object.defineProperty(o, "default", { enumerable: true, value: v });
  }) : function(o, v) {
      o["default"] = v;
  });
  var __importStar = (this && this.__importStar) || function (mod) {
      if (mod && mod.__esModule) return mod;
      var result = {};
      if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
      __setModuleDefault(result, mod);
      return result;
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.MappingTemplate = exports.InlineTemplate = exports.S3MappingTemplate = exports.S3MappingFunctionCode = void 0;
  const crypto = __importStar(require("crypto"));
  const graphql_transformer_interfaces_1 = require("@aws-amplify/graphql-transformer-interfaces");
  const file_asset_1 = require("./file-asset");
  const fs = __importStar(require("fs-extra"));
  class S3MappingFunctionCode {
      constructor(fileName, filePath) {
          this.type = graphql_transformer_interfaces_1.MappingTemplateType.S3_LOCATION;
          this.fileName = fileName;
          this.filePath = filePath;
      }
      bind(scope) {
          if (!this.asset) {
              this.asset = new file_asset_1.FileAsset(scope, `Code${this.fileName}`, {
                  fileContent: this.filePath,
                  fileName: this.fileName,
              });
          }
          return this.asset;
      }
  }
  exports.S3MappingFunctionCode = S3MappingFunctionCode;
  class S3MappingTemplate {
      constructor(content, name) {
          this.type = graphql_transformer_interfaces_1.MappingTemplateType.S3_LOCATION;
          this.content = content;
          const assetHash = crypto.createHash('sha256').update(content).digest('hex');
          this.name = name || `mapping-template-${assetHash}.vtl`;
      }
      static fromFile(name, path) {
          const fileContents = fs.readFileSync(path, { encoding: 'utf-8' });
          return new S3MappingTemplate(fileContents, name);
      }
      static fromInlineTemplate(code, templateName) {
          return new S3MappingTemplate(code, templateName);
      }
      bind(scope) {
          if (!this.asset) {
              this.asset = new file_asset_1.FileAsset(scope, `Template${this.name}`, {
                  fileContent: this.content,
                  fileName: this.name,
              });
          }
          return this.asset.s3Url;
      }
      substitueValues(values) {
          let name = this.name;
          Object.entries(values).forEach(([key, value]) => {
              const regex = new RegExp(`({${key}})`, 'g');
              name = name.replace(regex, `${value}`);
          });
          this.name = name;
      }
  }
  exports.S3MappingTemplate = S3MappingTemplate;
  class InlineTemplate {
      constructor(content) {
          this.content = content;
          this.type = graphql_transformer_interfaces_1.MappingTemplateType.INLINE;
      }
      bind() {
          return this.content;
      }
  }
  exports.InlineTemplate = InlineTemplate;
  class MappingTemplate {
      static inlineTemplateFromString(template) {
          return new InlineTemplate(template);
      }
      static s3MappingTemplateFromString(template, templateName, type = 'pipeline') {
          const templatePrefix = type == 'pipeline' ? 'pipelineFunctions' : 'resolvers';
          return new S3MappingTemplate(template, `${templatePrefix}/${templateName}`);
      }
  }
  exports.MappingTemplate = MappingTemplate;
  //# sourceMappingURL=template-asset.js.map