@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
@@ -49,7 +49,7 @@ import { generatePaginationLogic } from './array-mapper-pagination';
49
49
  import { extractDataSourceIntoNextAPIFolder } from './utils';
50
50
  export var createNextArrayMapperPaginationPlugin = function () {
51
51
  var paginationPlugin = function (structure) { return __awaiter(void 0, void 0, void 0, function () {
52
- 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;
52
+ 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;
53
53
  var _b, _c, _d;
54
54
  return __generator(this, function (_e) {
55
55
  uidl = structure.uidl, chunks = structure.chunks, dependencies = structure.dependencies, options = structure.options;
@@ -133,6 +133,7 @@ export var createNextArrayMapperPaginationPlugin = function () {
133
133
  perPageMap = ((_b = opts.paginationConfig) === null || _b === void 0 ? void 0 : _b.perPageMap) || new Map();
134
134
  searchConfigMap = ((_c = opts.paginationConfig) === null || _c === void 0 ? void 0 : _c.searchConfigMap) || new Map();
135
135
  queryColumnsMap = ((_d = opts.paginationConfig) === null || _d === void 0 ? void 0 : _d.queryColumnsMap) || new Map();
136
+ stateDeclarations = [];
136
137
  detectedPaginations.forEach(function (detected, index) {
137
138
  var paginationNodeId = "pg_".concat(index);
138
139
  // Use arrayMapperRenderProp if available, otherwise fall back to dataSourceIdentifier
@@ -143,6 +144,37 @@ export var createNextArrayMapperPaginationPlugin = function () {
143
144
  var queryColumns = queryColumnsMap.get(detected.dataSourceIdentifier);
144
145
  var info = generatePaginationLogic(paginationNodeId, detected.dataSourceIdentifier, perPage, searchConfig, queryColumns);
145
146
  paginationInfos.push(info);
147
+ // Add refs to track first render for each useEffect (add first)
148
+ if (info.searchEnabled) {
149
+ var skipCountFetchOnMountRefVar = "skipCountFetchOnMount_pg_".concat(index);
150
+ var skipCountFetchRefAST = types.variableDeclaration('const', [
151
+ types.variableDeclarator(types.identifier(skipCountFetchOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
152
+ ]);
153
+ stateDeclarations.push(skipCountFetchRefAST);
154
+ info.skipCountFetchOnMountRefVar = skipCountFetchOnMountRefVar;
155
+ var skipDebounceOnMountRefVar = "skipDebounceOnMount_pg_".concat(index);
156
+ var skipDebounceRefAST = types.variableDeclaration('const', [
157
+ types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
158
+ ]);
159
+ stateDeclarations.push(skipDebounceRefAST);
160
+ info.skipDebounceOnMountRefVar = skipDebounceOnMountRefVar;
161
+ }
162
+ // Add maxPages state
163
+ var maxPagesStateVar = "".concat(info.pageStateVar.replace('_page', ''), "_maxPages");
164
+ var setMaxPagesStateVar = "set".concat(maxPagesStateVar.charAt(0).toUpperCase() + maxPagesStateVar.slice(1));
165
+ // For pages: initialize from props (with pagination-specific prop name), for components: initialize to 0
166
+ var maxPagesInitValue = isPage
167
+ ? types.logicalExpression('||', types.optionalMemberExpression(types.identifier('props'), types.identifier("".concat(info.dataSourceIdentifier, "_pg_").concat(index, "_maxPages")), false, true), types.numericLiteral(0))
168
+ : types.numericLiteral(0);
169
+ var maxPagesStateAST = types.variableDeclaration('const', [
170
+ types.variableDeclarator(types.arrayPattern([
171
+ types.identifier(maxPagesStateVar),
172
+ types.identifier(setMaxPagesStateVar),
173
+ ]), types.callExpression(types.identifier('useState'), [maxPagesInitValue])),
174
+ ]);
175
+ stateDeclarations.push(maxPagesStateAST);
176
+ info.maxPagesStateVar = maxPagesStateVar;
177
+ info.setMaxPagesStateVar = setMaxPagesStateVar;
146
178
  // If both pagination and search are enabled, combine them into a single state object
147
179
  if (info.searchEnabled && info.searchQueryVar && info.setSearchQueryVar) {
148
180
  // Combined state: { page: 1, debouncedQuery: '' }
@@ -159,7 +191,7 @@ export var createNextArrayMapperPaginationPlugin = function () {
159
191
  ]),
160
192
  ])),
161
193
  ]);
162
- blockStatement.body.unshift(combinedStateAST);
194
+ stateDeclarations.push(combinedStateAST);
163
195
  // Still need the immediate search query state for the input
164
196
  var searchStateAST = types.variableDeclaration('const', [
165
197
  types.variableDeclarator(types.arrayPattern([
@@ -167,7 +199,7 @@ export var createNextArrayMapperPaginationPlugin = function () {
167
199
  types.identifier(info.setSearchQueryVar),
168
200
  ]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
169
201
  ]);
170
- blockStatement.body.unshift(searchStateAST);
202
+ stateDeclarations.push(searchStateAST);
171
203
  info.combinedStateVar = combinedStateVar;
172
204
  info.setCombinedStateVar = setCombinedStateVar;
173
205
  }
@@ -179,40 +211,13 @@ export var createNextArrayMapperPaginationPlugin = function () {
179
211
  types.identifier(info.setPageStateVar),
180
212
  ]), types.callExpression(types.identifier('useState'), [types.numericLiteral(1)])),
181
213
  ]);
182
- blockStatement.body.unshift(pageStateAST);
183
- }
184
- // Add maxPages state
185
- var maxPagesStateVar = "".concat(info.pageStateVar.replace('_page', ''), "_maxPages");
186
- var setMaxPagesStateVar = "set".concat(maxPagesStateVar.charAt(0).toUpperCase() + maxPagesStateVar.slice(1));
187
- // For pages: initialize from props (with pagination-specific prop name), for components: initialize to 0
188
- var maxPagesInitValue = isPage
189
- ? types.logicalExpression('||', types.optionalMemberExpression(types.identifier('props'), types.identifier("".concat(info.dataSourceIdentifier, "_pg_").concat(index, "_maxPages")), false, true), types.numericLiteral(0))
190
- : types.numericLiteral(0);
191
- var maxPagesStateAST = types.variableDeclaration('const', [
192
- types.variableDeclarator(types.arrayPattern([
193
- types.identifier(maxPagesStateVar),
194
- types.identifier(setMaxPagesStateVar),
195
- ]), types.callExpression(types.identifier('useState'), [maxPagesInitValue])),
196
- ]);
197
- blockStatement.body.unshift(maxPagesStateAST);
198
- info.maxPagesStateVar = maxPagesStateVar;
199
- info.setMaxPagesStateVar = setMaxPagesStateVar;
200
- // Add refs to track first render for each useEffect
201
- if (info.searchEnabled) {
202
- var skipDebounceOnMountRefVar = "skipDebounceOnMount_pg_".concat(index);
203
- var skipDebounceRefAST = types.variableDeclaration('const', [
204
- types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
205
- ]);
206
- blockStatement.body.unshift(skipDebounceRefAST);
207
- info.skipDebounceOnMountRefVar = skipDebounceOnMountRefVar;
208
- var skipCountFetchOnMountRefVar = "skipCountFetchOnMount_pg_".concat(index);
209
- var skipCountFetchRefAST = types.variableDeclaration('const', [
210
- types.variableDeclarator(types.identifier(skipCountFetchOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
211
- ]);
212
- blockStatement.body.unshift(skipCountFetchRefAST);
213
- info.skipCountFetchOnMountRefVar = skipCountFetchOnMountRefVar;
214
+ stateDeclarations.push(pageStateAST);
214
215
  }
215
216
  });
217
+ // Add all state declarations at once to the beginning in correct order
218
+ stateDeclarations.reverse().forEach(function (stateDecl) {
219
+ blockStatement.body.unshift(stateDecl);
220
+ });
216
221
  hasSearchEnabled = paginationInfos.some(function (info) { return info.searchEnabled; });
217
222
  if (hasSearchEnabled && !dependencies.useEffect) {
218
223
  dependencies.useEffect = {
@@ -262,74 +267,75 @@ export var createNextArrayMapperPaginationPlugin = function () {
262
267
  ]));
263
268
  blockStatement.body.splice(insertIndex, 0, debounceEffect);
264
269
  // Add useEffect to refetch count when search changes (for both pages and components)
265
- if (info.queryColumns && info.queryColumns.length > 0) {
266
- var detected = detectedPaginations.find(function (d) { return d.dataSourceIdentifier === info.dataSourceIdentifier; });
267
- if (!detected) {
268
- return;
269
- }
270
- var resourceDefAttr = detected.dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'resourceDefinition'; });
271
- if (resourceDefAttr &&
272
- resourceDefAttr.value &&
273
- resourceDefAttr.value.type === 'JSXExpressionContainer') {
274
- var resourceDef = resourceDefAttr.value.expression;
275
- if (resourceDef.type === 'ObjectExpression') {
276
- var dataSourceIdProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceId'; });
277
- var tableNameProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'tableName'; });
278
- var dataSourceTypeProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceType'; });
279
- if (dataSourceIdProp && tableNameProp && dataSourceTypeProp) {
280
- var dataSourceId = dataSourceIdProp.value.value;
281
- var tableName = tableNameProp.value.value;
282
- var dataSourceType = dataSourceTypeProp.value.value;
283
- var fileName = "".concat(dataSourceType, "-").concat(tableName, "-").concat(dataSourceId.substring(0, 8));
284
- var setMaxPagesStateVar = info.setMaxPagesStateVar;
285
- // Create useEffect to refetch count when debounced search changes
286
- var skipCountFetchOnMountRefVar = info.skipCountFetchOnMountRefVar;
287
- var combinedStateVar = info.combinedStateVar;
288
- var refetchCountEffect = types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
289
- types.arrowFunctionExpression([], types.blockStatement([
290
- types.ifStatement(types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.blockStatement([
291
- types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.booleanLiteral(false))),
292
- types.returnStatement(),
293
- ])),
294
- types.expressionStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.identifier('fetch'), [
295
- types.templateLiteral([
296
- types.templateElement({
297
- raw: "/api/".concat(fileName, "-count?"),
298
- cooked: "/api/".concat(fileName, "-count?"),
299
- }),
300
- types.templateElement({ raw: '', cooked: '' }),
301
- ], [
302
- types.newExpression(types.identifier('URLSearchParams'), [
303
- types.objectExpression([
304
- types.objectProperty(types.identifier('query'), types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery'))),
305
- types.objectProperty(types.identifier('queryColumns'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [
306
- types.arrayExpression(info.queryColumns.map(function (col) {
307
- return types.stringLiteral(col);
308
- })),
309
- ])),
310
- ]),
311
- ]),
270
+ var detected = detectedPaginations.find(function (d) { return d.dataSourceIdentifier === info.dataSourceIdentifier; });
271
+ if (!detected) {
272
+ return;
273
+ }
274
+ var resourceDefAttr = detected.dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'resourceDefinition'; });
275
+ if (resourceDefAttr &&
276
+ resourceDefAttr.value &&
277
+ resourceDefAttr.value.type === 'JSXExpressionContainer') {
278
+ var resourceDef = resourceDefAttr.value.expression;
279
+ if (resourceDef.type === 'ObjectExpression') {
280
+ var dataSourceIdProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceId'; });
281
+ var tableNameProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'tableName'; });
282
+ var dataSourceTypeProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceType'; });
283
+ if (dataSourceIdProp && tableNameProp && dataSourceTypeProp) {
284
+ var dataSourceId = dataSourceIdProp.value.value;
285
+ var tableName = tableNameProp.value.value;
286
+ var dataSourceType = dataSourceTypeProp.value.value;
287
+ var fileName = "".concat(dataSourceType, "-").concat(tableName, "-").concat(dataSourceId.substring(0, 8));
288
+ var setMaxPagesStateVar = info.setMaxPagesStateVar;
289
+ // Create useEffect to refetch count when debounced search changes
290
+ var skipCountFetchOnMountRefVar = info.skipCountFetchOnMountRefVar;
291
+ var combinedStateVar = info.combinedStateVar;
292
+ // Build URLSearchParams properties - query is always included, queryColumns is optional
293
+ var urlSearchParamsProperties = [
294
+ types.objectProperty(types.identifier('query'), types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery'))),
295
+ ];
296
+ // Add queryColumns only if they exist
297
+ if (info.queryColumns && info.queryColumns.length > 0) {
298
+ urlSearchParamsProperties.push(types.objectProperty(types.identifier('queryColumns'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [
299
+ types.arrayExpression(info.queryColumns.map(function (col) { return types.stringLiteral(col); })),
300
+ ])));
301
+ }
302
+ var refetchCountEffect = types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
303
+ types.arrowFunctionExpression([], types.blockStatement([
304
+ types.ifStatement(types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.blockStatement([
305
+ types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier(skipCountFetchOnMountRefVar), types.identifier('current')), types.booleanLiteral(false))),
306
+ types.returnStatement(),
307
+ ])),
308
+ types.expressionStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.identifier('fetch'), [
309
+ types.templateLiteral([
310
+ types.templateElement({
311
+ raw: "/api/".concat(fileName, "-count?"),
312
+ cooked: "/api/".concat(fileName, "-count?"),
313
+ }),
314
+ types.templateElement({ raw: '', cooked: '' }),
315
+ ], [
316
+ types.newExpression(types.identifier('URLSearchParams'), [
317
+ types.objectExpression(urlSearchParamsProperties),
312
318
  ]),
313
- ]), types.identifier('then')), [
314
- types.arrowFunctionExpression([types.identifier('res')], types.callExpression(types.memberExpression(types.identifier('res'), types.identifier('json')), [])),
315
- ]), types.identifier('then')), [
316
- types.arrowFunctionExpression([types.identifier('data')], types.blockStatement([
317
- types.ifStatement(types.logicalExpression('&&', types.identifier('data'), types.binaryExpression('in', types.stringLiteral('count'), types.identifier('data'))), types.blockStatement([
318
- types.expressionStatement(types.callExpression(types.identifier(setMaxPagesStateVar), [
319
- 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')), [
320
- types.binaryExpression('/', types.memberExpression(types.identifier('data'), types.identifier('count')), types.numericLiteral(info.perPage)),
321
- ])),
319
+ ]),
320
+ ]), types.identifier('then')), [
321
+ types.arrowFunctionExpression([types.identifier('res')], types.callExpression(types.memberExpression(types.identifier('res'), types.identifier('json')), [])),
322
+ ]), types.identifier('then')), [
323
+ types.arrowFunctionExpression([types.identifier('data')], types.blockStatement([
324
+ types.ifStatement(types.logicalExpression('&&', types.identifier('data'), types.binaryExpression('in', types.stringLiteral('count'), types.identifier('data'))), types.blockStatement([
325
+ types.expressionStatement(types.callExpression(types.identifier(setMaxPagesStateVar), [
326
+ 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')), [
327
+ types.binaryExpression('/', types.memberExpression(types.identifier('data'), types.identifier('count')), types.numericLiteral(info.perPage)),
322
328
  ])),
323
329
  ])),
324
330
  ])),
325
331
  ])),
326
332
  ])),
327
- types.arrayExpression([
328
- types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery')),
329
- ]),
330
- ]));
331
- blockStatement.body.splice(insertIndex, 0, refetchCountEffect);
332
- }
333
+ ])),
334
+ types.arrayExpression([
335
+ types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery')),
336
+ ]),
337
+ ]));
338
+ blockStatement.body.splice(insertIndex, 0, refetchCountEffect);
333
339
  }
