@teleporthq/teleport-plugin-next-data-source 0.42.1 → 0.42.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/cjs/count-fetchers.d.ts.map +1 -1
  2. package/dist/cjs/count-fetchers.js +1 -1
  3. package/dist/cjs/count-fetchers.js.map +1 -1
  4. package/dist/cjs/fetchers/clickhouse.d.ts.map +1 -1
  5. package/dist/cjs/fetchers/clickhouse.js +1 -1
  6. package/dist/cjs/fetchers/clickhouse.js.map +1 -1
  7. package/dist/cjs/fetchers/firestore.d.ts.map +1 -1
  8. package/dist/cjs/fetchers/firestore.js +1 -1
  9. package/dist/cjs/fetchers/firestore.js.map +1 -1
  10. package/dist/cjs/fetchers/javascript.d.ts.map +1 -1
  11. package/dist/cjs/fetchers/javascript.js +1 -1
  12. package/dist/cjs/fetchers/javascript.js.map +1 -1
  13. package/dist/cjs/fetchers/redshift.d.ts.map +1 -1
  14. package/dist/cjs/fetchers/redshift.js +3 -1
  15. package/dist/cjs/fetchers/redshift.js.map +1 -1
  16. package/dist/cjs/fetchers/rest-api.d.ts.map +1 -1
  17. package/dist/cjs/fetchers/rest-api.js +2 -2
  18. package/dist/cjs/fetchers/rest-api.js.map +1 -1
  19. package/dist/cjs/fetchers/turso.d.ts.map +1 -1
  20. package/dist/cjs/fetchers/turso.js +1 -1
  21. package/dist/cjs/fetchers/turso.js.map +1 -1
  22. package/dist/cjs/pagination-plugin.d.ts.map +1 -1
  23. package/dist/cjs/pagination-plugin.js +180 -131
  24. package/dist/cjs/pagination-plugin.js.map +1 -1
  25. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  26. package/dist/esm/count-fetchers.d.ts.map +1 -1
  27. package/dist/esm/count-fetchers.js +1 -1
  28. package/dist/esm/count-fetchers.js.map +1 -1
  29. package/dist/esm/fetchers/clickhouse.d.ts.map +1 -1
  30. package/dist/esm/fetchers/clickhouse.js +1 -1
  31. package/dist/esm/fetchers/clickhouse.js.map +1 -1
  32. package/dist/esm/fetchers/firestore.d.ts.map +1 -1
  33. package/dist/esm/fetchers/firestore.js +1 -1
  34. package/dist/esm/fetchers/firestore.js.map +1 -1
  35. package/dist/esm/fetchers/javascript.d.ts.map +1 -1
  36. package/dist/esm/fetchers/javascript.js +1 -1
  37. package/dist/esm/fetchers/javascript.js.map +1 -1
  38. package/dist/esm/fetchers/redshift.d.ts.map +1 -1
  39. package/dist/esm/fetchers/redshift.js +3 -1
  40. package/dist/esm/fetchers/redshift.js.map +1 -1
  41. package/dist/esm/fetchers/rest-api.d.ts.map +1 -1
  42. package/dist/esm/fetchers/rest-api.js +2 -2
  43. package/dist/esm/fetchers/rest-api.js.map +1 -1
  44. package/dist/esm/fetchers/turso.d.ts.map +1 -1
  45. package/dist/esm/fetchers/turso.js +1 -1
  46. package/dist/esm/fetchers/turso.js.map +1 -1
  47. package/dist/esm/pagination-plugin.d.ts.map +1 -1
  48. package/dist/esm/pagination-plugin.js +180 -131
  49. package/dist/esm/pagination-plugin.js.map +1 -1
  50. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +2 -2
  52. package/src/count-fetchers.ts +2 -1
  53. package/src/fetchers/clickhouse.ts +12 -6
  54. package/src/fetchers/firestore.ts +45 -13
  55. package/src/fetchers/javascript.ts +48 -13
  56. package/src/fetchers/redshift.ts +32 -9
  57. package/src/fetchers/rest-api.ts +68 -6
  58. package/src/fetchers/turso.ts +46 -16
  59. package/src/pagination-plugin.ts +336 -266
@@ -75,7 +75,7 @@ var array_mapper_pagination_1 = require("./array-mapper-pagination");
75
75
  var utils_1 = require("./utils");
