@teleporthq/teleport-plugin-next-data-source 0.40.15

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 (240) hide show
  1. package/ARRAY_MAPPER_PAGINATION.md +1128 -0
  2. package/LICENSE +21 -0
  3. package/README.md +40 -0
  4. package/SEARCH_IMPLEMENTATION_SUMMARY.md +983 -0
  5. package/__tests__/fetchers.test.ts +545 -0
  6. package/__tests__/integration.test.ts +561 -0
  7. package/__tests__/mocks.ts +241 -0
  8. package/__tests__/pagination.test.ts +31 -0
  9. package/__tests__/plugin.test.ts +577 -0
  10. package/__tests__/utils.test.ts +430 -0
  11. package/__tests__/validation.test.ts +348 -0
  12. package/dist/cjs/array-mapper-pagination.d.ts +32 -0
  13. package/dist/cjs/array-mapper-pagination.d.ts.map +1 -0
  14. package/dist/cjs/array-mapper-pagination.js +77 -0
  15. package/dist/cjs/array-mapper-pagination.js.map +1 -0
  16. package/dist/cjs/count-fetchers.d.ts +12 -0
  17. package/dist/cjs/count-fetchers.d.ts.map +1 -0
  18. package/dist/cjs/count-fetchers.js +46 -0
  19. package/dist/cjs/count-fetchers.js.map +1 -0
  20. package/dist/cjs/data-source-fetchers.d.ts +14 -0
  21. package/dist/cjs/data-source-fetchers.d.ts.map +1 -0
  22. package/dist/cjs/data-source-fetchers.js +185 -0
  23. package/dist/cjs/data-source-fetchers.js.map +1 -0
  24. package/dist/cjs/fetchers/airtable.d.ts +6 -0
  25. package/dist/cjs/fetchers/airtable.d.ts.map +1 -0
  26. package/dist/cjs/fetchers/airtable.js +27 -0
  27. package/dist/cjs/fetchers/airtable.js.map +1 -0
  28. package/dist/cjs/fetchers/clickhouse.d.ts +6 -0
  29. package/dist/cjs/fetchers/clickhouse.d.ts.map +1 -0
  30. package/dist/cjs/fetchers/clickhouse.js +29 -0
  31. package/dist/cjs/fetchers/clickhouse.js.map +1 -0
  32. package/dist/cjs/fetchers/csv-file.d.ts +7 -0
  33. package/dist/cjs/fetchers/csv-file.d.ts.map +1 -0
  34. package/dist/cjs/fetchers/csv-file.js +36 -0
  35. package/dist/cjs/fetchers/csv-file.js.map +1 -0
  36. package/dist/cjs/fetchers/firestore.d.ts +6 -0
  37. package/dist/cjs/fetchers/firestore.d.ts.map +1 -0
  38. package/dist/cjs/fetchers/firestore.js +35 -0
  39. package/dist/cjs/fetchers/firestore.js.map +1 -0
  40. package/dist/cjs/fetchers/google-sheets.d.ts +6 -0
  41. package/dist/cjs/fetchers/google-sheets.d.ts.map +1 -0
  42. package/dist/cjs/fetchers/google-sheets.js +30 -0
  43. package/dist/cjs/fetchers/google-sheets.js.map +1 -0
  44. package/dist/cjs/fetchers/index.d.ts +17 -0
  45. package/dist/cjs/fetchers/index.d.ts.map +1 -0
  46. package/dist/cjs/fetchers/index.js +56 -0
  47. package/dist/cjs/fetchers/index.js.map +1 -0
  48. package/dist/cjs/fetchers/javascript.d.ts +7 -0
  49. package/dist/cjs/fetchers/javascript.d.ts.map +1 -0
  50. package/dist/cjs/fetchers/javascript.js +40 -0
  51. package/dist/cjs/fetchers/javascript.js.map +1 -0
  52. package/dist/cjs/fetchers/mariadb.d.ts +3 -0
  53. package/dist/cjs/fetchers/mariadb.d.ts.map +1 -0
  54. package/dist/cjs/fetchers/mariadb.js +23 -0
  55. package/dist/cjs/fetchers/mariadb.js.map +1 -0
  56. package/dist/cjs/fetchers/mongodb.d.ts +7 -0
  57. package/dist/cjs/fetchers/mongodb.d.ts.map +1 -0
  58. package/dist/cjs/fetchers/mongodb.js +52 -0
  59. package/dist/cjs/fetchers/mongodb.js.map +1 -0
  60. package/dist/cjs/fetchers/mysql.d.ts +3 -0
  61. package/dist/cjs/fetchers/mysql.d.ts.map +1 -0
  62. package/dist/cjs/fetchers/mysql.js +30 -0
  63. package/dist/cjs/fetchers/mysql.js.map +1 -0
  64. package/dist/cjs/fetchers/postgresql.d.ts +3 -0
  65. package/dist/cjs/fetchers/postgresql.d.ts.map +1 -0
  66. package/dist/cjs/fetchers/postgresql.js +25 -0
  67. package/dist/cjs/fetchers/postgresql.js.map +1 -0
  68. package/dist/cjs/fetchers/redis.d.ts +6 -0
  69. package/dist/cjs/fetchers/redis.d.ts.map +1 -0
  70. package/dist/cjs/fetchers/redis.js +46 -0
  71. package/dist/cjs/fetchers/redis.js.map +1 -0
  72. package/dist/cjs/fetchers/redshift.d.ts +2 -0
  73. package/dist/cjs/fetchers/redshift.d.ts.map +1 -0
  74. package/dist/cjs/fetchers/redshift.js +24 -0
  75. package/dist/cjs/fetchers/redshift.js.map +1 -0
  76. package/dist/cjs/fetchers/rest-api.d.ts +6 -0
  77. package/dist/cjs/fetchers/rest-api.d.ts.map +1 -0
  78. package/dist/cjs/fetchers/rest-api.js +58 -0
  79. package/dist/cjs/fetchers/rest-api.js.map +1 -0
  80. package/dist/cjs/fetchers/static-collection.d.ts +7 -0
  81. package/dist/cjs/fetchers/static-collection.d.ts.map +1 -0
  82. package/dist/cjs/fetchers/static-collection.js +24 -0
  83. package/dist/cjs/fetchers/static-collection.js.map +1 -0
  84. package/dist/cjs/fetchers/supabase.d.ts +7 -0
  85. package/dist/cjs/fetchers/supabase.d.ts.map +1 -0
  86. package/dist/cjs/fetchers/supabase.js +42 -0
  87. package/dist/cjs/fetchers/supabase.js.map +1 -0
  88. package/dist/cjs/fetchers/turso.d.ts +6 -0
  89. package/dist/cjs/fetchers/turso.d.ts.map +1 -0
  90. package/dist/cjs/fetchers/turso.js +25 -0
  91. package/dist/cjs/fetchers/turso.js.map +1 -0
  92. package/dist/cjs/index.d.ts +9 -0
  93. package/dist/cjs/index.d.ts.map +1 -0
  94. package/dist/cjs/index.js +325 -0
  95. package/dist/cjs/index.js.map +1 -0
  96. package/dist/cjs/pagination-plugin.d.ts +5 -0
  97. package/dist/cjs/pagination-plugin.d.ts.map +1 -0
  98. package/dist/cjs/pagination-plugin.js +1484 -0
  99. package/dist/cjs/pagination-plugin.js.map +1 -0
  100. package/dist/cjs/pagination-with-count.d.ts +6 -0
  101. package/dist/cjs/pagination-with-count.d.ts.map +1 -0
  102. package/dist/cjs/pagination-with-count.js +63 -0
  103. package/dist/cjs/pagination-with-count.js.map +1 -0
  104. package/dist/cjs/tsconfig.tsbuildinfo +1 -0
  105. package/dist/cjs/utils.d.ts +31 -0
  106. package/dist/cjs/utils.d.ts.map +1 -0
  107. package/dist/cjs/utils.js +763 -0
  108. package/dist/cjs/utils.js.map +1 -0
  109. package/dist/cjs/validation.d.ts +5 -0
  110. package/dist/cjs/validation.d.ts.map +1 -0
  111. package/dist/cjs/validation.js +29 -0
  112. package/dist/cjs/validation.js.map +1 -0
  113. package/dist/esm/array-mapper-pagination.d.ts +32 -0
  114. package/dist/esm/array-mapper-pagination.d.ts.map +1 -0
  115. package/dist/esm/array-mapper-pagination.js +72 -0
  116. package/dist/esm/array-mapper-pagination.js.map +1 -0
  117. package/dist/esm/count-fetchers.d.ts +12 -0
  118. package/dist/esm/count-fetchers.d.ts.map +1 -0
  119. package/dist/esm/count-fetchers.js +35 -0
  120. package/dist/esm/count-fetchers.js.map +1 -0
  121. package/dist/esm/data-source-fetchers.d.ts +14 -0
  122. package/dist/esm/data-source-fetchers.d.ts.map +1 -0
  123. package/dist/esm/data-source-fetchers.js +179 -0
  124. package/dist/esm/data-source-fetchers.js.map +1 -0
  125. package/dist/esm/fetchers/airtable.d.ts +6 -0
  126. package/dist/esm/fetchers/airtable.d.ts.map +1 -0
  127. package/dist/esm/fetchers/airtable.js +22 -0
  128. package/dist/esm/fetchers/airtable.js.map +1 -0
  129. package/dist/esm/fetchers/clickhouse.d.ts +6 -0
  130. package/dist/esm/fetchers/clickhouse.d.ts.map +1 -0
  131. package/dist/esm/fetchers/clickhouse.js +24 -0
  132. package/dist/esm/fetchers/clickhouse.js.map +1 -0
  133. package/dist/esm/fetchers/csv-file.d.ts +7 -0
  134. package/dist/esm/fetchers/csv-file.d.ts.map +1 -0
  135. package/dist/esm/fetchers/csv-file.js +30 -0
  136. package/dist/esm/fetchers/csv-file.js.map +1 -0
  137. package/dist/esm/fetchers/firestore.d.ts +6 -0
  138. package/dist/esm/fetchers/firestore.d.ts.map +1 -0
  139. package/dist/esm/fetchers/firestore.js +30 -0
  140. package/dist/esm/fetchers/firestore.js.map +1 -0
  141. package/dist/esm/fetchers/google-sheets.d.ts +6 -0
  142. package/dist/esm/fetchers/google-sheets.d.ts.map +1 -0
  143. package/dist/esm/fetchers/google-sheets.js +25 -0
  144. package/dist/esm/fetchers/google-sheets.js.map +1 -0
  145. package/dist/esm/fetchers/index.d.ts +17 -0
  146. package/dist/esm/fetchers/index.d.ts.map +1 -0
  147. package/dist/esm/fetchers/index.js +17 -0
  148. package/dist/esm/fetchers/index.js.map +1 -0
  149. package/dist/esm/fetchers/javascript.d.ts +7 -0
  150. package/dist/esm/fetchers/javascript.d.ts.map +1 -0
  151. package/dist/esm/fetchers/javascript.js +34 -0
  152. package/dist/esm/fetchers/javascript.js.map +1 -0
  153. package/dist/esm/fetchers/mariadb.d.ts +3 -0
  154. package/dist/esm/fetchers/mariadb.d.ts.map +1 -0
  155. package/dist/esm/fetchers/mariadb.js +18 -0
  156. package/dist/esm/fetchers/mariadb.js.map +1 -0
  157. package/dist/esm/fetchers/mongodb.d.ts +7 -0
  158. package/dist/esm/fetchers/mongodb.d.ts.map +1 -0
  159. package/dist/esm/fetchers/mongodb.js +46 -0
  160. package/dist/esm/fetchers/mongodb.js.map +1 -0
  161. package/dist/esm/fetchers/mysql.d.ts +3 -0
  162. package/dist/esm/fetchers/mysql.d.ts.map +1 -0
  163. package/dist/esm/fetchers/mysql.js +25 -0
  164. package/dist/esm/fetchers/mysql.js.map +1 -0
  165. package/dist/esm/fetchers/postgresql.d.ts +3 -0
  166. package/dist/esm/fetchers/postgresql.d.ts.map +1 -0
  167. package/dist/esm/fetchers/postgresql.js +20 -0
  168. package/dist/esm/fetchers/postgresql.js.map +1 -0
  169. package/dist/esm/fetchers/redis.d.ts +6 -0
  170. package/dist/esm/fetchers/redis.d.ts.map +1 -0
  171. package/dist/esm/fetchers/redis.js +41 -0
  172. package/dist/esm/fetchers/redis.js.map +1 -0
  173. package/dist/esm/fetchers/redshift.d.ts +2 -0
  174. package/dist/esm/fetchers/redshift.d.ts.map +1 -0
  175. package/dist/esm/fetchers/redshift.js +20 -0
  176. package/dist/esm/fetchers/redshift.js.map +1 -0
  177. package/dist/esm/fetchers/rest-api.d.ts +6 -0
  178. package/dist/esm/fetchers/rest-api.d.ts.map +1 -0
  179. package/dist/esm/fetchers/rest-api.js +53 -0
  180. package/dist/esm/fetchers/rest-api.js.map +1 -0
  181. package/dist/esm/fetchers/static-collection.d.ts +7 -0
  182. package/dist/esm/fetchers/static-collection.d.ts.map +1 -0
  183. package/dist/esm/fetchers/static-collection.js +18 -0
  184. package/dist/esm/fetchers/static-collection.js.map +1 -0
  185. package/dist/esm/fetchers/supabase.d.ts +7 -0
  186. package/dist/esm/fetchers/supabase.d.ts.map +1 -0
  187. package/dist/esm/fetchers/supabase.js +36 -0
  188. package/dist/esm/fetchers/supabase.js.map +1 -0
  189. package/dist/esm/fetchers/turso.d.ts +6 -0
  190. package/dist/esm/fetchers/turso.d.ts.map +1 -0
  191. package/dist/esm/fetchers/turso.js +20 -0
  192. package/dist/esm/fetchers/turso.js.map +1 -0
  193. package/dist/esm/index.d.ts +9 -0
  194. package/dist/esm/index.d.ts.map +1 -0
  195. package/dist/esm/index.js +306 -0
  196. package/dist/esm/index.js.map +1 -0
  197. package/dist/esm/pagination-plugin.d.ts +5 -0
  198. package/dist/esm/pagination-plugin.d.ts.map +1 -0
  199. package/dist/esm/pagination-plugin.js +1457 -0
  200. package/dist/esm/pagination-plugin.js.map +1 -0
  201. package/dist/esm/pagination-with-count.d.ts +6 -0
  202. package/dist/esm/pagination-with-count.d.ts.map +1 -0
  203. package/dist/esm/pagination-with-count.js +34 -0
  204. package/dist/esm/pagination-with-count.js.map +1 -0
  205. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  206. package/dist/esm/utils.d.ts +31 -0
  207. package/dist/esm/utils.d.ts.map +1 -0
  208. package/dist/esm/utils.js +722 -0
  209. package/dist/esm/utils.js.map +1 -0
  210. package/dist/esm/validation.d.ts +5 -0
  211. package/dist/esm/validation.d.ts.map +1 -0
  212. package/dist/esm/validation.js +25 -0
  213. package/dist/esm/validation.js.map +1 -0
  214. package/package.json +33 -0
  215. package/src/array-mapper-pagination.ts +113 -0
  216. package/src/count-fetchers.ts +99 -0
  217. package/src/data-source-fetchers.ts +313 -0
  218. package/src/fetchers/airtable.ts +153 -0
  219. package/src/fetchers/clickhouse.ts +127 -0
  220. package/src/fetchers/csv-file.ts +163 -0
  221. package/src/fetchers/firestore.ts +138 -0
  222. package/src/fetchers/google-sheets.ts +189 -0
  223. package/src/fetchers/index.ts +32 -0
  224. package/src/fetchers/javascript.ts +150 -0
  225. package/src/fetchers/mariadb.ts +230 -0
  226. package/src/fetchers/mongodb.ts +239 -0
  227. package/src/fetchers/mysql.ts +237 -0
  228. package/src/fetchers/postgresql.ts +247 -0
  229. package/src/fetchers/redis.ts +152 -0
  230. package/src/fetchers/redshift.ts +138 -0
  231. package/src/fetchers/rest-api.ts +148 -0
  232. package/src/fetchers/static-collection.ts +149 -0
  233. package/src/fetchers/supabase.ts +246 -0
  234. package/src/fetchers/turso.ts +131 -0
  235. package/src/index.ts +352 -0
  236. package/src/pagination-plugin.ts +2335 -0
  237. package/src/pagination-with-count.ts +89 -0
  238. package/src/utils.ts +1013 -0
  239. package/src/validation.ts +32 -0
  240. package/tsconfig.json +9 -0
