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

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 +151 -119
  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 +151 -119
  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 +308 -257
@@ -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) {
@@ -724,8 +736,8 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
724
736
  depth++;
725
737
  }
726
738
  // Record the DataProvider with its pagination/search info
727
- var uniqueKey = "".concat(dataProviderIdentifier, "__").concat(arrayMapperRenderProp);
728
- dataProviderMap.set(uniqueKey, {
739
+ // Use array instead of Map to handle multiple DataProviders with same name
740
+ dataProviderList.push({
729
741
  identifier: dataProviderIdentifier,
730
742
  dataProvider: dataProvider,
731
743
  arrayMapperRenderProp: arrayMapperRenderProp,
@@ -740,9 +752,16 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
740
752
  var searchOnlyMappers = [];
741
753
  var paginationOnlyMappers = [];
742
754
  var plainMappers = [];
743
- dataProviderMap.forEach(function (info) {
755
+ dataProviderList.forEach(function (info) {
744
756
  var _a, _b, _c, _d;
745
- if (info.hasPagination && info.hasSearch) {
757
+ // Check UIDL flags for this array mapper
758
+ var uidlInfo = info.arrayMapperRenderProp
759
+ ? arrayMapperInfoMap.get(info.arrayMapperRenderProp)
760
+ : null;
761
+ // Only process pagination/search if UIDL explicitly enables it
762
+ var shouldHavePagination = (uidlInfo === null || uidlInfo === void 0 ? void 0 : uidlInfo.paginated) && info.hasPagination;
763
+ var shouldHaveSearch = (uidlInfo === null || uidlInfo === void 0 ? void 0 : uidlInfo.searchEnabled) && info.hasSearch;
764
+ if (shouldHavePagination && shouldHaveSearch) {
746
765
  // Pagination + Search
747
766
  paginatedMappers.push({
748
767
  paginationNodeClass: info.paginationNode.class,
@@ -755,7 +774,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
755
774
  searchInputJSX: (_b = info.searchInput) === null || _b === void 0 ? void 0 : _b.jsx,
756
775
  });
757
776
  }
758
- else if (info.hasPagination && !info.hasSearch) {
777
+ else if (shouldHavePagination && !shouldHaveSearch) {
759
778
  // Pagination only
760
779
  paginationOnlyMappers.push({
761
780
  paginationNodeClass: info.paginationNode.class,
@@ -768,7 +787,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
768
787
  searchInputJSX: undefined,
769
788
  });
770
789
  }
771
- else if (!info.hasPagination && info.hasSearch) {
790
+ else if (!shouldHavePagination && shouldHaveSearch) {
772
791
  // Search only
773
792
  searchOnlyMappers.push({
774
793
  paginationNodeClass: '',
@@ -782,7 +801,7 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
782
801
  });
783
802
  }
784
803
  else {
785
- // Plain (no pagination, no search)
804
+ // Plain (no pagination, no search) - UIDL doesn't enable it or no controls found
786
805
  plainMappers.push({
787
806
  paginationNodeClass: '',
788
807
  prevButtonClass: null,
@@ -797,7 +816,9 @@ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
797
816
  });
798
817
  return { paginatedMappers: paginatedMappers, searchOnlyMappers: searchOnlyMappers, paginationOnlyMappers: paginationOnlyMappers, plainMappers: plainMappers };
799
818
  }
800
- function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, insertIndex, dependencies) {
819
+ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, dependencies) {
820
+ var searchOnlyStates = [];
821
+ var searchOnlyEffects = [];
801
822
  searchOnlyDataSources.forEach(function (detected, index) {
802
823
  var searchId = "search_".concat(index);
803
824
  var searchQueryVar = "".concat(searchId, "_query");
@@ -808,11 +829,11 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
808
829
  var searchConfig = searchConfigMap.get(detected.dataSourceIdentifier);
809
830
  var searchDebounce = (searchConfig === null || searchConfig === void 0 ? void 0 : searchConfig.searchDebounce) || 300;
810
831
  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('')])),
832
+ // Add skip ref
833
+ var skipRefAST = types.variableDeclaration('const', [
834
+ types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
814
835
  ]);
815
- blockStatement.body.unshift(searchStateAST);
836
+ searchOnlyStates.push(skipRefAST);
816
837
  // Add debounced search state
817
838
  var debouncedSearchStateAST = types.variableDeclaration('const', [
818
839
  types.variableDeclarator(types.arrayPattern([
@@ -820,12 +841,12 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
820
841
  types.identifier(setDebouncedSearchQueryVar),
821
842
  ]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
822
843
  ]);
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)])),
844
+ searchOnlyStates.push(debouncedSearchStateAST);
845
+ // Add search query state
846
+ var searchStateAST = types.variableDeclaration('const', [
847
+ types.variableDeclarator(types.arrayPattern([types.identifier(searchQueryVar), types.identifier(setSearchQueryVar)]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
827
848
  ]);
828
- blockStatement.body.unshift(skipRefAST);
849
+ searchOnlyStates.push(searchStateAST);
829
850
  // Add useEffect for debouncing
830
851
  if (!dependencies.useEffect) {
831
852
  dependencies.useEffect = {
@@ -857,7 +878,7 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
857
878
  ])),
858
879
  types.arrayExpression([types.identifier(searchQueryVar)]),
859
880
  ]));
860
- blockStatement.body.splice(insertIndex, 0, debounceEffect);
881
+ searchOnlyEffects.push(debounceEffect);
861
882
  // Modify DataProvider to include search params (even without queryColumns)
862
883
  if (detected.dataProviderJSX) {
863
884
  addSearchParamsToDataProvider(detected.dataProviderJSX, {
@@ -874,6 +895,17 @@ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, sea
874
895
  });
875
896
  }
876
897
  });
898
+ // Add all state declarations at the beginning in correct order
899
+ searchOnlyStates.reverse().forEach(function (stateDecl) {
900
+ blockStatement.body.unshift(stateDecl);
901
+ });
902
+ // Recalculate insertIndex after adding states (since unshift shifted everything)
903
+ var newInsertIndex = blockStatement.body.findIndex(function (stmt) { return stmt.type === 'ReturnStatement'; });
904
+ var finalInsertIndex = newInsertIndex !== -1 ? newInsertIndex : blockStatement.body.length;
905
+ // Add all useEffect hooks before the return statement
906
+ searchOnlyEffects.reverse().forEach(function (effect) {
907
+ blockStatement.body.splice(finalInsertIndex, 0, effect);
908
+ });
877
909
  }
878
910
  function addSearchParamsToDataProvider(dataProviderJSX, config) {
879
911
  var _a, _b;