76
76
  var createNextArrayMapperPaginationPlugin = function () {
77
77
  var paginationPlugin = function (structure) { return __awaiter(void 0, void 0, void 0, function () {
78
- var uidl, chunks, dependencies, options, componentChunk, variableDeclaration, declarator, arrowFunction, blockStatement, _a, paginatedMappers, searchOnlyMappers, paginationOnlyMappers, detectedPaginations, detectedSearchOnly, paginationInfos, getStaticPropsChunk, isPage, isComponent, opts, perPageMap, searchConfigMap, queryColumnsMap, hasSearchEnabled, firstReturnIndex, insertIndex, dataSourceToInfos_1, searchOnlyDataSources;
78
+ var uidl, chunks, dependencies, options, componentChunk, variableDeclaration, declarator, arrowFunction, blockStatement, _a, paginatedMappers, searchOnlyMappers, paginationOnlyMappers, detectedPaginations, detectedSearchOnly, paginationInfos, getStaticPropsChunk, isPage, isComponent, opts, perPageMap, searchConfigMap, queryColumnsMap, stateDeclarations, hasSearchEnabled, firstReturnIndex, insertIndex, dataSourceToInfos_1, componentUseEffects_1, componentReturnIndex, componentEffectsInsertIndex_1, searchOnlyDataSources;
79
79
  var _b, _c, _d;
80
80
  return __generator(this, function (_e) {
81
81
  uidl = structure.uidl, chunks = structure.chunks, dependencies = structure.dependencies, options = structure.options;
@@ -159,6 +159,7 @@ var createNextArrayMapperPaginationPlugin = function () {
159
159
  perPageMap = ((_b = opts.paginationConfig) === null || _b === void 0 ? void 0 : _b.perPageMap) || new Map();
160
160
  searchConfigMap = ((_c = opts.paginationConfig) === null || _c === void 0 ? void 0 : _c.searchConfigMap) || new Map();
161
161
  queryColumnsMap = ((_d = opts.paginationConfig) === null || _d === void 0 ? void 0 : _d.queryColumnsMap) || new Map();
162
+ stateDeclarations = [];
162
163
  detectedPaginations.forEach(function (detected, index) {
163
164
  var paginationNodeId = "pg_".concat(index);
164
165
  // Use arrayMapperRenderProp if available, otherwise fall back to dataSourceIdentifier
@@ -169,6 +170,37 @@ var createNextArrayMapperPaginationPlugin = function () {
169
170
  var queryColumns = queryColumnsMap.get(detected.dataSourceIdentifier);
170
171
  var info = (0, array_mapper_pagination_1.generatePaginationLogic)(paginationNodeId, detected.dataSourceIdentifier, perPage, searchConfig, queryColumns);
171
172
  paginationInfos.push(info);
173
+ // Add refs to track first render for each useEffect (add first)
174
+ if (info.searchEnabled) {
175
+ var skipCountFetchOnMountRefVar = "skipCountFetchOnMount_pg_".concat(index);
176
+ var skipCountFetchRefAST = types.variableDeclaration('const', [
177
+ types.variableDeclarator(types.identifier(skipCountFetchOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
178
+ ]);
179
+ stateDeclarations.push(skipCountFetchRefAST);
180
+ info.skipCountFetchOnMountRefVar = skipCountFetchOnMountRefVar;
181
+ var skipDebounceOnMountRefVar = "skipDebounceOnMount_pg_".concat(index);
182
+ var skipDebounceRefAST = types.variableDeclaration('const', [
183
+ types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
184
+ ]);
185
+ stateDeclarations.push(skipDebounceRefAST);
186
+ info.skipDebounceOnMountRefVar = skipDebounceOnMountRefVar;
187
+ }
188
+ // Add maxPages state
189
+ var maxPagesStateVar = "".concat(info.pageStateVar.replace('_page', ''), "_maxPages");
190
+ var setMaxPagesStateVar = "set".concat(maxPagesStateVar.charAt(0).toUpperCase() + maxPagesStateVar.slice(1));
191
+ // For pages: initialize from props (with pagination-specific prop name), for components: initialize to 0
192
+ var maxPagesInitValue = isPage
193
+ ? types.logicalExpression('||', types.optionalMemberExpression(types.identifier('props'), types.identifier("".concat(info.dataSourceIdentifier, "_pg_").concat(index, "_maxPages")), false, true), types.numericLiteral(0))
194
+ : types.numericLiteral(0);
195
+ var maxPagesStateAST = types.variableDeclaration('const', [
196
+ types.variableDeclarator(types.arrayPattern([
197
+ types.identifier(maxPagesStateVar),
198
+ types.identifier(setMaxPagesStateVar),
199
+ ]), types.callExpression(types.identifier('useState'), [maxPagesInitValue])),
200
+ ]);
201
+ stateDeclarations.push(maxPagesStateAST);
202
+ info.maxPagesStateVar = maxPagesStateVar;
203
+ info.setMaxPagesStateVar = setMaxPagesStateVar;
172
204
  // If both pagination and search are enabled, combine them into a single state object
173
205
  if (info.searchEnabled && info.searchQueryVar && info.setSearchQueryVar) {
174
206
  // Combined state: { page: 1, debouncedQuery: '' }
@@ -185,7 +217,7 @@ var createNextArrayMapperPaginationPlugin = function () {
185
217
  ]),
186
218
  ])),
187
219
  ]);
188
- blockStatement.body.unshift(combinedStateAST);
220
+ stateDeclarations.push(combinedStateAST);
189
221
  // Still need the immediate search query state for the input
190
222
  var searchStateAST = types.variableDeclaration('const', [
191
223
  types.variableDeclarator(types.arrayPattern([
@@ -193,7 +225,7 @@ var createNextArrayMapperPaginationPlugin = function () {
193
225
  types.identifier(info.setSearchQueryVar),
194
226
  ]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
195
227
  ]);
196
- blockStatement.body.unshift(searchStateAST);
228
+ stateDeclarations.push(searchStateAST);
197
229
  info.combinedStateVar = combinedStateVar;
198
230
  info.setCombinedStateVar = setCombinedStateVar;
199
231
  }
@@ -205,40 +237,13 @@ var createNextArrayMapperPaginationPlugin = function () {
205
237
  types.identifier(info.setPageStateVar),
206
238
  ]), types.callExpression(types.identifier('useState'), [types.numericLiteral(1)])),
207
239
  ]);
208
- blockStatement.body.unshift(pageStateAST);
209
- }
210
- // Add maxPages state
211
- var maxPagesStateVar = "".concat(info.pageStateVar.replace('_page', ''), "_maxPages");
212
- var setMaxPagesStateVar = "set".concat(maxPagesStateVar.charAt(0).toUpperCase() + maxPagesStateVar.slice(1));
213
- // For pages: initialize from props (with pagination-specific prop name), for components: initialize to 0
214
- var maxPagesInitValue = isPage
215
- ? types.logicalExpression('||', types.optionalMemberExpression(types.identifier('props'), types.identifier("".concat(info.dataSourceIdentifier, "_pg_").concat(index, "_maxPages")), false, true), types.numericLiteral(0))
216
- : types.numericLiteral(0);
217
- var maxPagesStateAST = types.variableDeclaration('const', [
218
- types.variableDeclarator(types.arrayPattern([
219
- types.identifier(maxPagesStateVar),
220
- types.identifier(setMaxPagesStateVar),
221
- ]), types.callExpression(types.identifier('useState'), [maxPagesInitValue])),
222
- ]);
223
- blockStatement.body.unshift(maxPagesStateAST);
224
- info.maxPagesStateVar = maxPagesStateVar;
225
- info.setMaxPagesStateVar = setMaxPagesStateVar;
226
- // Add refs to track first render for each useEffect
227
- if (info.searchEnabled) {
228
- var skipDebounceOnMountRefVar = "skipDebounceOnMount_pg_".concat(index);
229
- var skipDebounceRefAST = types.variableDeclaration('const', [
230
- types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
231
- ]);
232
- blockStatement.body.unshift(skipDebounceRefAST);
233
- info.skipDebounceOnMountRefVar = skipDebounceOnMountRefVar;
234
- var skipCountFetchOnMountRefVar = "skipCountFetchOnMount_pg_".concat(index);
235
- var skipCountFetchRefAST = types.variableDeclaration('const', [
236
- types.variableDeclarator(types.identifier(skipCountFetchOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
237
- ]);
238
- blockStatement.body.unshift(skipCountFetchRefAST);
239
- info.skipCountFetchOnMountRefVar = skipCountFetchOnMountRefVar;
240
+ stateDeclarations.push(pageStateAST);
240
241
  }
241
242
  });
243
+ // Add all state declarations at once to the beginning in correct order
244
+ stateDeclarations.reverse().forEach(function (stateDecl) {
245
+ blockStatement.body.unshift(stateDecl);
246
+ });
242
247
  hasSearchEnabled = paginationInfos.some(function (info) { return info.searchEnabled; });
243
248
  if (hasSearchEnabled && !dependencies.useEffect) {
244
249
  dependencies.useEffect = {
@@ -288,74 +293,75 @@ var createNextArrayMapperPaginationPlugin = function () {
288
293
  ]));
289
294
  blockStatement.body.splice(insertIndex, 0, debounceEffect);
290
295
  // Add useEffect to refetch count when search changes (for both pages and components)
291
- if (info.queryColumns && info.queryColumns.length > 0) {
292
- var detected = detectedPaginations.find(function (d) { return d.dataSourceIdentifier === info.dataSourceIdentifier; });
293
- if (!detected) {
294
- return;
295
- }
296
- var resourceDefAttr = detected.dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'resourceDefinition'; });
297
- if (resourceDefAttr &&
298
- resourceDefAttr.value &&
299
- resourceDefAttr.value.type === 'JSXExpressionContainer') {
300
- var resourceDef = resourceDefAttr.value.expression;
301
- if (resourceDef.type === 'ObjectExpression') {
302
- var dataSourceIdProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceId'; });
303
- var tableNameProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'tableName'; });
304
- var dataSourceTypeProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceType'; });
305
- if (dataSourceIdProp && tableNameProp && dataSourceTypeProp) {
306
- var dataSourceId = dataSourceIdProp.value.value;
307
- var tableName = tableNameProp.value.value;
308
- var dataSourceType = dataSourceTypeProp.value.value;
309
- var fileName = "".concat(dataSourceType, "-").concat(tableName, "-").concat(dataSourceId.substring(0, 8));
310
- var setMaxPagesStateVar = info.setMaxPagesStateVar;
311
- // Create useEffect to refetch count when debounced search changes
312
- var skipCountFetchOnMountRefVar = info.skipCountFetchOnMountRefVar;
313
- var combinedStateVar = info.combinedStateVar;
314
- var refetchCountEffect = types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
315
- types.arrowFunctionExpression([], types.blockStatement([
316
- types.ifStatement(types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.blockStatement([
317
- types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.booleanLiteral(false))),
318
- types.returnStatement(),
319
- ])),
320
- types.expressionStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.identifier('fetch'), [
321
- types.templateLiteral([
322
- types.templateElement({
323
- raw: "/api/".concat(fileName, "-count?"),
324
- cooked: "/api/".concat(fileName, "-count?"),
325
- }),
326
- types.templateElement({ raw: '', cooked: '' }),
327
- ], [
328
- types.newExpression(types.identifier('URLSearchParams'), [
329
- types.objectExpression([
330
- types.objectProperty(types.identifier('query'), types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery'))),
331
- types.objectProperty(types.identifier('queryColumns'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [
332
- types.arrayExpression(info.queryColumns.map(function (col) {
333
- return types.stringLiteral(col);
334
- })),
335
- ])),
336
- ]),
337
- ]),
296
+ var detected = detectedPaginations.find(function (d) { return d.dataSourceIdentifier === info.dataSourceIdentifier; });
297
+ if (!detected) {
298
+ return;
299
+ }
300
+ var resourceDefAttr = detected.dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'resourceDefinition'; });
301
+ if (resourceDefAttr &&
302
+ resourceDefAttr.value &&
303
+ resourceDefAttr.value.type === 'JSXExpressionContainer') {
304
+ var resourceDef = resourceDefAttr.value.expression;
305
+ if (resourceDef.type === 'ObjectExpression') {
306
+ var dataSourceIdProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceId'; });
307
+ var tableNameProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'tableName'; });
308
+ var dataSourceTypeProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceType'; });
309
+ if (dataSourceIdProp && tableNameProp && dataSourceTypeProp) {
310
+ var dataSourceId = dataSourceIdProp.value.value;
311
+ var tableName = tableNameProp.value.value;
312
+ var dataSourceType = dataSourceTypeProp.value.value;
313
+ var fileName = "".concat(dataSourceType, "-").concat(tableName, "-").concat(dataSourceId.substring(0, 8));
314
+ var setMaxPagesStateVar = info.setMaxPagesStateVar;
315
+ // Create useEffect to refetch count when debounced search changes
316
+ var skipCountFetchOnMountRefVar = info.skipCountFetchOnMountRefVar;
317
+ var combinedStateVar = info.combinedStateVar;
318
+ // Build URLSearchParams properties - query is always included, queryColumns is optional
319
+ var urlSearchParamsProperties = [
320
+ types.objectProperty(types.identifier('query'), types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery'))),
321
+ ];
322
+ // Add queryColumns only if they exist
323
+ if (info.queryColumns && info.queryColumns.length > 0) {
324
+ urlSearchParamsProperties.push(types.objectProperty(types.identifier('queryColumns'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [
325
+ types.arrayExpression(info.queryColumns.map(function (col) { return types.stringLiteral(col); })),
326
+ ])));
327
+ }
328
+ var refetchCountEffect = types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
329
+ types.arrowFunctionExpression([], types.blockStatement([
330
+ types.ifStatement(types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.blockStatement([
331
+ types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.booleanLiteral(false))),
332
+ types.returnStatement(),
333
+ ])),
334
+ types.expressionStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.identifier('fetch'), [
335
+ types.templateLiteral([
336
+ types.templateElement({
337
+ raw: "/api/".concat(fileName, "-count?"),
338
+ cooked: "/api/".concat(fileName, "-count?"),
339
+ }),
340
+ types.templateElement({ raw: '', cooked: '' }),
341
+ ], [
342
+ types.newExpression(types.identifier('URLSearchParams'), [
343
+ types.objectExpression(urlSearchParamsProperties),
338
344
  ]),
339
- ]), types.identifier('then')), [
340
- types.arrowFunctionExpression([types.identifier('res')], types.callExpression(types.memberExpression(types.identifier('res'), types.identifier('json')), [])),
341
- ]), types.identifier('then')), [
342
- types.arrowFunctionExpression([types.identifier('data')], types.blockStatement([
343
- types.ifStatement(types.logicalExpression('&&', types.identifier('data'), types.binaryExpression('in', types.stringLiteral('count'), types.identifier('data'))), types.blockStatement([
344
- types.expressionStatement(types.callExpression(types.identifier(setMaxPagesStateVar), [
345
- types.conditionalExpression(types.binaryExpression('===', types.memberExpression(types.identifier('data'), types.identifier('count')), types.numericLiteral(0)), types.numericLiteral(0), types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('ceil')), [
346
- types.binaryExpression('/', types.memberExpression(types.identifier('data'), types.identifier('count')), types.numericLiteral(info.perPage)),
347
- ])),
345
+ ]),
346
+ ]), types.identifier('then')), [
347
+ types.arrowFunctionExpression([types.identifier('res')], types.callExpression(types.memberExpression(types.identifier('res'), types.identifier('json')), [])),
348
+ ]), types.identifier('then')), [
349
+ types.arrowFunctionExpression([types.identifier('data')], types.blockStatement([
350
+ types.ifStatement(types.logicalExpression('&&', types.identifier('data'), types.binaryExpression('in', types.stringLiteral('count'), types.identifier('data'))), types.blockStatement([
351
+ types.expressionStatement(types.callExpression(types.identifier(setMaxPagesStateVar), [
352
+ types.conditionalExpression(types.binaryExpression('===', types.memberExpression(types.identifier('data'), types.identifier('count')), types.numericLiteral(0)), types.numericLiteral(0), types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('ceil')), [
353
+ types.binaryExpression('/', types.memberExpression(types.identifier('data'), types.identifier('count')), types.numericLiteral(info.perPage)),
348
354
  ])),
349
355
  ])),
350
356
  ])),
351
357
  ])),
352
358
  ])),
353
- types.arrayExpression([
354
- types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery')),
355
- ]),
356
- ]));
357
- blockStatement.body.splice(insertIndex, 0, refetchCountEffect);
358
- }
359
+ ])),
360
+ types.arrayExpression([
361
+ types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery')),
362
+ ]),
363
+ ]));
364
+ blockStatement.body.splice(insertIndex, 0, refetchCountEffect);
359
365
  }