334
340
  }
335
341
  }
@@ -379,7 +385,7 @@ export var createNextArrayMapperPaginationPlugin = function () {
379
385
  }
380
386
  dataSourceToInfos_1.get(info.dataSourceIdentifier).push({ info: info, detected: detected, fileName: fileName });
381
387
  });
382
- // Create ONE useEffect per unique data source
388
+ componentUseEffects_1 = [];
383
389
  dataSourceToInfos_1.forEach(function (infos) {
384
390
  var fileName = infos[0].fileName;
385
391
  // Create array of setState calls - one for each pagination using this data source
@@ -407,7 +413,13 @@ export var createNextArrayMapperPaginationPlugin = function () {
407
413
  ])),
408
414
  types.arrayExpression([]),
409
415
  ]));
410
- blockStatement.body.unshift(useEffectAST);
416
+ componentUseEffects_1.push(useEffectAST);
417
+ });
418
+ componentReturnIndex = blockStatement.body.findIndex(function (stmt) { return stmt.type === 'ReturnStatement'; });
419
+ componentEffectsInsertIndex_1 = componentReturnIndex !== -1 ? componentReturnIndex : blockStatement.body.length;
420
+ // Insert in reverse order to maintain correct order
421
+ componentUseEffects_1.reverse().forEach(function (effect) {
422
+ blockStatement.body.splice(componentEffectsInsertIndex_1, 0, effect);
411
423
  });
