UNPKG

aws-sdk-js-codemod

Version:

Collection of codemod scripts that help update AWS SDK for JavaScript APIs

42 lines (41 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getV3ClientTypes = void 0; const config_1 = require("../config"); const getClientTypeNames_1 = require("./getClientTypeNames"); const arrayBracketRegex = /<([\w]+)>/g; const recordBracketRegex = /<string, ([\w]+)>/g; const nativeTypes = ["string", "number", "boolean", "Date", "Uint8Array"]; const getTypesFromString = (str) => { const arraryMatches = [...str.matchAll(arrayBracketRegex)].map((match) => match[1]); const recordMatches = [...str.matchAll(recordBracketRegex)].map((match) => match[1]); return [...arraryMatches, ...recordMatches].sort(); }; const getV3ClientTypes = (j, source, options) => { const { v2ClientName } = options; const clientTypeNames = (0, getClientTypeNames_1.getClientTypeNames)(j, source, options); const clientTypesMap = config_1.CLIENT_TYPES_MAP[v2ClientName]; const v3ClientUnavailableTypes = Object.keys(clientTypesMap).filter((item) => item !== "ClientConfiguration"); const clientReqRespTypesMap = config_1.CLIENT_REQ_RESP_TYPES_MAP[v2ClientName]; return clientTypeNames .filter((clientTypeName) => { if (!v3ClientUnavailableTypes.includes(clientTypeName)) { return true; } const typesFromString = getTypesFromString(clientTypesMap[clientTypeName]); return typesFromString.some((type) => !nativeTypes.includes(type)); }) .flatMap((clientTypeName) => { if (clientTypeName === "ClientConfiguration") { return clientTypesMap[clientTypeName]; } if (Object.keys(clientReqRespTypesMap).includes(clientTypeName)) { return clientReqRespTypesMap[clientTypeName]; } if (Object.keys(clientTypesMap).includes(clientTypeName)) { return getTypesFromString(clientTypesMap[clientTypeName]); } return clientTypeName; }); }; exports.getV3ClientTypes = getV3ClientTypes;