import { ComponentPlugin, ComponentPluginFactory, ChunkDefinition, ChunkType, FileType, UIDLDataSource, UIDLStateDefinition, UIDLStateDataSourceBinding, UIDLFilterConfigEntry, } from '@teleporthq/teleport-types' import { GenericUtils, PageAccess, PageArrival, StringUtils, TableAccess, } from '@teleporthq/teleport-shared' import { RouteUtils } from '@teleporthq/teleport-plugin-common' import * as types from '@babel/types' import { generateDataSourceFetcherWithCore, generateRawQueryFetcher, generateSafeFileName, sanitizeFileName, validateDataSourceConfig, buildProductTransformOptions, buildServerLocaleParam, isLocalizedProject, } from '@teleporthq/teleport-plugin-next-data-source' import { CsvColumnLabel, getCsvColumnLabels, isSelectOnlyQuery, } from './global-state/data-source-utils' const { stateQueryHasTemplatePlaceholder } = RouteUtils interface ParallelFetchMeta { names: string[] expressions: types.Expression[] declaration?: types.VariableDeclaration } /** * Generates a safe fetch expression wrapped with .catch() for error handling. * Falls back to the provided defaultValue on error. */ const createSafeFetchExpressionWithFallback = ( fetchCallExpression: types.CallExpression, label: string, defaultValue: types.Expression ): types.Expression => { const errorIdentifier = types.identifier('error') const catchHandler = types.arrowFunctionExpression( [errorIdentifier], types.blockStatement([ types.expressionStatement( types.callExpression( types.memberExpression(types.identifier('console'), types.identifier('error')), [types.stringLiteral(`Error fetching state "${label}":`), errorIdentifier] ) ), types.returnStatement(defaultValue), ]) ) return types.callExpression( types.memberExpression(fetchCallExpression, types.identifier('catch')), [catchHandler] ) } /** * `.then((__rows) => Array.isArray(__rows) ? __rows.map((__row) => ({