412
424
  }
413
425
  createAPIRoutesForPaginatedDataSources(uidl.node, options.dataSources, componentChunk, options.extractedResources, paginationInfos, isComponent);
@@ -421,7 +433,7 @@ export var createNextArrayMapperPaginationPlugin = function () {
421
433
  }
422
434
  searchOnlyDataSources = detectedSearchOnly;
423
435
  if (searchOnlyDataSources.length > 0) {
424
- handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, insertIndex, dependencies);
436
+ handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, dependencies);
425
437
  // Create API routes for search-only data sources
426
438
  createAPIRoutesForSearchOnlyDataSources(uidl.node, options.dataSources, componentChunk, options.extractedResources, searchOnlyDataSources);
427
439
  }
@@ -489,7 +501,7 @@ function findParentNode(root, target, currentParent) {
489
501
  return null;
490
502
  }
491
503
  function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
492
- var dataProviderMap = new Map();
504
+ var dataProviderList = [];
493
505
  var arrayMapperInfoMap = new Map();
494
506
  if (uidlNode) {
495
507
  var collectArrayMapperInfo_1 = function (node) {
@@ -656,14 +668,16 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
656
668
  var paginationNodeInfo = null;
657
669
  var searchInputInfo = null;
658
670
  var findSearchAndPaginationInScope = function (scopeNode, skipNode) {
671
+ var _a, _b, _c, _d, _e, _f;
659
672
  if (skipNode === void 0) { skipNode = null; }
660
673
  if (!scopeNode || !scopeNode.children || !Array.isArray(scopeNode.children)) {
661
- return;
674
+ return false;
662
675
  }
663
- scopeNode.children.forEach(function (child) {
664
- var _a, _b, _c;
676
+ var foundSomething = false;
677
+ for (var _i = 0, _g = scopeNode.children; _i < _g.length; _i++) {
678
+ var child = _g[_i];
665
679
  if (child === skipNode) {
666
- return;
680
+ continue;
667
681
  }
668
682
  if (child.type === 'JSXElement') {
669
683
  var childClassName = getClassName(((_a = child.openingElement) === null || _a === void 0 ? void 0 : _a.attributes) || []);
@@ -678,16 +692,17 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
678
692
  prevClass: prevClass,
679
693
  nextClass: nextClass,
680
694
  };
695
+ foundSomething = true;
681
696
  }
682
697
  }
683
698
  // Found search container - search for input inside it
684
699
  if (childClassName && childClassName.includes('data-source-search-node')) {
685
700
  if (child.children && Array.isArray(child.children)) {
686
- child.children.forEach(function (searchChild) {
687
- var _a, _b, _c;
701
+ for (var _h = 0, _j = child.children; _h < _j.length; _h++) {
702
+ var searchChild = _j[_h];
688
703
  if (searchChild.type === 'JSXElement') {
689
- var searchChildElementName = (_b = (_a = searchChild.openingElement) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.name;
690
- var searchChildClassName = getClassName(((_c = searchChild.openingElement) === null || _c === void 0 ? void 0 : _c.attributes) || []);
704
+ var searchChildElementName = (_e = (_d = searchChild.openingElement) === null || _d === void 0 ? void 0 : _d.name) === null || _e === void 0 ? void 0 : _e.name;
705
+ var searchChildClassName = getClassName(((_f = searchChild.openingElement) === null || _f === void 0 ? void 0 : _f.attributes) || []);
691
706
  if (searchChildClassName &&
692
707
  searchChildClassName.includes('search-input') &&
693
708
  searchChildElementName === 'input') {
@@ -695,9 +710,10 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
695
710
  class: searchChildClassName,
696
711
  jsx: searchChild,
697
712
  };
713
+ foundSomething = true;
698
714
  }
699
715
  }
700
- });
716
+ }
701
717
  }
702
718
  }
703
719
  // Also check if search input is a direct child
@@ -708,24 +724,37 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
708
724
  class: childClassName,
709
725
  jsx: child,
710
726
  };
727
+ foundSomething = true;
711
728
  }
729
+ // Stop searching if we found both or if we found what we're looking for
730
+ if (foundSomething && (searchInputInfo || paginationNodeInfo)) {
731
+ return true;
732
+ }
733
+ // Only recurse if we haven't found what we're looking for yet
712
734
  if (!searchInputInfo || !paginationNodeInfo) {
713
- findSearchAndPaginationInScope(child, skipNode);
735
+ if (findSearchAndPaginationInScope(child, skipNode)) {
736
+ return true;
737
+ }
714
738
  }
715
739
  }
716
- });
740
+ }
741
+ return foundSomething;
717
742
  };