360
366
  }
361
367
  }
@@ -405,7 +411,7 @@ var createNextArrayMapperPaginationPlugin = function () {
405
411
  }
406
412
  dataSourceToInfos_1.get(info.dataSourceIdentifier).push({ info: info, detected: detected, fileName: fileName });
407
413
  });
408
- // Create ONE useEffect per unique data source
414
+ componentUseEffects_1 = [];
409
415
  dataSourceToInfos_1.forEach(function (infos) {
410
416
  var fileName = infos[0].fileName;
411
417
  // Create array of setState calls - one for each pagination using this data source
@@ -433,7 +439,13 @@ var createNextArrayMapperPaginationPlugin = function () {
433
439
  ])),
434
440
  types.arrayExpression([]),
435
441
  ]));
436
- blockStatement.body.unshift(useEffectAST);
442
+ componentUseEffects_1.push(useEffectAST);
443
+ });
444
+ componentReturnIndex = blockStatement.body.findIndex(function (stmt) { return stmt.type === 'ReturnStatement'; });
445
+ componentEffectsInsertIndex_1 = componentReturnIndex !== -1 ? componentReturnIndex : blockStatement.body.length;
446
+ // Insert in reverse order to maintain correct order
447
+ componentUseEffects_1.reverse().forEach(function (effect) {
448
+ blockStatement.body.splice(componentEffectsInsertIndex_1, 0, effect);
437
449
  });
