@mondaydotcomorg/atp-compiler 0.19.21 → 0.19.23

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.
package/dist/index.cjs CHANGED
@@ -507,6 +507,21 @@ var BatchOptimizer = class {
507
507
  reason: "Simple conditional - can batch but consider array size"
508
508
  };
509
509
  }
510
+ const lastStmt = statements[statements.length - 1];
511
+ if (t7__namespace.isReturnStatement(lastStmt) && lastStmt.argument) {
512
+ if (t7__namespace.isObjectExpression(lastStmt.argument)) {
513
+ return {
514
+ canBatch: false,
515
+ reason: "Return statement is object expression - batch would lose structure"
516
+ };
517
+ }
518
+ if (t7__namespace.isArrayExpression(lastStmt.argument)) {
519
+ return {
520
+ canBatch: false,
521
+ reason: "Return statement is array expression - batch would lose structure"
522
+ };
523
+ }
524
+ }
510
525
  return {
511
526
  canBatch: true,
512
527
  llmCallPattern: "single",
@@ -1250,6 +1265,100 @@ function transformToSequential(path, node, methodName, callback, onTransform) {
1250
1265
  return true;
1251
1266
  }
1252
1267
  __name(transformToSequential, "transformToSequential");
1268
+ var traverse2 = typeof _traverse__default.default.default === "function" ? _traverse__default.default.default : _traverse__default.default;
1269
+ function transformToBatchWithReconstruction(path, node, methodName, callback, batchDetector, onTransform) {
1270
+ if (methodName !== "map") {
1271
+ return false;
1272
+ }
1273
+ const paramName = callback.params[0];
1274
+ if (!t7__namespace.isIdentifier(paramName)) {
1275
+ return false;
1276
+ }
1277
+ const param = paramName.name;
1278
+ const array = node.callee.object;
1279
+ const llmCall = findLLMCallExpression(callback.body);
1280
+ if (!llmCall) {
1281
+ return false;
1282
+ }
1283
+ const callInfo = batchDetector.extractCallInfo(llmCall);
1284
+ if (!callInfo) {
1285
+ return false;
1286
+ }
1287
+ const payloadNode = batchDetector.extractPayloadNode(llmCall);
1288
+ if (!payloadNode) {
1289
+ return false;
1290
+ }
1291
+ const methodId = generateUniqueId(`${methodName}_batch_reconstruct`);
1292
+ const resultsVar = `__batch_results_${methodId.replace(/[^a-zA-Z0-9]/g, "_")}`;
1293
+ const indexVar = "__idx";
1294
+ const payloadMapper = t7__namespace.arrowFunctionExpression([
1295
+ t7__namespace.identifier(param)
1296
+ ], t7__namespace.objectExpression([
1297
+ t7__namespace.objectProperty(t7__namespace.identifier("type"), t7__namespace.stringLiteral(callInfo.type)),
1298
+ t7__namespace.objectProperty(t7__namespace.identifier("operation"), t7__namespace.stringLiteral(callInfo.operation)),
1299
+ t7__namespace.objectProperty(t7__namespace.identifier("payload"), t7__namespace.cloneNode(payloadNode, true))
1300
+ ]));
1301
+ const clonedBody = t7__namespace.cloneNode(callback.body, true);
1302
+ const resultAccess = t7__namespace.memberExpression(t7__namespace.identifier(resultsVar), t7__namespace.identifier(indexVar), true);
1303
+ let traversableNode;
1304
+ if (t7__namespace.isBlockStatement(clonedBody)) {
1305
+ traversableNode = t7__namespace.functionDeclaration(t7__namespace.identifier("__temp"), [], clonedBody);
1306
+ } else {
1307
+ traversableNode = t7__namespace.expressionStatement(clonedBody);
1308
+ }
1309
+ let replaced = false;
1310
+ traverse2(t7__namespace.file(t7__namespace.program([
1311
+ traversableNode
1312
+ ])), {
1313
+ AwaitExpression(awaitPath) {
1314
+ if (replaced) return;
1315
+ const arg = awaitPath.node.argument;
1316
+ if (t7__namespace.isCallExpression(arg)) {
1317
+ const info = batchDetector.extractCallInfo(arg);
1318
+ if (info && info.type === callInfo.type && info.operation === callInfo.operation) {
1319
+ awaitPath.replaceWith(resultAccess);
1320
+ replaced = true;
1321
+ }
1322
+ }
1323
+ },
1324
+ noScope: true
1325
+ });
1326
+ if (!replaced) {
1327
+ return false;
1328
+ }
1329
+ let reconstructBody;
1330
+ if (t7__namespace.isBlockStatement(clonedBody)) {
1331
+ reconstructBody = clonedBody;
1332
+ } else {
1333
+ reconstructBody = clonedBody;
1334
+ }
1335
+ const reconstructMapper = t7__namespace.arrowFunctionExpression([
1336
+ t7__namespace.identifier(param),
1337
+ t7__namespace.identifier(indexVar)
1338
+ ], reconstructBody);
1339
+ reconstructMapper.async = false;
1340
+ const batchCall = t7__namespace.awaitExpression(t7__namespace.callExpression(t7__namespace.memberExpression(t7__namespace.identifier("__runtime"), t7__namespace.identifier("batchParallel")), [
1341
+ t7__namespace.callExpression(t7__namespace.memberExpression(t7__namespace.cloneNode(array, true), t7__namespace.identifier("map")), [
1342
+ payloadMapper
1343
+ ]),
1344
+ t7__namespace.stringLiteral(methodId)
1345
+ ]));
1346
+ const resultsDeclaration = t7__namespace.variableDeclaration("const", [
1347
+ t7__namespace.variableDeclarator(t7__namespace.identifier(resultsVar), batchCall)
1348
+ ]);
1349
+ const reconstructCall = t7__namespace.callExpression(t7__namespace.memberExpression(t7__namespace.cloneNode(array, true), t7__namespace.identifier("map")), [
1350
+ reconstructMapper
1351
+ ]);
1352
+ const iife = t7__namespace.callExpression(t7__namespace.arrowFunctionExpression([], t7__namespace.blockStatement([
1353
+ resultsDeclaration,
1354
+ t7__namespace.returnStatement(reconstructCall)
1355
+ ]), true), []);
1356
+ const awaitIife = t7__namespace.awaitExpression(iife);
1357
+ path.replaceWith(awaitIife);
1358
+ onTransform();
1359
+ return true;
1360
+ }
1361
+ __name(transformToBatchWithReconstruction, "transformToBatchWithReconstruction");
1253
1362
 
1254
1363
  // src/transformer/array-transformer.ts
1255
1364
  var ArrayTransformer = class {
@@ -1276,6 +1385,19 @@ var ArrayTransformer = class {
1276
1385
  return false;
1277
1386
  }
1278
1387
  const batchResult = this.batchOptimizer.canBatchArrayMethod(callback);
1388
+ if (!batchResult.canBatch && methodName === "map") {
1389
+ const reason = batchResult.reason || "";
1390
+ const hasObjectOrArrayReturn = reason.includes("object expression") || reason.includes("array expression");
1391
+ if (hasObjectOrArrayReturn) {
1392
+ const llmCall = findLLMCallExpression(callback.body);
1393
+ if (llmCall) {
1394
+ const success = transformToBatchWithReconstruction(path, node, methodName, callback, this.batchDetector, () => this.transformCount++);
1395
+ if (success) {
1396
+ return true;
1397
+ }
1398
+ }
1399
+ }
1400
+ }
1279
1401
  if (batchResult.canBatch && canUseBatchParallel(methodName)) {
1280
1402
  const array = node.callee.object;
1281
1403
  const decision = this.batchOptimizer.makeSmartBatchDecision(methodName, batchResult, array, this.batchSizeThreshold);
@@ -1579,7 +1701,7 @@ function isTransformationError(error) {
1579
1701
  __name(isTransformationError, "isTransformationError");
1580
1702
 
1581
1703
  // src/transformer/index.ts
1582
- var traverse2 = _traverse__default.default.default || _traverse__default.default;
1704
+ var traverse3 = _traverse__default.default.default || _traverse__default.default;
1583
1705
  var generate = _generate__default.default.default || _generate__default.default;
1584
1706
  var ATPCompiler = class {
1585
1707
  static {
@@ -1631,7 +1753,7 @@ var ATPCompiler = class {
1631
1753
  this.loopTransformer.resetTransformCount();
1632
1754
  this.arrayTransformer.resetTransformCount();
1633
1755
  this.promiseTransformer.resetTransformCount();
1634
- traverse2(ast, {
1756
+ traverse3(ast, {
1635
1757
  ForOfStatement: /* @__PURE__ */ __name((path) => {
1636
1758
  this.loopTransformer.transformForOfLoop(path);
1637
1759
  }, "ForOfStatement"),
@@ -2314,7 +2436,7 @@ function createTransformPlugin(config) {
2314
2436
  };
2315
2437
  }
2316
2438
  __name(createTransformPlugin, "createTransformPlugin");
2317
- var traverse3 = _traverse__default.default.default || _traverse__default.default;
2439
+ var traverse4 = _traverse__default.default.default || _traverse__default.default;
2318
2440
  var generate2 = _generate__default.default.default || _generate__default.default;
2319
2441
  var PluggableCompiler = class {
2320
2442
  static {
@@ -2435,7 +2557,7 @@ var PluggableCompiler = class {
2435
2557
  }
2436
2558
  }
2437
2559
  }
2438
- traverse3(ast, visitors);
2560
+ traverse4(ast, visitors);
2439
2561
  let optimizedAst = ast;
2440
2562
  const optimizers = this.registry.getOptimizers();
2441
2563
  for (const optimizer of optimizers) {
@@ -2827,7 +2949,7 @@ var AsyncTimeoutPlugin = class {
2827
2949
  return null;
2828
2950
  }
2829
2951
  };
2830
- var traverse4 = _traverse__default.default.default || _traverse__default.default;
2952
+ var traverse5 = _traverse__default.default.default || _traverse__default.default;
2831
2953
  var SecurityValidatorPlugin = class {
2832
2954
  static {
2833
2955
  __name(this, "SecurityValidatorPlugin");
@@ -2864,7 +2986,7 @@ var SecurityValidatorPlugin = class {
2864
2986
  }
2865
2987
  let maxNestingFound = 0;
2866
2988
  let complexityScore = 0;
2867
- traverse4(ast, {
2989
+ traverse5(ast, {
2868
2990
  enter(path) {
2869
2991
  const depth = path.scope.path.node ? getDepth(path) : 0;
2870
2992
  maxNestingFound = Math.max(maxNestingFound, depth);
@@ -2979,6 +3101,7 @@ exports.resumableSome = resumableSome;
2979
3101
  exports.resumableWhile = resumableWhile;
2980
3102
  exports.setCheckpointManager = setCheckpointManager;
2981
3103
  exports.setRuntimeContext = setRuntimeContext;
3104
+ exports.transformToBatchWithReconstruction = transformToBatchWithReconstruction;
2982
3105
  exports.wrapInAsyncFunction = wrapInAsyncFunction;
2983
3106
  //# sourceMappingURL=index.cjs.map
2984
3107
  //# sourceMappingURL=index.cjs.map