718
743
  var currentScope = parent;
719
744
  var depth = 0;
720
745
  var maxDepth = 5;
721
746
  while (currentScope && (!searchInputInfo || !paginationNodeInfo) && depth < maxDepth) {
722
- findSearchAndPaginationInScope(currentScope, depth === 0 ? dataProvider : null);
747
+ var found = findSearchAndPaginationInScope(currentScope, depth === 0 ? dataProvider : null);
748
+ // Stop searching up the tree if we found a pagination node at this level
749
+ if (found && paginationNodeInfo) {
750
+ break;
751
+ }
723
752
  currentScope = findParentNode(blockStatement, currentScope);
724
753
  depth++;
725
754
  }
726
755
  // Record the DataProvider with its pagination/search info
727
- var uniqueKey = "".concat(dataProviderIdentifier, "__").concat(arrayMapperRenderProp);
728
- dataProviderMap.set(uniqueKey, {
756
+ // Use array instead of Map to handle multiple DataProviders with same name
757
+ dataProviderList.push({
729
758
  identifier: dataProviderIdentifier,
730
759
  dataProvider: dataProvider,
731
760
  arrayMapperRenderProp: arrayMapperRenderProp,
@@ -740,9 +769,16 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
740
769
  var searchOnlyMappers = [];
741
770
  var paginationOnlyMappers = [];
742
771
  var plainMappers = [];
743
- dataProviderMap.forEach(function (info) {
772
+ dataProviderList.forEach(function (info) {
744
773
  var _a, _b, _c, _d;
745
- if (info.hasPagination && info.hasSearch) {
774
+ // Check UIDL flags for this array mapper
775
+ var uidlInfo = info.arrayMapperRenderProp
776
+ ? arrayMapperInfoMap.get(info.arrayMapperRenderProp)
777
+ : null;
778
+ // Only process pagination/search if UIDL explicitly enables it
779
+ var shouldHavePagination = (uidlInfo === null || uidlInfo === void 0 ? void 0 : uidlInfo.paginated) && info.hasPagination;
780
+ var shouldHaveSearch = (uidlInfo === null || uidlInfo === void 0 ? void 0 : uidlInfo.searchEnabled) && info.hasSearch;
781
+ if (shouldHavePagination && shouldHaveSearch) {
746
782
  // Pagination + Search
747
783
  paginatedMappers.push({
748
784
  paginationNodeClass: info.paginationNode.class,
@@ -755,7 +791,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
755
791
  searchInputJSX: (_b = info.searchInput) === null || _b === void 0 ? void 0 : _b.jsx,
756
792
  });
757
793
  }
758
- else if (info.hasPagination && !info.hasSearch) {
794
+ else if (shouldHavePagination && !shouldHaveSearch) {
759
795
  // Pagination only
760
796
  paginationOnlyMappers.push({
761
797
  paginationNodeClass: info.paginationNode.class,
@@ -768,7 +804,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
768
804
  searchInputJSX: undefined,
769
805
  });
770
806
  }
771
- else if (!info.hasPagination && info.hasSearch) {
807
+ else if (!shouldHavePagination && shouldHaveSearch) {
772
808
  // Search only
773
809
  searchOnlyMappers.push({
774
810
  paginationNodeClass: '',
@@ -782,7 +818,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
782
818
  });
783
819
  }
784
820
  else {
785
- // Plain (no pagination, no search)
821
+ // Plain (no pagination, no search) - UIDL doesn't enable it or no controls found
786
822
  plainMappers.push({
787
823
  paginationNodeClass: '',
788
824
  prevButtonClass: null,
@@ -797,7 +833,9 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
797
833
  });
798
834
  return { paginatedMappers: paginatedMappers, searchOnlyMappers: searchOnlyMappers, paginationOnlyMappers: paginationOnlyMappers, plainMappers: plainMappers };
799
835
  }
800
- function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, insertIndex, dependencies) {
836
+ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, dependencies) {
837
+ var searchOnlyStates = [];
838
+ var searchOnlyEffects = [];
801
839
  searchOnlyDataSources.forEach(function (detected, index) {
802
840
  var searchId = "search_".concat(index);
803
841
  var searchQueryVar = "".concat(searchId, "_query");
@@ -808,11 +846,11 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
808
846
  var searchConfig = searchConfigMap.get(detected.dataSourceIdentifier);
809
847
  var searchDebounce = (searchConfig === null || searchConfig === void 0 ? void 0 : searchConfig.searchDebounce) || 300;
810
848
  var queryColumns = queryColumnsMap.get(detected.dataSourceIdentifier);
811
- // Add search query state
812
- var searchStateAST = types.variableDeclaration('const', [
813
- types.variableDeclarator(types.arrayPattern([types.identifier(searchQueryVar), types.identifier(setSearchQueryVar)]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
849
+ // Add skip ref
850
+ var skipRefAST = types.variableDeclaration('const', [
851
+ types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
814
852
  ]);
815
- blockStatement.body.unshift(searchStateAST);
853
+ searchOnlyStates.push(skipRefAST);
816
854
  // Add debounced search state
817
855
  var debouncedSearchStateAST = types.variableDeclaration('const', [
818
856
  types.variableDeclarator(types.arrayPattern([
@@ -820,12 +858,12 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
820
858
  types.identifier(setDebouncedSearchQueryVar),
821
859
  ]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
822
860
  ]);
823
- blockStatement.body.unshift(debouncedSearchStateAST);
824
- // Add skip ref
825
- var skipRefAST = types.variableDeclaration('const', [
826
- types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
861
+ searchOnlyStates.push(debouncedSearchStateAST);
862
+ // Add search query state
863
+ var searchStateAST = types.variableDeclaration('const', [
864
+ types.variableDeclarator(types.arrayPattern([types.identifier(searchQueryVar), types.identifier(setSearchQueryVar)]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
827
865
  ]);
828
- blockStatement.body.unshift(skipRefAST);
866
+ searchOnlyStates.push(searchStateAST);
829
867
  // Add useEffect for debouncing
830
868
  if (!dependencies.useEffect) {
831
869
  dependencies.useEffect = {
@@ -857,7 +895,7 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
857
895
  ])),
858
896
  types.arrayExpression([types.identifier(searchQueryVar)]),
859
897
  ]));
860
- blockStatement.body.splice(insertIndex, 0, debounceEffect);
898
+ searchOnlyEffects.push(debounceEffect);
861
899
  // Modify DataProvider to include search params (even without queryColumns)
862
900
  if (detected.dataProviderJSX) {
863
901
  addSearchParamsToDataProvider(detected.dataProviderJSX, {
@@ -874,6 +912,17 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
874
912
  });
875
913
  }
876
914
  });
915
+ // Add all state declarations at the beginning in correct order
916
+ searchOnlyStates.reverse().forEach(function (stateDecl) {
917
+ blockStatement.body.unshift(stateDecl);
918
+ });
919
+ // Recalculate insertIndex after adding states (since unshift shifted everything)
920
+ var newInsertIndex = blockStatement.body.findIndex(function (stmt) { return stmt.type === 'ReturnStatement'; });
921
+ var finalInsertIndex = newInsertIndex !== -1 ? newInsertIndex : blockStatement.body.length;
922
+ // Add all useEffect hooks before the return statement
923
+ searchOnlyEffects.reverse().forEach(function (effect) {
924
+ blockStatement.body.splice(finalInsertIndex, 0, effect);
925
+ });
877
926
  }
878
927
  function addSearchParamsToDataProvider(dataProviderJSX, config) {
879
928
  var _a, _b;