438
450
  }
439
451
  createAPIRoutesForPaginatedDataSources(uidl.node, options.dataSources, componentChunk, options.extractedResources, paginationInfos, isComponent);
@@ -447,7 +459,7 @@ var createNextArrayMapperPaginationPlugin = function () {
447
459
  }
448
460
  searchOnlyDataSources = detectedSearchOnly;
449
461
  if (searchOnlyDataSources.length > 0) {
450
- handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, insertIndex, dependencies);
462
+ handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, dependencies);
451
463
  // Create API routes for search-only data sources
452
464
  createAPIRoutesForSearchOnlyDataSources(uidl.node, options.dataSources, componentChunk, options.extractedResources, searchOnlyDataSources);
453
465
  }
@@ -516,7 +528,7 @@ function findParentNode(root, target, currentParent) {
516
528
  return null;
517
529
  }
518
530
  function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
519
- var dataProviderMap = new Map();
531
+ var dataProviderList = [];
520
532
  var arrayMapperInfoMap = new Map();
521
533
  if (uidlNode) {
522
534
  var collectArrayMapperInfo_1 = function (node) {
@@ -683,14 +695,16 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
683
695
  var paginationNodeInfo = null;
684
696
  var searchInputInfo = null;
685
697
  var findSearchAndPaginationInScope = function (scopeNode, skipNode) {
698
+ var _a, _b, _c, _d, _e, _f;
686
699
  if (skipNode === void 0) { skipNode = null; }
687
700
  if (!scopeNode || !scopeNode.children || !Array.isArray(scopeNode.children)) {
688
- return;
701
+ return false;
689
702
  }
690
- scopeNode.children.forEach(function (child) {
691
- var _a, _b, _c;
703
+ var foundSomething = false;
704
+ for (var _i = 0, _g = scopeNode.children; _i < _g.length; _i++) {
705
+ var child = _g[_i];
692
706
  if (child === skipNode) {
693
- return;
707
+ continue;
694
708
  }
695
709
  if (child.type === 'JSXElement') {
696
710
  var childClassName = getClassName(((_a = child.openingElement) === null || _a === void 0 ? void 0 : _a.attributes) || []);
@@ -705,16 +719,17 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
705
719
  prevClass: prevClass,
706
720
  nextClass: nextClass,
707
721
  };
722
+ foundSomething = true;
708
723
  }
709
724
  }
710
725
  // Found search container - search for input inside it
711
726
  if (childClassName && childClassName.includes('data-source-search-node')) {
712
727
  if (child.children && Array.isArray(child.children)) {
713
- child.children.forEach(function (searchChild) {
714
- var _a, _b, _c;
728
+ for (var _h = 0, _j = child.children; _h < _j.length; _h++) {
729
+ var searchChild = _j[_h];
715
730
  if (searchChild.type === 'JSXElement') {
716
- var searchChildElementName = (_b = (_a = searchChild.openingElement) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.name;
717
- var searchChildClassName = getClassName(((_c = searchChild.openingElement) === null || _c === void 0 ? void 0 : _c.attributes) || []);
731
+ var searchChildElementName = (_e = (_d = searchChild.openingElement) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.name;
732
+ var searchChildClassName = getClassName(((_f = searchChild.openingElement) === null || _f === void 0 ? void 0 : _f.attributes) || []);
718
733
  if (searchChildClassName &&
719
734
  searchChildClassName.includes('search-input') &&
720
735
  searchChildElementName === 'input') {
@@ -722,9 +737,10 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
722
737
  class: searchChildClassName,
723
738
  jsx: searchChild,
724
739
  };
740
+ foundSomething = true;
725
741
  }
726
742
  }
727
- });
743
+ }
728
744
  }
729
745
  }
730
746
  // Also check if search input is a direct child
@@ -735,24 +751,37 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
735
751
  class: childClassName,
736
752
  jsx: child,
737
753
  };
754
+ foundSomething = true;
738
755
  }
756
+ // Stop searching if we found both or if we found what we're looking for
757
+ if (foundSomething && (searchInputInfo || paginationNodeInfo)) {
758
+ return true;
759
+ }
760
+ // Only recurse if we haven't found what we're looking for yet
739
761
  if (!searchInputInfo || !paginationNodeInfo) {
740
- findSearchAndPaginationInScope(child, skipNode);
762
+ if (findSearchAndPaginationInScope(child, skipNode)) {
763
+ return true;
764
+ }
741
765
  }
742
766
  }
743
- });
767
+ }
768
+ return foundSomething;
744
769
  };