@@ -0,0 +1,1457 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
46
+ import { ChunkType, FileType, } from '@teleporthq/teleport-types';
47
+ import * as types from '@babel/types';
48
+ import { generatePaginationLogic } from './array-mapper-pagination';
49
+ import { extractDataSourceIntoNextAPIFolder } from './utils';
50
+ export var createNextArrayMapperPaginationPlugin = function () {
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;
53
+ var _b, _c, _d;
54
+ return __generator(this, function (_e) {
55
+ uidl = structure.uidl, chunks = structure.chunks, dependencies = structure.dependencies, options = structure.options;
56
+ componentChunk = chunks.find(function (chunk) { return chunk.name === 'jsx-component'; });
57
+ if (!componentChunk || componentChunk.type !== ChunkType.AST) {
58
+ return [2 /*return*/, structure];
59
+ }
60
+ if (!options || !options.dataSources || !options.extractedResources) {
61
+ return [2 /*return*/, structure];
62
+ }
63
+ variableDeclaration = componentChunk.content;
64
+ if (!variableDeclaration.declarations || variableDeclaration.declarations.length === 0) {
65
+ return [2 /*return*/, structure];
66
+ }
67
+ declarator = variableDeclaration.declarations[0];
68
+ if (!declarator.init) {
69
+ return [2 /*return*/, structure];
70
+ }
71
+ arrowFunction = declarator.init;
72
+ if (!arrowFunction.body) {
73
+ return [2 /*return*/, structure];
74
+ }
75
+ blockStatement = arrowFunction.body;
76
+ _a = detectPaginationsAndSearchFromJSX(blockStatement, uidl.node), paginatedMappers = _a.paginatedMappers, searchOnlyMappers = _a.searchOnlyMappers, paginationOnlyMappers = _a.paginationOnlyMappers;
77
+ if (paginatedMappers.length === 0 &&
78
+ searchOnlyMappers.length === 0 &&
79
+ paginationOnlyMappers.length === 0) {
80
+ return [2 /*return*/, structure];
81
+ }
82
+ detectedPaginations = __spreadArray(__spreadArray([], paginatedMappers, true), paginationOnlyMappers, true);
83
+ detectedSearchOnly = searchOnlyMappers;
84
+ if (!dependencies.useState) {
85
+ dependencies.useState = {
86
+ type: 'library',
87
+ path: 'react',
88
+ version: '',
89
+ meta: {
90
+ namedImport: true,
91
+ },
92
+ };
93
+ }
94
+ if (!dependencies.useMemo) {
95
+ dependencies.useMemo = {
96
+ type: 'library',
97
+ path: 'react',
98
+ version: '',
99
+ meta: {
100
+ namedImport: true,
101
+ },
102
+ };
103
+ }
104
+ if (!dependencies.useCallback) {
105
+ dependencies.useCallback = {
106
+ type: 'library',
107
+ path: 'react',
108
+ version: '',
109
+ meta: {
110
+ namedImport: true,
111
+ },
112
+ };
113
+ }
114
+ if (!dependencies.useRef) {
115
+ dependencies.useRef = {
116
+ type: 'library',
117
+ path: 'react',
118
+ version: '',
119
+ meta: {
120
+ namedImport: true,
121
+ },
122
+ };
123
+ }
124
+ if (!componentChunk.meta) {
125
+ componentChunk.meta = {};
126
+ }
127
+ componentChunk.meta.isClientComponent = true;
128
+ paginationInfos = [];
129
+ getStaticPropsChunk = chunks.find(function (chunk) { return chunk.name === 'getStaticProps'; });
130
+ isPage = !!getStaticPropsChunk;
131
+ isComponent = !isPage;
132
+ opts = options;
133
+ perPageMap = ((_b = opts.paginationConfig) === null || _b === void 0 ? void 0 : _b.perPageMap) || new Map();
134
+ searchConfigMap = ((_c = opts.paginationConfig) === null || _c === void 0 ? void 0 : _c.searchConfigMap) || new Map();
135
+ queryColumnsMap = ((_d = opts.paginationConfig) === null || _d === void 0 ? void 0 : _d.queryColumnsMap) || new Map();
136
+ detectedPaginations.forEach(function (detected, index) {
137
+ var paginationNodeId = "pg_".concat(index);
138
+ // Use arrayMapperRenderProp if available, otherwise fall back to dataSourceIdentifier
139
+ var lookupKey = detected.arrayMapperRenderProp || detected.dataSourceIdentifier;
140
+ var perPage = perPageMap.get(lookupKey) || 10;
141
+ var searchConfig = searchConfigMap.get(lookupKey);
142
+ // queryColumns is keyed by dataSourceIdentifier, not array mapper render prop
143
+ var queryColumns = queryColumnsMap.get(detected.dataSourceIdentifier);
144
+ var info = generatePaginationLogic(paginationNodeId, detected.dataSourceIdentifier, perPage, searchConfig, queryColumns);
145
+ paginationInfos.push(info);
146
+ // If both pagination and search are enabled, combine them into a single state object
147
+ if (info.searchEnabled && info.searchQueryVar && info.setSearchQueryVar) {
148
+ // Combined state: { page: 1, debouncedQuery: '' }
149
+ var combinedStateVar = "paginationState_pg_".concat(index);
150
+ var setCombinedStateVar = "setPaginationState_pg_".concat(index);
151
+ var combinedStateAST = types.variableDeclaration('const', [
152
+ types.variableDeclarator(types.arrayPattern([
153
+ types.identifier(combinedStateVar),
154
+ types.identifier(setCombinedStateVar),
155
+ ]), types.callExpression(types.identifier('useState'), [
156
+ types.objectExpression([
157
+ types.objectProperty(types.identifier('page'), types.numericLiteral(1)),
158
+ types.objectProperty(types.identifier('debouncedQuery'), types.stringLiteral('')),
159
+ ]),
160
+ ])),
161
+ ]);
162
+ blockStatement.body.unshift(combinedStateAST);
163
+ // Still need the immediate search query state for the input
164
+ var searchStateAST = types.variableDeclaration('const', [
165
+ types.variableDeclarator(types.arrayPattern([
166
+ types.identifier(info.searchQueryVar),
167
+ types.identifier(info.setSearchQueryVar),
168
+ ]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
169
+ ]);
170
+ blockStatement.body.unshift(searchStateAST);
171
+ info.combinedStateVar = combinedStateVar;
172
+ info.setCombinedStateVar = setCombinedStateVar;
173
+ }
174
+ else {
175
+ // If search is not enabled, just add regular page state
176
+ var pageStateAST = types.variableDeclaration('const', [
177
+ types.variableDeclarator(types.arrayPattern([
178
+ types.identifier(info.pageStateVar),
179
+ types.identifier(info.setPageStateVar),
180
+ ]), types.callExpression(types.identifier('useState'), [types.numericLiteral(1)])),
181
+ ]);
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
+ }
215
+ });
216
+ hasSearchEnabled = paginationInfos.some(function (info) { return info.searchEnabled; });
217
+ if (hasSearchEnabled && !dependencies.useEffect) {
218
+ dependencies.useEffect = {
219
+ type: 'library',
220
+ path: 'react',
221
+ version: '',
222
+ meta: {
223
+ namedImport: true,
224
+ },
225
+ };
226
+ }
227
+ firstReturnIndex = blockStatement.body.findIndex(function (stmt) { return stmt.type === 'ReturnStatement'; });
228
+ insertIndex = firstReturnIndex !== -1 ? firstReturnIndex : blockStatement.body.length;
229
+ // Add effects in reverse order so they appear in correct order
230
+ paginationInfos.forEach(function (info) {
231
+ if (info.searchEnabled &&
232
+ info.searchQueryVar &&
233
+ info.debouncedSearchQueryVar &&
234
+ info.setDebouncedSearchQueryVar) {
235
+ // Add effect that updates debounced search after delay
236
+ var skipDebounceOnMountRefVar = info.skipDebounceOnMountRefVar;
237
+ var setCombinedStateVar = info.setCombinedStateVar;
238
+ var debounceEffect = types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
239
+ types.arrowFunctionExpression([], types.blockStatement([
240
+ types.ifStatement(types.memberExpression(types.identifier(skipDebounceOnMountRefVar), types.identifier('current')), types.blockStatement([
241
+ types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier(skipDebounceOnMountRefVar), types.identifier('current')), types.booleanLiteral(false))),
242
+ types.returnStatement(),
243
+ ])),
244
+ types.variableDeclaration('const', [
245
+ types.variableDeclarator(types.identifier('timer'), types.callExpression(types.identifier('setTimeout'), [
246
+ types.arrowFunctionExpression([], types.blockStatement([
247
+ types.expressionStatement(types.callExpression(types.identifier(setCombinedStateVar), [
248
+ types.objectExpression([
249
+ types.objectProperty(types.identifier('page'), types.numericLiteral(1)),
250
+ types.objectProperty(types.identifier('debouncedQuery'), types.identifier(info.searchQueryVar)),
251
+ ]),
252
+ ])),
253
+ ])),
254
+ types.numericLiteral(info.searchDebounce || 300),
255
+ ])),
256
+ ]),
257
+ types.returnStatement(types.arrowFunctionExpression([], types.callExpression(types.identifier('clearTimeout'), [
258
+ types.identifier('timer'),
259
+ ]))),
260
+ ])),
261
+ types.arrayExpression([types.identifier(info.searchQueryVar)]),
262
+ ]));
263
+ blockStatement.body.splice(insertIndex, 0, debounceEffect);
264
+ // 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
+ ]),
312
+ ]),
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
+ ])),
322
+ ])),
323
+ ])),
324
+ ])),
325
+ ])),
326
+ ])),
327
+ types.arrayExpression([
328
+ types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery')),
329
+ ]),
330
+ ]));
331
+ blockStatement.body.splice(insertIndex, 0, refetchCountEffect);
332
+ }
333
+ }
334
+ }
335
+ }
336
+ }
337
+ });
338
+ // For components, add useEffect to fetch count on mount
339
+ if (isComponent) {
340
+ if (!dependencies.useEffect) {
341
+ dependencies.useEffect = {
342
+ type: 'library',
343
+ path: 'react',
344
+ version: '',
345
+ meta: {
346
+ namedImport: true,
347
+ },
348
+ };
349
+ }
350
+ dataSourceToInfos_1 = new Map();
351
+ paginationInfos.forEach(function (info) {
352
+ var detected = detectedPaginations.find(function (d) { return d.dataSourceIdentifier === info.dataSourceIdentifier; });
353
+ if (!detected) {
354
+ return;
355
+ }
356
+ var resourceDefAttr = detected.dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'resourceDefinition'; });
357
+ if (!resourceDefAttr ||
358
+ !resourceDefAttr.value ||
359
+ resourceDefAttr.value.type !== 'JSXExpressionContainer') {
360
+ return;
361
+ }
362
+ var resourceDef = resourceDefAttr.value.expression;
363
+ if (resourceDef.type !== 'ObjectExpression') {
364
+ return;
365
+ }
366
+ var dataSourceIdProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceId'; });
367
+ var tableNameProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'tableName'; });
368
+ var dataSourceTypeProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceType'; });
369
+ if (!dataSourceIdProp || !tableNameProp || !dataSourceTypeProp) {
370
+ return;
371
+ }
372
+ var dataSourceId = dataSourceIdProp.value.value;
373
+ var tableName = tableNameProp.value.value;
374
+ var dataSourceType = dataSourceTypeProp.value.value;
375
+ var fileName = "".concat(dataSourceType, "-").concat(tableName, "-").concat(dataSourceId.substring(0, 8));
376
+ // Group by data source identifier
377
+ if (!dataSourceToInfos_1.has(info.dataSourceIdentifier)) {
378
+ dataSourceToInfos_1.set(info.dataSourceIdentifier, []);
379
+ }
380
+ dataSourceToInfos_1.get(info.dataSourceIdentifier).push({ info: info, detected: detected, fileName: fileName });
381
+ });
382
+ // Create ONE useEffect per unique data source
383
+ dataSourceToInfos_1.forEach(function (infos) {
384
+ var fileName = infos[0].fileName;
385
+ // Create array of setState calls - one for each pagination using this data source
386
+ var setStateStatements = infos.map(function (_a) {
387
+ var info = _a.info;
388
+ var setMaxPagesStateVar = info.setMaxPagesStateVar;
389
+ return types.expressionStatement(types.callExpression(types.identifier(setMaxPagesStateVar), [
390
+ types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('ceil')), [
391
+ types.binaryExpression('/', types.memberExpression(types.identifier('data'), types.identifier('count')), types.numericLiteral(info.perPage)),
392
+ ]),
393
+ ]));
394
+ });
395
+ // Create useEffect to fetch count on mount - sets ALL maxPages for this data source
396
+ var useEffectAST = types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
397
+ types.arrowFunctionExpression([], types.blockStatement([
398
+ types.expressionStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.identifier('fetch'), [
399
+ types.stringLiteral("/api/".concat(fileName, "-count")),
400
+ ]), types.identifier('then')), [
401
+ types.arrowFunctionExpression([types.identifier('res')], types.callExpression(types.memberExpression(types.identifier('res'), types.identifier('json')), [])),
402
+ ]), types.identifier('then')), [
403
+ types.arrowFunctionExpression([types.identifier('data')], types.blockStatement([
404
+ types.ifStatement(types.logicalExpression('&&', types.identifier('data'), types.memberExpression(types.identifier('data'), types.identifier('count'))), types.blockStatement(setStateStatements)),
405
+ ])),
406
+ ])),
407
+ ])),
408
+ types.arrayExpression([]),
409
+ ]));
410
+ blockStatement.body.unshift(useEffectAST);
411
+ });
412
+ }
413
+ createAPIRoutesForPaginatedDataSources(uidl.node, options.dataSources, componentChunk, options.extractedResources, paginationInfos, isComponent);
414
+ detectedPaginations.forEach(function (detected, index) {
415
+ addPaginationParamsToDataProvider(detected.dataProviderJSX, paginationInfos[index], index);
416
+ });
417
+ modifyPaginationButtons(blockStatement, detectedPaginations, paginationInfos);
418
+ modifySearchInputs(blockStatement, detectedPaginations, paginationInfos);
419
+ if (isPage) {
420
+ modifyGetStaticPropsForPagination(chunks, paginationInfos);
421
+ }
422
+ searchOnlyDataSources = detectedSearchOnly;
423
+ if (searchOnlyDataSources.length > 0) {
424
+ handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, insertIndex, dependencies);
425
+ // Create API routes for search-only data sources
426
+ createAPIRoutesForSearchOnlyDataSources(uidl.node, options.dataSources, componentChunk, options.extractedResources, searchOnlyDataSources);
427
+ }
428
+ return [2 /*return*/, structure];
429
+ });
430
+ }); };
431
+ return paginationPlugin;
432
+ };
433
+ function detectPaginationsAndSearchFromJSX(blockStatement, uidlNode) {
434
+ var dataProviderMap = new Map();
435
+ var arrayMapperInfoMap = new Map();
436
+ if (uidlNode) {
437
+ var collectArrayMapperInfo_1 = function (node) {
438
+ var _a, _b, _c, _d, _e;
439
+ if (!node) {
440
+ return;
441
+ }
442
+ if (node.type === 'data-source-list' && ((_a = node.content) === null || _a === void 0 ? void 0 : _a.renderPropIdentifier)) {
443
+ var dataSourceIdentifier_1 = node.content.renderPropIdentifier;
444
+ if ((_d = (_c = (_b = node.content.nodes) === null || _b === void 0 ? void 0 : _b.success) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.children) {
445
+ node.content.nodes.success.content.children.forEach(function (child) {
446
+ var _a;
447
+ if (child.type === 'cms-list-repeater' && ((_a = child.content) === null || _a === void 0 ? void 0 : _a.renderPropIdentifier)) {
448
+ var arrayMapperRenderProp = child.content.renderPropIdentifier;
449
+ // Key by array mapper render prop (unique), not data source identifier
450
+ arrayMapperInfoMap.set(arrayMapperRenderProp, {
451
+ dataSourceIdentifier: dataSourceIdentifier_1,
452
+ renderProp: arrayMapperRenderProp,
453
+ paginated: child.content.paginated || false,
454
+ searchEnabled: child.content.searchEnabled || false,
455
+ });
456
+ }
457
+ });
458
+ }
459
+ }
460
+ if ((_e = node.content) === null || _e === void 0 ? void 0 : _e.children) {
461
+ node.content.children.forEach(function (child) { return collectArrayMapperInfo_1(child); });
462
+ }
463
+ if (node.children && Array.isArray(node.children)) {
464
+ node.children.forEach(function (child) { return collectArrayMapperInfo_1(child); });
465
+ }
466
+ };
467
+ collectArrayMapperInfo_1(uidlNode);
468
+ }
469
+ var dataProvidersWithParents = [];
470
+ var findDataProvidersAndParents = function (node, parent) {
471
+ var _a, _b;
472
+ if (parent === void 0) { parent = null; }
473
+ if (!node) {
474
+ return;
475
+ }
476
+ // Check if this is a DataProvider
477
+ if (node.type === 'JSXElement' && ((_b = (_a = node.openingElement) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.name) === 'DataProvider') {
478
+ dataProvidersWithParents.push({
479
+ dataProvider: node,
480
+ parent: parent,
481
+ });
482
+ }
483
+ // Only recurse through JSX structure, not into embedded expressions or code
484
+ if (node.type === 'ReturnStatement' && node.argument) {
485
+ findDataProvidersAndParents(node.argument, parent);
486
+ }
487
+ else if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
488
+ // Recurse through JSX children
489
+ if (node.children && Array.isArray(node.children)) {
490
+ node.children.forEach(function (child) { return findDataProvidersAndParents(child, node); });
491
+ }
492
+ }
493
+ else if (node.type === 'JSXExpressionContainer') {
494
+ // For expression containers, continue but don't go into the expression itself
495
+ if (node.expression &&
496
+ (node.expression.type === 'JSXElement' || node.expression.type === 'JSXFragment')) {
497
+ findDataProvidersAndParents(node.expression, parent);
498
+ }
499
+ }
500
+ else if (node.type === 'BlockStatement') {
501
+ // For block statements (function bodies), look through body array
502
+ if (node.body && Array.isArray(node.body)) {
503
+ node.body.forEach(function (stmt) { return findDataProvidersAndParents(stmt, node); });
504
+ }
505
+ }
506
+ else if (node.type === 'ConditionalExpression') {
507
+ // Check both branches of conditional
508
+ findDataProvidersAndParents(node.consequent, parent);
509
+ findDataProvidersAndParents(node.alternate, parent);
510
+ }
511
+ };
512
+ findDataProvidersAndParents(blockStatement);
513
+ // Now process each DataProvider and find its siblings
514
+ dataProvidersWithParents.forEach(function (_a) {
515
+ var _b, _c;
516
+ var dataProvider = _a.dataProvider, parent = _a.parent;
517
+ var nameAttr = dataProvider.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'name'; });
518
+ // Find the array mapper render prop by looking inside renderSuccess -> Repeater -> renderItem param
519
+ var renderSuccessAttr = dataProvider.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'renderSuccess'; });
520
+ var arrayMapperRenderProp;
521
+ if (renderSuccessAttr && ((_b = renderSuccessAttr.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
522
+ var renderFunc = renderSuccessAttr.value.expression;
523
+ if (renderFunc.type === 'ArrowFunctionExpression') {
524
+ // Look for Repeater inside the render function
525
+ var findRepeater_1 = function (node) {
526
+ var _a, _b;
527
+ if (!node) {
528
+ return null;
529
+ }
530
+ if (node.type === 'JSXElement' && ((_b = (_a = node.openingElement) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.name) === 'Repeater') {
531
+ return node;
532
+ }
533
+ if (node.body) {
534
+ return findRepeater_1(node.body);
535
+ }
536
+ if (node.children && Array.isArray(node.children)) {
537
+ for (var _i = 0, _c = node.children; _i < _c.length; _i++) {
538
+ var child = _c[_i];
539
+ var result = findRepeater_1(child);
540
+ if (result) {
541
+ return result;
542
+ }
543
+ }
544
+ }
545
+ if (node.type === 'JSXFragment' || node.type === 'JSXElement') {
546
+ if (node.children && Array.isArray(node.children)) {
547
+ for (var _d = 0, _e = node.children; _d < _e.length; _d++) {
548
+ var child = _e[_d];
549
+ var result = findRepeater_1(child);
550
+ if (result) {
551
+ return result;
552
+ }
553
+ }
554
+ }
555
+ }
556
+ if (node.type === 'JSXExpressionContainer') {
557
+ return findRepeater_1(node.expression);
558
+ }
559
+ if (node.expression) {
560
+ return findRepeater_1(node.expression);
561
+ }
562
+ if (node.consequent) {
563
+ var result = findRepeater_1(node.consequent);
564
+ if (result) {
565
+ return result;
566
+ }
567
+ }
568
+ if (node.alternate) {
569
+ return findRepeater_1(node.alternate);
570
+ }
571
+ return null;
572
+ };
573
+ var repeater = findRepeater_1(renderFunc);
574
+ if (repeater) {
575
+ // Find renderItem attribute on Repeater
576
+ var renderItemAttr = repeater.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'renderItem'; });
577
+ if (renderItemAttr && ((_c = renderItemAttr.value) === null || _c === void 0 ? void 0 : _c.type) === 'JSXExpressionContainer') {
578
+ var renderItemFunc = renderItemAttr.value.expression;
579
+ if (renderItemFunc.type === 'ArrowFunctionExpression' &&
580
+ renderItemFunc.params &&
581
+ renderItemFunc.params.length > 0) {
582
+ var param = renderItemFunc.params[0];
583
+ if (param.type === 'Identifier') {
584
+ arrayMapperRenderProp = param.name;
585
+ }
586
+ }
587
+ }
588
+ }
589
+ }
590
+ }
591
+ if (!nameAttr ||
592
+ !nameAttr.value ||
593
+ nameAttr.value.type !== 'JSXExpressionContainer' ||
594
+ !arrayMapperRenderProp) {
595
+ return;
596
+ }
597
+ var dataProviderIdentifier = nameAttr.value.expression.value;
598
+ var paginationNodeInfo = null;
599
+ var searchInputInfo = null;
600
+ // Look through parent's children for siblings
601
+ if (parent && parent.children && Array.isArray(parent.children)) {
602
+ parent.children.forEach(function (sibling) {
603
+ var _a, _b, _c;
604
+ if (sibling === dataProvider) {
605
+ return;
606
+ }
607
+ if (sibling.type === 'JSXElement') {
608
+ var siblingClassName = getClassName(((_a = sibling.openingElement) === null || _a === void 0 ? void 0 : _a.attributes) || []);
609
+ var siblingElementName = (_c = (_b = sibling.openingElement) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.name;
610
+ // Found pagination node
611
+ if (siblingClassName && siblingClassName.includes('cms-pagination-node')) {
612
+ var prevClass = findChildWithClass(sibling, 'previous');
613
+ var nextClass = findChildWithClass(sibling, 'next');
614
+ if (prevClass || nextClass) {
615
+ paginationNodeInfo = {
616
+ class: siblingClassName,
617
+ prevClass: prevClass,
618
+ nextClass: nextClass,
619
+ };
620
+ }
621
+ }
622
+ // Found search container - search for input inside it
623
+ if (siblingClassName && siblingClassName.includes('data-source-search-node')) {
624
+ if (sibling.children && Array.isArray(sibling.children)) {
625
+ sibling.children.forEach(function (searchChild) {
626
+ var _a, _b, _c;
627
+ if (searchChild.type === 'JSXElement') {
628
+ var searchChildElementName = (_b = (_a = searchChild.openingElement) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.name;
629
+ var searchChildClassName = getClassName(((_c = searchChild.openingElement) === null || _c === void 0 ? void 0 : _c.attributes) || []);
630
+ if (searchChildClassName &&
631
+ searchChildClassName.includes('search-input') &&
632
+ searchChildElementName === 'input') {
633
+ searchInputInfo = {
634
+ class: searchChildClassName,
635
+ jsx: searchChild,
636
+ };
637
+ }
638
+ }
639
+ });
640
+ }
641
+ }
642
+ // Also check if search input is a direct sibling
643
+ if (siblingClassName &&
644
+ siblingClassName.includes('search-input') &&
645
+ siblingElementName === 'input') {
646
+ searchInputInfo = {
647
+ class: siblingClassName,
648
+ jsx: sibling,
649
+ };
650
+ }
651
+ }
652
+ });
653
+ }
654
+ // Record the DataProvider with its pagination/search info
655
+ var uniqueKey = "".concat(dataProviderIdentifier, "__").concat(arrayMapperRenderProp);
656
+ dataProviderMap.set(uniqueKey, {
657
+ identifier: dataProviderIdentifier,
658
+ dataProvider: dataProvider,
659
+ arrayMapperRenderProp: arrayMapperRenderProp,
660
+ paginationNode: paginationNodeInfo || undefined,
661
+ searchInput: searchInputInfo || undefined,
662
+ hasPagination: !!paginationNodeInfo,
663
+ hasSearch: !!searchInputInfo,
664
+ });
665
+ });
666
+ // Categorize data providers
667
+ var paginatedMappers = [];
668
+ var searchOnlyMappers = [];
669
+ var paginationOnlyMappers = [];
670
+ var plainMappers = [];
671
+ dataProviderMap.forEach(function (info) {
672
+ var _a, _b, _c, _d;
673
+ if (info.hasPagination && info.hasSearch) {
674
+ // Pagination + Search
675
+ paginatedMappers.push({
676
+ paginationNodeClass: info.paginationNode.class,
677
+ prevButtonClass: info.paginationNode.prevClass,
678
+ nextButtonClass: info.paginationNode.nextClass,
679
+ dataSourceIdentifier: info.identifier,
680
+ dataProviderJSX: info.dataProvider,
681
+ arrayMapperRenderProp: info.arrayMapperRenderProp,
682
+ searchInputClass: (_a = info.searchInput) === null || _a === void 0 ? void 0 : _a.class,
683
+ searchInputJSX: (_b = info.searchInput) === null || _b === void 0 ? void 0 : _b.jsx,
684
+ });
685
+ }
686
+ else if (info.hasPagination && !info.hasSearch) {
687
+ // Pagination only
688
+ paginationOnlyMappers.push({
689
+ paginationNodeClass: info.paginationNode.class,
690
+ prevButtonClass: info.paginationNode.prevClass,
691
+ nextButtonClass: info.paginationNode.nextClass,
692
+ dataSourceIdentifier: info.identifier,
693
+ dataProviderJSX: info.dataProvider,
694
+ arrayMapperRenderProp: info.arrayMapperRenderProp,
695
+ searchInputClass: undefined,
696
+ searchInputJSX: undefined,
697
+ });
698
+ }
699
+ else if (!info.hasPagination && info.hasSearch) {
700
+ // Search only
701
+ searchOnlyMappers.push({
702
+ paginationNodeClass: '',
703
+ prevButtonClass: null,
704
+ nextButtonClass: null,
705
+ dataSourceIdentifier: info.identifier,
706
+ dataProviderJSX: info.dataProvider,
707
+ arrayMapperRenderProp: info.arrayMapperRenderProp,
708
+ searchInputClass: (_c = info.searchInput) === null || _c === void 0 ? void 0 : _c.class,
709
+ searchInputJSX: (_d = info.searchInput) === null || _d === void 0 ? void 0 : _d.jsx,
710
+ });
711
+ }
712
+ else {
713
+ // Plain (no pagination, no search)
714
+ plainMappers.push({
715
+ paginationNodeClass: '',
716
+ prevButtonClass: null,
717
+ nextButtonClass: null,
718
+ dataSourceIdentifier: info.identifier,
719
+ dataProviderJSX: info.dataProvider,
720
+ arrayMapperRenderProp: info.arrayMapperRenderProp,
721
+ searchInputClass: undefined,
722
+ searchInputJSX: undefined,
723
+ });
724
+ }
725
+ });
726
+ return { paginatedMappers: paginatedMappers, searchOnlyMappers: searchOnlyMappers, paginationOnlyMappers: paginationOnlyMappers, plainMappers: plainMappers };
727
+ }
728
+ function handleSearchOnlyArrayMappers(blockStatement, searchOnlyDataSources, searchConfigMap, queryColumnsMap, insertIndex, dependencies) {
729
+ searchOnlyDataSources.forEach(function (detected, index) {
730
+ var searchId = "search_".concat(index);
731
+ var searchQueryVar = "".concat(searchId, "_query");
732
+ var setSearchQueryVar = "set".concat(searchQueryVar.charAt(0).toUpperCase() + searchQueryVar.slice(1));
733
+ var debouncedSearchQueryVar = "debounced".concat(searchQueryVar.charAt(0).toUpperCase() + searchQueryVar.slice(1));
734
+ var setDebouncedSearchQueryVar = "set".concat(debouncedSearchQueryVar.charAt(0).toUpperCase() + debouncedSearchQueryVar.slice(1));
735
+ var skipDebounceOnMountRefVar = "skipDebounceOnMount".concat(searchId);
736
+ var searchConfig = searchConfigMap.get(detected.dataSourceIdentifier);
737
+ var searchDebounce = (searchConfig === null || searchConfig === void 0 ? void 0 : searchConfig.searchDebounce) || 300;
738
+ var queryColumns = queryColumnsMap.get(detected.dataSourceIdentifier);
739
+ // Add search query state
740
+ var searchStateAST = types.variableDeclaration('const', [
741
+ types.variableDeclarator(types.arrayPattern([types.identifier(searchQueryVar), types.identifier(setSearchQueryVar)]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
742
+ ]);
743
+ blockStatement.body.unshift(searchStateAST);
744
+ // Add debounced search state
745
+ var debouncedSearchStateAST = types.variableDeclaration('const', [
746
+ types.variableDeclarator(types.arrayPattern([
747
+ types.identifier(debouncedSearchQueryVar),
748
+ types.identifier(setDebouncedSearchQueryVar),
749
+ ]), types.callExpression(types.identifier('useState'), [types.stringLiteral('')])),
750
+ ]);
751
+ blockStatement.body.unshift(debouncedSearchStateAST);
752
+ // Add skip ref
753
+ var skipRefAST = types.variableDeclaration('const', [
754
+ types.variableDeclarator(types.identifier(skipDebounceOnMountRefVar), types.callExpression(types.identifier('useRef'), [types.booleanLiteral(true)])),
755
+ ]);
756
+ blockStatement.body.unshift(skipRefAST);
757
+ // Add useEffect for debouncing
758
+ if (!dependencies.useEffect) {
759
+ dependencies.useEffect = {
760
+ type: 'library',
761
+ path: 'react',
762
+ version: '',
763
+ meta: {
764
+ namedImport: true,
765
+ },
766
+ };
767
+ }
768
+ var debounceEffect = types.expressionStatement(types.callExpression(types.identifier('useEffect'), [
769
+ types.arrowFunctionExpression([], types.blockStatement([
770
+ types.ifStatement(types.memberExpression(types.identifier(skipDebounceOnMountRefVar), types.identifier('current')), types.blockStatement([
771
+ types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier(skipDebounceOnMountRefVar), types.identifier('current')), types.booleanLiteral(false))),
772
+ types.returnStatement(),
773
+ ])),
774
+ types.variableDeclaration('const', [
775
+ types.variableDeclarator(types.identifier('timer'), types.callExpression(types.identifier('setTimeout'), [
776
+ types.arrowFunctionExpression([], types.blockStatement([
777
+ types.expressionStatement(types.callExpression(types.identifier(setDebouncedSearchQueryVar), [
778
+ types.identifier(searchQueryVar),
779
+ ])),
780
+ ])),
781
+ types.numericLiteral(searchDebounce),
782
+ ])),
783
+ ]),
784
+ types.returnStatement(types.arrowFunctionExpression([], types.callExpression(types.identifier('clearTimeout'), [types.identifier('timer')]))),
785
+ ])),
786
+ types.arrayExpression([types.identifier(searchQueryVar)]),
787
+ ]));
788
+ blockStatement.body.splice(insertIndex, 0, debounceEffect);
789
+ // Modify DataProvider to include search params (even without queryColumns)
790
+ if (detected.dataProviderJSX) {
791
+ addSearchParamsToDataProvider(detected.dataProviderJSX, {
792
+ debouncedSearchQueryVar: debouncedSearchQueryVar,
793
+ queryColumns: queryColumns || [],
794
+ });
795
+ }
796
+ // Modify search input
797
+ if (detected.searchInputJSX) {
798
+ addSearchInputHandlers(detected.searchInputJSX, {
799
+ searchQueryVar: searchQueryVar,
800
+ setSearchQueryVar: setSearchQueryVar,
801
+ searchEnabled: true,
802
+ });
803
+ }
804
+ });
805
+ }
806
+ function addSearchParamsToDataProvider(dataProviderJSX, config) {
807
+ var _a, _b;
808
+ if (!dataProviderJSX || !dataProviderJSX.openingElement) {
809
+ return;
810
+ }
811
+ var debouncedSearchQueryVar = config.debouncedSearchQueryVar, queryColumns = config.queryColumns;
812
+ // 1. Update params to be wrapped in useMemo
813
+ var existingParamsAttr = dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'params'; });
814
+ if (existingParamsAttr && ((_a = existingParamsAttr.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer') {
815
+ var paramsObj = existingParamsAttr.value.expression;
816
+ if (paramsObj.type === 'ObjectExpression') {
817
+ // Add query to existing params properties
818
+ paramsObj.properties.push(types.objectProperty(types.identifier('query'), types.identifier(debouncedSearchQueryVar)));
819
+ // Add queryColumns only if they exist
820
+ if (queryColumns.length > 0) {
821
+ paramsObj.properties.push(types.objectProperty(types.identifier('queryColumns'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.arrayExpression(queryColumns.map(function (col) { return types.stringLiteral(col); }))])));
822
+ }
823
+ // Wrap in useMemo with debouncedSearchQueryVar as dependency
824
+ var memoizedParamsValue = types.callExpression(types.identifier('useMemo'), [
825
+ types.arrowFunctionExpression([], paramsObj),
826
+ types.arrayExpression([types.identifier(debouncedSearchQueryVar)]),
827
+ ]);
828
+ existingParamsAttr.value.expression = memoizedParamsValue;
829
+ }
830
+ }
831
+ // 2. Update initialData to be conditional on empty search
832
+ var existingInitialDataAttr = dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'initialData'; });
833
+ if (existingInitialDataAttr && ((_b = existingInitialDataAttr.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
834
+ var currentInitialData = existingInitialDataAttr.value.expression;
835
+ // Make it conditional: only use initialData if search is empty
836
+ existingInitialDataAttr.value.expression = types.conditionalExpression(types.unaryExpression('!', types.identifier(debouncedSearchQueryVar), true), currentInitialData, types.identifier('undefined'));
837
+ }
838
+ // 3. Update key to include search query
839
+ var existingKeyAttr = dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'key'; });
840
+ var keyExpression = types.templateLiteral([
841
+ types.templateElement({ raw: 'search-', cooked: 'search-' }),
842
+ types.templateElement({ raw: '', cooked: '' }),
843
+ ], [types.identifier(debouncedSearchQueryVar)]);
844
+ var keyAttr = types.jsxAttribute(types.jsxIdentifier('key'), types.jsxExpressionContainer(keyExpression));
845
+ if (existingKeyAttr) {
846
+ var index = dataProviderJSX.openingElement.attributes.indexOf(existingKeyAttr);
847
+ dataProviderJSX.openingElement.attributes[index] = keyAttr;
848
+ }
849
+ else {
850
+ dataProviderJSX.openingElement.attributes.push(keyAttr);
851
+ }
852
+ }
853
+ function addPaginationParamsToDataProvider(dataProviderJSX, info, paginationIndex) {
854
+ var _a;
855
+ if (!dataProviderJSX || !dataProviderJSX.openingElement) {
856
+ return;
857
+ }
858
+ var combinedStateVar = info.combinedStateVar;
859
+ var paramsProperties;
860
+ var dependencies;
861
+ if (info.searchEnabled && combinedStateVar) {
862
+ // Use combined state for both page and query
863
+ paramsProperties = [
864
+ types.objectProperty(types.identifier('page'), types.memberExpression(types.identifier(combinedStateVar), types.identifier('page'))),
865
+ types.objectProperty(types.identifier('perPage'), types.numericLiteral(info.perPage)),
866
+ types.objectProperty(types.identifier('query'), types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery'))),
867
+ ];
868
+ if (info.queryColumns && info.queryColumns.length > 0) {
869
+ paramsProperties.push(types.objectProperty(types.identifier('queryColumns'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.arrayExpression(info.queryColumns.map(function (col) { return types.stringLiteral(col); }))])));
870
+ }
871
+ // Single dependency: the combined state object
872
+ dependencies = [types.identifier(combinedStateVar)];
873
+ }
874
+ else {
875
+ // Pagination only (no search)
876
+ paramsProperties = [
877
+ types.objectProperty(types.identifier('page'), types.identifier(info.pageStateVar)),
878
+ types.objectProperty(types.identifier('perPage'), types.numericLiteral(info.perPage)),
879
+ ];
880
+ dependencies = [types.identifier(info.pageStateVar)];
881
+ }
882
+ // Wrap params in useMemo to prevent unnecessary refetches
883
+ var memoizedParamsValue = types.callExpression(types.identifier('useMemo'), [
884
+ types.arrowFunctionExpression([], types.objectExpression(paramsProperties)),
885
+ types.arrayExpression(dependencies),
886
+ ]);
887
+ var paramsAttr = types.jsxAttribute(types.jsxIdentifier('params'), types.jsxExpressionContainer(memoizedParamsValue));
888
+ var existingParamsAttr = dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'params'; });
889
+ if (existingParamsAttr) {
890
+ var index = dataProviderJSX.openingElement.attributes.indexOf(existingParamsAttr);
891
+ dataProviderJSX.openingElement.attributes[index] = paramsAttr;
892
+ }
893
+ else {
894
+ dataProviderJSX.openingElement.attributes.push(paramsAttr);
895
+ }
896
+ var existingInitialDataAttr = dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'initialData'; });
897
+ if (existingInitialDataAttr && existingInitialDataAttr.value) {
898
+ // Update initialData to use the paginated prop name
899
+ var paginatedPropName = "".concat(info.dataSourceIdentifier, "_pg_").concat(paginationIndex);
900
+ // If search is enabled, use combined state; otherwise use page state
901
+ var condition = void 0;
902
+ if (info.searchEnabled && combinedStateVar) {
903
+ condition = types.logicalExpression('&&', types.binaryExpression('===', types.memberExpression(types.identifier(combinedStateVar), types.identifier('page')), types.numericLiteral(1)), types.unaryExpression('!', types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery')), true));
904
+ }
905
+ else {
906
+ condition = types.binaryExpression('===', types.identifier(info.pageStateVar), types.numericLiteral(1));
907
+ }
908
+ existingInitialDataAttr.value.expression = types.conditionalExpression(condition, types.optionalMemberExpression(types.identifier('props'), types.identifier(paginatedPropName), false, true), types.identifier('undefined'));
909
+ }
910
+ var existingKeyAttr = dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'key'; });
911
+ // Include page and search in key to trigger refetch when they change
912
+ var keyExpression;
913
+ if (info.searchEnabled && combinedStateVar) {
914
+ keyExpression = types.templateLiteral([
915
+ types.templateElement({
916
+ raw: "".concat(info.dataSourceIdentifier, "-page-"),
917
+ cooked: "".concat(info.dataSourceIdentifier, "-page-"),
918
+ }),
919
+ types.templateElement({ raw: '-search-', cooked: '-search-' }),
920
+ types.templateElement({ raw: '', cooked: '' }),
921
+ ], [
922
+ types.memberExpression(types.identifier(combinedStateVar), types.identifier('page')),
923
+ types.memberExpression(types.identifier(combinedStateVar), types.identifier('debouncedQuery')),
924
+ ]);
925
+ }
926
+ else {
927
+ keyExpression = types.templateLiteral([
928
+ types.templateElement({
929
+ raw: "".concat(info.dataSourceIdentifier, "-"),
930
+ cooked: "".concat(info.dataSourceIdentifier, "-"),
931
+ }),
932
+ types.templateElement({ raw: '', cooked: '' }),
933
+ ], [types.identifier(info.pageStateVar)]);
934
+ }
935
+ var keyAttr = types.jsxAttribute(types.jsxIdentifier('key'), types.jsxExpressionContainer(keyExpression));
936
+ if (existingKeyAttr) {
937
+ var index = dataProviderJSX.openingElement.attributes.indexOf(existingKeyAttr);
938
+ dataProviderJSX.openingElement.attributes[index] = keyAttr;
939
+ }
940
+ else {
941
+ dataProviderJSX.openingElement.attributes.push(keyAttr);
942
+ }
943
+ // For pagination, always create a fresh fetchData that calls the API route
944
+ // Get the resource definition to build the API URL
945
+ var resourceDefAttr = dataProviderJSX.openingElement.attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'resourceDefinition'; });
946
+ if (resourceDefAttr && ((_a = resourceDefAttr.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer') {
947
+ var resourceDef = resourceDefAttr.value.expression;
948
+ if (resourceDef.type === 'ObjectExpression') {
949
+ var dataSourceIdProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceId'; });
950
+ var tableNameProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'tableName'; });
951
+ var dataSourceTypeProp = resourceDef.properties.find(function (p) { return p.type === 'ObjectProperty' && p.key.value === 'dataSourceType'; });
952
+ if (dataSourceIdProp && tableNameProp && dataSourceTypeProp) {
953
+ var dataSourceId = dataSourceIdProp.value.value;
954
+ var tableName = tableNameProp.value.value;
955
+ var dataSourceType = dataSourceTypeProp.value.value;
956
+ var fileName = "".concat(dataSourceType, "-").concat(tableName, "-").concat(dataSourceId.substring(0, 8));
957
+ // Create fetchData attribute with proper fetch chain wrapped in useCallback
958
+ var fetchDataValue = types.callExpression(types.identifier('useCallback'), [
959
+ types.arrowFunctionExpression([types.identifier('params')], types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.callExpression(types.identifier('fetch'), [
960
+ types.templateLiteral([
961
+ types.templateElement({
962
+ raw: "/api/".concat(fileName, "?"),
963
+ cooked: "/api/".concat(fileName, "?"),
964
+ }),
965
+ types.templateElement({ raw: '', cooked: '' }),
966
+ ], [
967
+ types.newExpression(types.identifier('URLSearchParams'), [
968
+ types.identifier('params'),
969
+ ]),
970
+ ]),
971
+ types.objectExpression([
972
+ types.objectProperty(types.identifier('headers'), types.objectExpression([
973
+ types.objectProperty(types.stringLiteral('Content-Type'), types.stringLiteral('application/json')),
974
+ ])),
975
+ ]),
976
+ ]), types.identifier('then')), [
977
+ types.arrowFunctionExpression([types.identifier('res')], types.callExpression(types.memberExpression(types.identifier('res'), types.identifier('json')), [])),
978
+ ]), types.identifier('then')), [
979
+ types.arrowFunctionExpression([types.identifier('response')], types.optionalMemberExpression(types.identifier('response'), types.identifier('data'), false, true)),
980
+ ])),
981
+ types.arrayExpression([]),
982
+ ]);
983
+ var newFetchDataAttr = types.jsxAttribute(types.jsxIdentifier('fetchData'), types.jsxExpressionContainer(fetchDataValue));
984
+ // Remove existing fetchData attribute if present
985
+ var existingFetchDataIndex = dataProviderJSX.openingElement.attributes.findIndex(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'fetchData'; });
986
+ if (existingFetchDataIndex !== -1) {
987
+ dataProviderJSX.openingElement.attributes[existingFetchDataIndex] = newFetchDataAttr;
988
+ }
989
+ else {
990
+ dataProviderJSX.openingElement.attributes.push(newFetchDataAttr);
991
+ }
992
+ }
993
+ }
994
+ }
995
+ }
996
+ function findChildWithClass(node, classSubstring) {
997
+ var _a;
998
+ if (!node) {
999
+ return null;
1000
+ }
1001
+ if (node.type === 'JSXElement') {
1002
+ var className = getClassName(((_a = node.openingElement) === null || _a === void 0 ? void 0 : _a.attributes) || []);
1003
+ if (className && className.includes(classSubstring)) {
1004
+ return className;
1005
+ }
1006
+ }
1007
+ if (node.children) {
1008
+ for (var _i = 0, _b = node.children; _i < _b.length; _i++) {
1009
+ var child = _b[_i];
1010
+ var found = findChildWithClass(child, classSubstring);
1011
+ if (found) {
1012
+ return found;
1013
+ }
1014
+ }
1015
+ }
1016
+ if (typeof node === 'object') {
1017
+ for (var _c = 0, _d = Object.values(node); _c < _d.length; _c++) {
1018
+ var value = _d[_c];
1019
+ if (Array.isArray(value)) {
1020
+ for (var _e = 0, value_1 = value; _e < value_1.length; _e++) {
1021
+ var item = value_1[_e];
1022
+ var found = findChildWithClass(item, classSubstring);
1023
+ if (found) {
1024
+ return found;
1025
+ }
1026
+ }
1027
+ }
1028
+ else if (typeof value === 'object') {
1029
+ var found = findChildWithClass(value, classSubstring);
1030
+ if (found) {
1031
+ return found;
1032
+ }
1033
+ }
1034
+ }
1035
+ }
1036
+ return null;
1037
+ }
1038
+ function modifyPaginationButtons(blockStatement, detectedPaginations, paginationInfos) {
1039
+ var modifyNode = function (node) {
1040
+ if (!node) {
1041
+ return;
1042
+ }
1043
+ if (node.type === 'JSXElement') {
1044
+ var openingElement = node.openingElement;
1045
+ if (openingElement && openingElement.name && openingElement.name.type === 'JSXIdentifier') {
1046
+ var className_1 = getClassName(openingElement.attributes);
1047
+ if (className_1) {
1048
+ detectedPaginations.forEach(function (detected, index) {
1049
+ var info = paginationInfos[index];
1050
+ if (!info) {
1051
+ return;
1052
+ }
1053
+ if (className_1 === detected.prevButtonClass) {
1054
+ convertToButton(node, info, 'prev');
1055
+ }
1056
+ else if (className_1 === detected.nextButtonClass) {
1057
+ convertToButton(node, info, 'next');
1058
+ }
1059
+ });
1060
+ }
1061
+ }
1062
+ }
1063
+ if (typeof node === 'object') {
1064
+ Object.values(node).forEach(function (value) {
1065
+ if (Array.isArray(value)) {
1066
+ value.forEach(function (item) { return modifyNode(item); });
1067
+ }
1068
+ else if (typeof value === 'object') {
1069
+ modifyNode(value);
1070
+ }
1071
+ });
1072
+ }
1073
+ };
1074
+ modifyNode(blockStatement);
1075
+ }
1076
+ function modifySearchInputs(blockStatement, detectedPaginations, paginationInfos) {
1077
+ var modifyNode = function (node) {
1078
+ if (!node) {
1079
+ return;
1080
+ }
1081
+ if (node.type === 'JSXElement') {
1082
+ var openingElement = node.openingElement;
1083
+ if (openingElement && openingElement.name && openingElement.name.type === 'JSXIdentifier') {
1084
+ var className_2 = getClassName(openingElement.attributes);
1085
+ if (className_2) {
1086
+ detectedPaginations.forEach(function (detected, index) {
1087
+ var info = paginationInfos[index];
1088
+ if (!info || !info.searchEnabled) {
1089
+ return;
1090
+ }
1091
+ if (className_2 === detected.searchInputClass) {
1092
+ addSearchInputHandlers(node, info);
1093
+ }
1094
+ else if (className_2 && className_2.includes('search-input')) {
1095
+ // Fallback: match any input with 'search-input' in class
1096
+ addSearchInputHandlers(node, info);
1097
+ }
1098
+ });
1099
+ }
1100
+ }
1101
+ }
1102
+ if (typeof node === 'object') {
1103
+ Object.values(node).forEach(function (value) {
1104
+ if (Array.isArray(value)) {
1105
+ value.forEach(function (item) { return modifyNode(item); });
1106
+ }
1107
+ else if (typeof value === 'object') {
1108
+ modifyNode(value);
1109
+ }
1110
+ });
1111
+ }
1112
+ };
1113
+ modifyNode(blockStatement);
1114
+ }
1115
+ function addSearchInputHandlers(jsxElement, info) {
1116
+ if (!info.searchQueryVar || !info.setSearchQueryVar) {
1117
+ return;
1118
+ }
1119
+ var openingElement = jsxElement.openingElement;
1120
+ removeAttribute(openingElement.attributes, 'onChange');
1121
+ removeAttribute(openingElement.attributes, 'value');
1122
+ var onChangeHandler = types.arrowFunctionExpression([types.identifier('e')], types.callExpression(types.identifier(info.setSearchQueryVar), [
1123
+ types.memberExpression(types.memberExpression(types.identifier('e'), types.identifier('target')), types.identifier('value')),
1124
+ ]));
1125
+ openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onChange'), types.jsxExpressionContainer(onChangeHandler)));
1126
+ openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('value'), types.jsxExpressionContainer(types.identifier(info.searchQueryVar))));
1127
+ }
1128
+ function convertToButton(jsxElement, info, buttonType) {
1129
+ var openingElement = jsxElement.openingElement;
1130
+ if (openingElement.name.type === 'JSXIdentifier') {
1131
+ openingElement.name.name = 'button';
1132
+ }
1133
+ if (jsxElement.closingElement && jsxElement.closingElement.name.type === 'JSXIdentifier') {
1134
+ jsxElement.closingElement.name.name = 'button';
1135
+ }
1136
+ removeAttribute(openingElement.attributes, 'onClick');
1137
+ removeAttribute(openingElement.attributes, 'disabled');
1138
+ removeAttribute(openingElement.attributes, 'type');
1139
+ var combinedStateVar = info.combinedStateVar;
1140
+ var setCombinedStateVar = info.setCombinedStateVar;
1141
+ var onClickHandler;
1142
+ if (info.searchEnabled && combinedStateVar && setCombinedStateVar) {
1143
+ // Use combined state: update only the page property
1144
+ onClickHandler =
1145
+ buttonType === 'prev'
1146
+ ? types.arrowFunctionExpression([], types.callExpression(types.identifier(setCombinedStateVar), [
1147
+ types.arrowFunctionExpression([types.identifier('state')], types.objectExpression([
1148
+ types.spreadElement(types.identifier('state')),
1149
+ types.objectProperty(types.identifier('page'), types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('max')), [
1150
+ types.numericLiteral(1),
1151
+ types.binaryExpression('-', types.memberExpression(types.identifier('state'), types.identifier('page')), types.numericLiteral(1)),
1152
+ ])),
1153
+ ])),
1154
+ ]))
1155
+ : types.arrowFunctionExpression([], types.callExpression(types.identifier(setCombinedStateVar), [
1156
+ types.arrowFunctionExpression([types.identifier('state')], types.objectExpression([
1157
+ types.spreadElement(types.identifier('state')),
1158
+ types.objectProperty(types.identifier('page'), types.binaryExpression('+', types.memberExpression(types.identifier('state'), types.identifier('page')), types.numericLiteral(1))),
1159
+ ])),
1160
+ ]));
1161
+ }
1162
+ else {
1163
+ // Regular pagination (no search)
1164
+ onClickHandler =
1165
+ buttonType === 'prev'
1166
+ ? types.arrowFunctionExpression([], types.callExpression(types.identifier(info.setPageStateVar), [
1167
+ types.arrowFunctionExpression([types.identifier('p')], types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('max')), [
1168
+ types.numericLiteral(1),
1169
+ types.binaryExpression('-', types.identifier('p'), types.numericLiteral(1)),
1170
+ ])),
1171
+ ]))
1172
+ : types.arrowFunctionExpression([], types.callExpression(types.identifier(info.setPageStateVar), [
1173
+ types.arrowFunctionExpression([types.identifier('p')], types.binaryExpression('+', types.identifier('p'), types.numericLiteral(1))),
1174
+ ]));
1175
+ }
1176
+ openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('onClick'), types.jsxExpressionContainer(onClickHandler)));
1177
+ openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('type'), types.stringLiteral('button')));
1178
+ // Add disabled attribute with simple page number checks
1179
+ var maxPagesStateVar = info.maxPagesStateVar;
1180
+ var disabledExpr;
1181
+ if (info.searchEnabled && combinedStateVar) {
1182
+ disabledExpr =
1183
+ buttonType === 'prev'
1184
+ ? types.binaryExpression('<=', types.memberExpression(types.identifier(combinedStateVar), types.identifier('page')), types.numericLiteral(1))
1185
+ : types.binaryExpression('>=', types.memberExpression(types.identifier(combinedStateVar), types.identifier('page')), types.identifier(maxPagesStateVar));
1186
+ }
1187
+ else {
1188
+ disabledExpr =
1189
+ buttonType === 'prev'
1190
+ ? types.binaryExpression('<=', types.identifier(info.pageStateVar), types.numericLiteral(1))
1191
+ : types.binaryExpression('>=', types.identifier(info.pageStateVar), types.identifier(maxPagesStateVar));
1192
+ }
1193
+ openingElement.attributes.push(types.jsxAttribute(types.jsxIdentifier('disabled'), types.jsxExpressionContainer(disabledExpr)));
1194
+ }
1195
+ function getClassName(attributes) {
1196
+ var classNameAttr = attributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'className'; });
1197
+ if (classNameAttr && classNameAttr.value && classNameAttr.value.type === 'StringLiteral') {
1198
+ return classNameAttr.value.value;
1199
+ }
1200
+ return null;
1201
+ }
1202
+ function removeAttribute(attrs, attributeName) {
1203
+ var index = attrs.findIndex(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === attributeName; });
1204
+ if (index !== -1) {
1205
+ attrs.splice(index, 1);
1206
+ }
1207
+ }
1208
+ function modifyGetStaticPropsForPagination(chunks, paginationInfos) {
1209
+ var _a;
1210
+ var getStaticPropsChunk = chunks.find(function (chunk) { return chunk.name === 'getStaticProps'; });
1211
+ if (!getStaticPropsChunk || getStaticPropsChunk.type !== 'ast') {
1212
+ return;
1213
+ }
1214
+ var exportDeclaration = getStaticPropsChunk.content;
1215
+ if (!exportDeclaration || exportDeclaration.type !== 'ExportNamedDeclaration') {
1216
+ return;
1217
+ }
1218
+ var functionDeclaration = exportDeclaration.declaration;
1219
+ if (!functionDeclaration || functionDeclaration.type !== 'FunctionDeclaration') {
1220
+ return;
1221
+ }
1222
+ // Find Promise.all and add NEW fetchData calls for each paginated DataProvider
1223
+ var functionBody = functionDeclaration.body.body;
1224
+ var tryBlock = functionBody.find(function (stmt) { return stmt.type === 'TryStatement'; });
1225
+ if (!tryBlock) {
1226
+ return;
1227
+ }
1228
+ var tryBody = tryBlock.block.body;
1229
+ // Find the Promise.all statement
1230
+ var promiseAllStmt = tryBody.find(function (stmt) {
1231
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
1232
+ return stmt.type === 'VariableDeclaration' &&
1233
+ ((_c = (_b = (_a = stmt.declarations) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.init) === null || _c === void 0 ? void 0 : _c.type) === 'AwaitExpression' &&
1234
+ ((_g = (_f = (_e = (_d = stmt.declarations) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.init) === null || _f === void 0 ? void 0 : _f.argument) === null || _g === void 0 ? void 0 : _g.type) === 'CallExpression' &&
1235
+ ((_m = (_l = (_k = (_j = (_h = stmt.declarations) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.init) === null || _k === void 0 ? void 0 : _k.argument) === null || _l === void 0 ? void 0 : _l.callee) === null || _m === void 0 ? void 0 : _m.type) === 'MemberExpression' &&
1236
+ ((_t = (_s = (_r = (_q = (_p = (_o = stmt.declarations) === null || _o === void 0 ? void 0 : _o[0]) === null || _p === void 0 ? void 0 : _p.init) === null || _q === void 0 ? void 0 : _q.argument) === null || _r === void 0 ? void 0 : _r.callee) === null || _s === void 0 ? void 0 : _s.property) === null || _t === void 0 ? void 0 : _t.name) === 'all';
1237
+ });
1238
+ if (!promiseAllStmt) {
1239
+ return;
1240
+ }
1241
+ var awaitExpr = promiseAllStmt.declarations[0].init;
1242
+ var promiseAllCall = awaitExpr.argument;
1243
+ var promiseArray = promiseAllCall.arguments[0];
1244
+ var destructuringPattern = promiseAllStmt.declarations[0].id;
1245
+ // Map import names to data source identifiers from existing fetchData calls
1246
+ // Also track which indices to remove (non-paginated calls that will be replaced)
1247
+ var importToDataSource = new Map();
1248
+ var indicesToRemove = [];
1249
+ promiseArray.elements.forEach(function (element, index) {
1250
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1251
+ if (element && element.type === 'CallExpression') {
1252
+ var fetchCallExpr = element;
1253
+ // If wrapped in .catch(), unwrap it
1254
+ if (((_a = element.callee) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression' &&
1255
+ ((_c = (_b = element.callee) === null || _b === void 0 ? void 0 : _b.property) === null || _c === void 0 ? void 0 : _c.name) === 'catch' &&
1256
+ ((_e = (_d = element.callee) === null || _d === void 0 ? void 0 : _d.object) === null || _e === void 0 ? void 0 : _e.type) === 'CallExpression') {
1257
+ fetchCallExpr = element.callee.object;
1258
+ }
1259
+ // Now find the .fetchData() call
1260
+ if (((_f = fetchCallExpr.callee) === null || _f === void 0 ? void 0 : _f.type) === 'MemberExpression' &&
1261
+ ((_h = (_g = fetchCallExpr.callee) === null || _g === void 0 ? void 0 : _g.property) === null || _h === void 0 ? void 0 : _h.name) === 'fetchData' &&
1262
+ ((_k = (_j = fetchCallExpr.callee) === null || _j === void 0 ? void 0 : _j.object) === null || _k === void 0 ? void 0 : _k.type) === 'Identifier') {
1263
+ var importName = fetchCallExpr.callee.object.name;
1264
+ var dataSourceVar_1 = destructuringPattern.elements[index].name;
1265
+ // Check if this fetchData call has page/perPage params
1266
+ var params = fetchCallExpr.arguments[0];
1267
+ var hasPageParam = params &&
1268
+ params.type === 'ObjectExpression' &&
1269
+ params.properties.some(function (prop) {
1270
+ return prop.type === 'ObjectProperty' &&
1271
+ (prop.key.name === 'page' || prop.key.name === 'perPage');
1272
+ });
1273
+ // If this is a data source that will be paginated but this call has NO pagination params,
1274
+ // mark it for removal
1275
+ if (!hasPageParam &&
1276
+ paginationInfos.some(function (info) { return info.dataSourceIdentifier === dataSourceVar_1; })) {
1277
+ indicesToRemove.push(index);
1278
+ }
1279
+ importToDataSource.set(importName, dataSourceVar_1);
1280
+ }
1281
+ }
1282
+ });
1283
+ // Remove non-paginated fetchData calls in reverse order to preserve indices
1284
+ indicesToRemove.reverse().forEach(function (index) {
1285
+ var _a, _b;
1286
+ // Get the prop name BEFORE removing it
1287
+ var propToRemove = (_a = destructuringPattern.elements[index]) === null || _a === void 0 ? void 0 : _a.name;
1288
+ promiseArray.elements.splice(index, 1);
1289
+ destructuringPattern.elements.splice(index, 1);
1290
+ // Also remove from props in return statement
1291
+ if (propToRemove) {
1292
+ var foundReturnStmt = tryBody.find(function (stmt) { return stmt.type === 'ReturnStatement'; });
1293
+ if (foundReturnStmt && ((_b = foundReturnStmt.argument) === null || _b === void 0 ? void 0 : _b.type) === 'ObjectExpression') {
1294
+ var propsProperty = foundReturnStmt.argument.properties.find(function (prop) {
1295
+ return prop.type === 'ObjectProperty' && prop.key.name === 'props';
1296
+ });
1297
+ if (propsProperty && propsProperty.value.type === 'ObjectExpression') {
1298
+ var propsObject = propsProperty.value;
1299
+ var propIndex = propsObject.properties.findIndex(function (prop) {
1300
+ return prop.type === 'ObjectProperty' && prop.key.name === propToRemove;
1301
+ });
1302
+ if (propIndex !== -1) {
1303
+ propsObject.properties.splice(propIndex, 1);
1304
+ }
1305
+ }
1306
+ }
1307
+ }
1308
+ });
1309
+ // Add NEW fetchData calls for each paginated DataProvider
1310
+ paginationInfos.forEach(function (info, index) {
1311
+ var _a, _b;
1312
+ // Try exact match first, then case-insensitive match
1313
+ var importName = (_a = Array.from(importToDataSource.entries()).find(function (_a) {
1314
+ var _ = _a[0], dataSourceVar = _a[1];
1315
+ return dataSourceVar === info.dataSourceIdentifier;
1316
+ })) === null || _a === void 0 ? void 0 : _a[0];
1317
+ if (!importName) {
1318
+ // Try case-insensitive match
1319
+ var normalizedIdentifier_1 = info.dataSourceIdentifier.toLowerCase().replace(/[_-]/g, '');
1320
+ importName = (_b = Array.from(importToDataSource.entries()).find(function (_a) {
1321
+ var _ = _a[0], dataSourceVar = _a[1];
1322
+ return dataSourceVar.toLowerCase().replace(/[_-]/g, '') === normalizedIdentifier_1;
1323
+ })) === null || _b === void 0 ? void 0 : _b[0];
1324
+ }
1325
+ if (importName) {
1326
+ var paginatedVarName = "".concat(info.dataSourceIdentifier, "_pg_").concat(index);
1327
+ var fetchParams = [
1328
+ types.objectProperty(types.identifier('page'), types.numericLiteral(1)),
1329
+ types.objectProperty(types.identifier('perPage'), types.numericLiteral(info.perPage)),
1330
+ ];
1331
+ // Add queryColumns if they exist
1332
+ if (info.queryColumns && info.queryColumns.length > 0) {
1333
+ fetchParams.push(types.objectProperty(types.identifier('queryColumns'), types.arrayExpression(info.queryColumns.map(function (col) { return types.stringLiteral(col); }))));
1334
+ }
1335
+ // Create new fetchData call with pagination params
1336
+ var newFetchDataCall = types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.identifier(importName), types.identifier('fetchData')), [types.objectExpression(fetchParams)]), types.identifier('catch')), [
1337
+ types.arrowFunctionExpression([types.identifier('error')], types.blockStatement([
1338
+ types.expressionStatement(types.callExpression(types.memberExpression(types.identifier('console'), types.identifier('error')), [
1339
+ types.stringLiteral("Error fetching ".concat(paginatedVarName, ":")),
1340
+ types.identifier('error'),
1341
+ ])),
1342
+ types.returnStatement(types.arrayExpression([])),
1343
+ ])),
1344
+ ]);
1345
+ promiseArray.elements.push(newFetchDataCall);
1346
+ destructuringPattern.elements.push(types.identifier(paginatedVarName));
1347
+ }
1348
+ });
1349
+ // Add fetchCount calls for paginated data sources (deduplicated by data source)
1350
+ // Deduplicate by data source identifier
1351
+ var uniqueDataSources = new Set(paginationInfos.map(function (info) { return info.dataSourceIdentifier; }));
1352
+ var addedCountFetches = new Set();
1353
+ uniqueDataSources.forEach(function (dataSourceId) {
1354
+ var _a, _b;
1355
+ var importName = (_a = Array.from(importToDataSource.entries()).find(function (_a) {
1356
+ var _ = _a[0], dataSourceVar = _a[1];
1357
+ return dataSourceVar === dataSourceId;
1358
+ })) === null || _a === void 0 ? void 0 : _a[0];
1359
+ if (!importName) {
1360
+ // Try case-insensitive match
1361
+ var normalizedIdentifier_2 = dataSourceId.toLowerCase().replace(/[_-]/g, '');
1362
+ importName = (_b = Array.from(importToDataSource.entries()).find(function (_a) {
1363
+ var _ = _a[0], dataSourceVar = _a[1];
1364
+ return dataSourceVar.toLowerCase().replace(/[_-]/g, '') === normalizedIdentifier_2;
1365
+ })) === null || _b === void 0 ? void 0 : _b[0];
1366
+ }
1367
+ if (importName && !addedCountFetches.has(dataSourceId)) {
1368
+ var fetchCountCall = types.callExpression(types.memberExpression(types.identifier(importName), types.identifier('fetchCount')), []);
1369
+ promiseArray.elements.push(fetchCountCall);
1370
+ destructuringPattern.elements.push(types.identifier("".concat(dataSourceId, "_count")));
1371
+ addedCountFetches.add(dataSourceId);
1372
+ }
1373
+ });
1374
+ // Calculate and add maxPages before return
1375
+ var returnStmt = tryBody.find(function (stmt) { return stmt.type === 'ReturnStatement'; });
1376
+ if (returnStmt && ((_a = returnStmt.argument) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
1377
+ var propsProperty = returnStmt.argument.properties.find(function (prop) {
1378
+ return prop.type === 'ObjectProperty' && prop.key.name === 'props';
1379
+ });
1380
+ if (propsProperty && propsProperty.value.type === 'ObjectExpression') {
1381
+ var propsObject_1 = propsProperty.value;
1382
+ var returnIndex_1 = tryBody.indexOf(returnStmt);
1383
+ paginationInfos.forEach(function (info, index) {
1384
+ var paginatedVarName = "".concat(info.dataSourceIdentifier, "_pg_").concat(index);
1385
+ var countVarName = "".concat(info.dataSourceIdentifier, "_count");
1386
+ var maxPagesVarName = "".concat(info.dataSourceIdentifier, "_pg_").concat(index, "_maxPages");
1387
+ var maxPagesCalc = types.variableDeclaration('const', [
1388
+ types.variableDeclarator(types.identifier(maxPagesVarName), types.callExpression(types.memberExpression(types.identifier('Math'), types.identifier('ceil')), [
1389
+ types.binaryExpression('/', types.logicalExpression('||', types.identifier(countVarName), types.numericLiteral(0)), types.numericLiteral(info.perPage)),
1390
+ ])),
1391
+ ]);
1392
+ tryBody.splice(returnIndex_1, 0, maxPagesCalc);
1393
+ // Add both the paginated data and maxPages to props
1394
+ propsObject_1.properties.push(types.objectProperty(types.identifier(paginatedVarName), types.identifier(paginatedVarName)));
1395
+ propsObject_1.properties.push(types.objectProperty(types.identifier(maxPagesVarName), types.identifier(maxPagesVarName)));
1396
+ });
1397
+ }
1398
+ }
1399
+ }
1400
+ function createAPIRoutesForPaginatedDataSources(uidlNode, dataSources, componentChunk, extractedResources, paginationInfos, isComponent) {
1401
+ var paginatedDataSourceIds = new Set(paginationInfos.map(function (info) { return info.dataSourceIdentifier; }));
1402
+ var traverseForDataSources = function (node) {
1403
+ var _a;
1404
+ if (!node) {
1405
+ return;
1406
+ }
1407
+ if (node.type === 'data-source-list' || node.type === 'data-source-item') {
1408
+ var renderProp = node.content.renderPropIdentifier;
1409
+ if (renderProp && paginatedDataSourceIds.has(renderProp)) {
1410
+ extractDataSourceIntoNextAPIFolder(node, dataSources, componentChunk, extractedResources);
1411
+ // For components, also create count API route
1412
+ if (isComponent) {
1413
+ var resourceDef = node.content.resourceDefinition;
1414
+ if (resourceDef) {
1415
+ var dataSourceId = resourceDef.dataSourceId;
1416
+ var tableName = resourceDef.tableName;
1417
+ var dataSourceType = resourceDef.dataSourceType;
1418
+ var fileName = "".concat(dataSourceType, "-").concat(tableName, "-").concat(dataSourceId.substring(0, 8));
1419
+ var countFileName = "".concat(fileName, "-count");
1420
+ // Create count API route that exports getCount handler
1421
+ extractedResources["api/".concat(countFileName)] = {
1422
+ fileName: countFileName,
1423
+ fileType: FileType.JS,
1424
+ path: ['pages', 'api'],
1425
+ content: "import dataSource from '../../utils/data-sources/".concat(fileName, "'\n\nexport default dataSource.getCount\n"),
1426
+ };
1427
+ }
1428
+ }
1429
+ }
1430
+ }
1431
+ if ((_a = node.content) === null || _a === void 0 ? void 0 : _a.children) {
1432
+ node.content.children.forEach(function (child) { return traverseForDataSources(child); });
1433
+ }
1434
+ };
1435
+ traverseForDataSources(uidlNode);
1436
+ }
1437
+ function createAPIRoutesForSearchOnlyDataSources(uidlNode, dataSources, componentChunk, extractedResources, searchOnlyDataSources) {
1438
+ var searchOnlyDataSourceIds = new Set(searchOnlyDataSources.map(function (info) { return info.dataSourceIdentifier; }));
1439
+ var traverseForDataSources = function (node) {
1440
+ var _a;
1441
+ if (!node) {
1442
+ return;
1443
+ }
1444
+ if (node.type === 'data-source-list' || node.type === 'data-source-item') {
1445
+ var renderProp = node.content.renderPropIdentifier;
1446
+ if (renderProp && searchOnlyDataSourceIds.has(renderProp)) {
1447
+ extractDataSourceIntoNextAPIFolder(node, dataSources, componentChunk, extractedResources);
1448
+ }
1449
+ }
1450
+ if ((_a = node.content) === null || _a === void 0 ? void 0 : _a.children) {
1451
+ node.content.children.forEach(function (child) { return traverseForDataSources(child); });
1452
+ }
1453
+ };
1454
+ traverseForDataSources(uidlNode);
1455
+ }
1456
+ export default createNextArrayMapperPaginationPlugin();
1457
+ //# sourceMappingURL=pagination-plugin.js.map