745
770
  var currentScope = parent;
746
771
  var depth = 0;
747
772
  var maxDepth = 5;
748
773
  while (currentScope && (!searchInputInfo || !paginationNodeInfo) && depth < maxDepth) {
749
- findSearchAndPaginationInScope(currentScope, depth === 0 ? dataProvider : null);
774
+ var found = findSearchAndPaginationInScope(currentScope, depth === 0 ? dataProvider : null);
775
+ // Stop searching up the tree if we found a pagination node at this level
776
+ if (found && paginationNodeInfo) {
777
+ break;
778
+ }
750
779
  currentScope = findParentNode(blockStatement, currentScope);
751
780
  depth++;
752
781
  }
753
782
  // Record the DataProvider with its pagination/search info
754
- var uniqueKey = "".concat(dataProviderIdentifier, "__").concat(arrayMapperRenderProp);
755
- dataProviderMap.set(uniqueKey, {
783
+ // Use array instead of Map to handle multiple DataProviders with same name
784
+ dataProviderList.push({
756
785
  identifier: dataProviderIdentifier,
757
786
  dataProvider: dataProvider,
758
787
  arrayMapperRenderProp: arrayMapperRenderProp,
@@ -767,9 +796,16 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
767
796
  var searchOnlyMappers = [];
768
797
  var paginationOnlyMappers = [];
769
798
  var plainMappers = [];
770
- dataProviderMap.forEach(function (info) {
799
+ dataProviderList.forEach(function (info) {
771
800
  var _a, _b, _c, _d;
772
- if (info.hasPagination && info.hasSearch) {
801
+ // Check UIDL flags for this array mapper
802
+ var uidlInfo = info.arrayMapperRenderProp
803
+ ? arrayMapperInfoMap.get(info.arrayMapperRenderProp)
804
+ : null;
805
+ // Only process pagination/search if UIDL explicitly enables it
806
+ var shouldHavePagination = (uidlInfo === null || uidlInfo === void 0 ? void 0 : uidlInfo.paginated) && info.hasPagination;
807
+ var shouldHaveSearch = (uidlInfo === null || uidlInfo === void 0 ? void 0 : uidlInfo.searchEnabled) && info.hasSearch;
808
+ if (shouldHavePagination && shouldHaveSearch) {
773
809
  // Pagination + Search
774
810
  paginatedMappers.push({
775
811
  paginationNodeClass: info.paginationNode.class,
@@ -782,7 +818,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
782
818
  searchInputJSX: (_b = info.searchInput) === null || _b === void 0 ? void 0 : _b.jsx,
783
819
  });
784
820
  }
785
- else if (info.hasPagination && !info.hasSearch) {
821
+ else if (shouldHavePagination && !shouldHaveSearch) {
786
822
  // Pagination only
787
823
  paginationOnlyMappers.push({
788
824
  paginationNodeClass: info.paginationNode.class,
@@ -795,7 +831,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
795
831
  searchInputJSX: undefined,
796
832
  });
797
833
  }
798
- else if (!info.hasPagination && info.hasSearch) {
834
+ else if (!shouldHavePagination && shouldHaveSearch) {
799
835
  // Search only
800
836
  searchOnlyMappers.push({
801
837
  paginationNodeClass: '',
@@ -809,7 +845,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
809
845
  });
810
846
  }
811
847
  else {
812
- // Plain (no pagination, no search)
848
+ // Plain (no pagination, no search) - UIDL doesn't enable it or no controls found
813
849
  plainMappers.push({
814
850
  paginationNodeClass: '',
815
851
  prevButtonClass: null,
@@ -824,7 +860,9 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
824
860
  });
825
861
  return { paginatedMappers: paginatedMappers, searchOnlyMappers: searchOnlyMappers, paginationOnlyMappers: paginationOnlyMappers, plainMappers: plainMappers };
826
862
  }
827
- function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, insertIndex, dependencies) {
863
+ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, dependencies) {
864
+ var searchOnlyStates = [];
865
+ var searchOnlyEffects = [];
828
866
  searchOnlyDataSources.forEach(function (detected, index) {
829
867
  var searchId = "search_".concat(index);
830
868
  var searchQueryVar = "".concat(searchId, "_query");
@@ -835,11 +873,11 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
835
873
  var searchConfig = searchConfigMap.get(detected.dataSourceIdentifier);
836
874
  var searchDebounce = (searchConfig === null || searchConfig === void 0 ? void 0 : searchConfig.searchDebounce) || 300;
837
875
  var queryColumns = queryColumnsMap.get(detected.dataSourceIdentifier);
838
- // Add search query state
839
- var searchStateAST = types.variableDeclaration('const', [
840
- types.variableDeclarator(types.arrayPattern([types.identifier(searchQueryVar), types.identifier(setSearchQueryVar)]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
876
+ // Add skip ref
877
+ var skipRefAST = types.variableDeclaration('const', [
878
+ types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
841
879
  ]);
842
- blockStatement.body.unshift(searchStateAST);
880
+ searchOnlyStates.push(skipRefAST);
843
881
  // Add debounced search state
844
882
  var debouncedSearchStateAST = types.variableDeclaration('const', [
845
883
  types.variableDeclarator(types.arrayPattern([
@@ -847,12 +885,12 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
847
885
  types.identifier(setDebouncedSearchQueryVar),
848
886
  ]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
849
887
  ]);
850
- blockStatement.body.unshift(debouncedSearchStateAST);
851
- // Add skip ref
852
- var skipRefAST = types.variableDeclaration('const', [
853
- types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
888
+ searchOnlyStates.push(debouncedSearchStateAST);
889
+ // Add search query state
890
+ var searchStateAST = types.variableDeclaration('const', [
891
+ types.variableDeclarator(types.arrayPattern([types.identifier(searchQueryVar), types.identifier(setSearchQueryVar)]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
854
892
  ]);
855
- blockStatement.body.unshift(skipRefAST);
893
+ searchOnlyStates.push(searchStateAST);
856
894
  // Add useEffect for debouncing
857
895
  if (!dependencies.useEffect) {
858
896
  dependencies.useEffect = {
@@ -884,7 +922,7 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
884
922
  ])),
885
923
  types.arrayExpression([types.identifier(searchQueryVar)]),
886
924
  ]));
887
- blockStatement.body.splice(insertIndex, 0, debounceEffect);
925
+ searchOnlyEffects.push(debounceEffect);
888
926
  // Modify DataProvider to include search params (even without queryColumns)
889
927
  if (detected.dataProviderJSX) {
890
928
  addSearchParamsToDataProvider(detected.dataProviderJSX, {
@@ -901,6 +939,17 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
901
939
  });
902
940
  }
903
941
  });
942
+ // Add all state declarations at the beginning in correct order
943
+ searchOnlyStates.reverse().forEach(function (stateDecl) {
944
+ blockStatement.body.unshift(stateDecl);
945
+ });
946
+ // Recalculate insertIndex after adding states (since unshift shifted everything)
947
+ var newInsertIndex = blockStatement.body.findIndex(function (stmt) { return stmt.type === 'ReturnStatement'; });
948
+ var finalInsertIndex = newInsertIndex !== -1 ? newInsertIndex : blockStatement.body.length;
949
+ // Add all useEffect hooks before the return statement
950
+ searchOnlyEffects.reverse().forEach(function (effect) {
951
+ blockStatement.body.splice(finalInsertIndex, 0, effect);
952
+ });
904
953
  }
905
954
  function addSearchParamsToDataProvider(dataProviderJSX, config) {
906
955
  var _a, _b;