@mondaydotcomorg/atp-compiler 0.19.22 → 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.js CHANGED
@@ -1239,6 +1239,100 @@ function transformToSequential(path, node, methodName, callback, onTransform) {
1239
1239
  return true;
1240
1240
  }
1241
1241
  __name(transformToSequential, "transformToSequential");
1242
+ var traverse2 = typeof _traverse.default === "function" ? _traverse.default : _traverse;
1243
+ function transformToBatchWithReconstruction(path, node, methodName, callback, batchDetector, onTransform) {
1244
+ if (methodName !== "map") {
1245
+ return false;
1246
+ }
1247
+ const paramName = callback.params[0];
1248
+ if (!t7.isIdentifier(paramName)) {
1249
+ return false;
1250
+ }
1251
+ const param = paramName.name;
1252
+ const array = node.callee.object;
1253
+ const llmCall = findLLMCallExpression(callback.body);
1254
+ if (!llmCall) {
1255
+ return false;
1256
+ }
1257
+ const callInfo = batchDetector.extractCallInfo(llmCall);
1258
+ if (!callInfo) {
1259
+ return false;
1260
+ }
1261
+ const payloadNode = batchDetector.extractPayloadNode(llmCall);
1262
+ if (!payloadNode) {
1263
+ return false;
1264
+ }
1265
+ const methodId = generateUniqueId(`${methodName}_batch_reconstruct`);
1266
+ const resultsVar = `__batch_results_${methodId.replace(/[^a-zA-Z0-9]/g, "_")}`;
1267
+ const indexVar = "__idx";
1268
+ const payloadMapper = t7.arrowFunctionExpression([
1269
+ t7.identifier(param)
1270
+ ], t7.objectExpression([
1271
+ t7.objectProperty(t7.identifier("type"), t7.stringLiteral(callInfo.type)),
1272
+ t7.objectProperty(t7.identifier("operation"), t7.stringLiteral(callInfo.operation)),
1273
+ t7.objectProperty(t7.identifier("payload"), t7.cloneNode(payloadNode, true))
1274
+ ]));
1275
+ const clonedBody = t7.cloneNode(callback.body, true);
1276
+ const resultAccess = t7.memberExpression(t7.identifier(resultsVar), t7.identifier(indexVar), true);
1277
+ let traversableNode;
1278
+ if (t7.isBlockStatement(clonedBody)) {
1279
+ traversableNode = t7.functionDeclaration(t7.identifier("__temp"), [], clonedBody);
1280
+ } else {
1281
+ traversableNode = t7.expressionStatement(clonedBody);
1282
+ }
1283
+ let replaced = false;
1284
+ traverse2(t7.file(t7.program([
1285
+ traversableNode
1286
+ ])), {
1287
+ AwaitExpression(awaitPath) {
1288
+ if (replaced) return;
1289
+ const arg = awaitPath.node.argument;
1290
+ if (t7.isCallExpression(arg)) {
1291
+ const info = batchDetector.extractCallInfo(arg);
1292
+ if (info && info.type === callInfo.type && info.operation === callInfo.operation) {
1293
+ awaitPath.replaceWith(resultAccess);
1294
+ replaced = true;
1295
+ }
1296
+ }
1297
+ },
1298
+ noScope: true
1299
+ });
1300
+ if (!replaced) {
1301
+ return false;
1302
+ }
1303
+ let reconstructBody;
1304
+ if (t7.isBlockStatement(clonedBody)) {
1305
+ reconstructBody = clonedBody;
1306
+ } else {
1307
+ reconstructBody = clonedBody;
1308
+ }
1309
+ const reconstructMapper = t7.arrowFunctionExpression([
1310
+ t7.identifier(param),
1311
+ t7.identifier(indexVar)
1312
+ ], reconstructBody);
1313
+ reconstructMapper.async = false;
1314
+ const batchCall = t7.awaitExpression(t7.callExpression(t7.memberExpression(t7.identifier("__runtime"), t7.identifier("batchParallel")), [
1315
+ t7.callExpression(t7.memberExpression(t7.cloneNode(array, true), t7.identifier("map")), [
1316
+ payloadMapper
1317
+ ]),
1318
+ t7.stringLiteral(methodId)
1319
+ ]));
1320
+ const resultsDeclaration = t7.variableDeclaration("const", [
1321
+ t7.variableDeclarator(t7.identifier(resultsVar), batchCall)
1322
+ ]);
1323
+ const reconstructCall = t7.callExpression(t7.memberExpression(t7.cloneNode(array, true), t7.identifier("map")), [
1324
+ reconstructMapper
1325
+ ]);
1326
+ const iife = t7.callExpression(t7.arrowFunctionExpression([], t7.blockStatement([
1327
+ resultsDeclaration,
1328
+ t7.returnStatement(reconstructCall)
1329
+ ]), true), []);
1330
+ const awaitIife = t7.awaitExpression(iife);
1331
+ path.replaceWith(awaitIife);
1332
+ onTransform();
1333
+ return true;
1334
+ }
1335
+ __name(transformToBatchWithReconstruction, "transformToBatchWithReconstruction");
1242
1336
 
1243
1337
  // src/transformer/array-transformer.ts
1244
1338
  var ArrayTransformer = class {
@@ -1265,6 +1359,19 @@ var ArrayTransformer = class {
1265
1359
  return false;
1266
1360
  }
1267
1361
  const batchResult = this.batchOptimizer.canBatchArrayMethod(callback);
1362
+ if (!batchResult.canBatch && methodName === "map") {
1363
+ const reason = batchResult.reason || "";
1364
+ const hasObjectOrArrayReturn = reason.includes("object expression") || reason.includes("array expression");
1365
+ if (hasObjectOrArrayReturn) {
1366
+ const llmCall = findLLMCallExpression(callback.body);
1367
+ if (llmCall) {
1368
+ const success = transformToBatchWithReconstruction(path, node, methodName, callback, this.batchDetector, () => this.transformCount++);
1369
+ if (success) {
1370
+ return true;
1371
+ }
1372
+ }
1373
+ }
1374
+ }
1268
1375
  if (batchResult.canBatch && canUseBatchParallel(methodName)) {
1269
1376
  const array = node.callee.object;
1270
1377
  const decision = this.batchOptimizer.makeSmartBatchDecision(methodName, batchResult, array, this.batchSizeThreshold);
@@ -1568,7 +1675,7 @@ function isTransformationError(error) {
1568
1675
  __name(isTransformationError, "isTransformationError");
1569
1676
 
1570
1677
  // src/transformer/index.ts
1571
- var traverse2 = _traverse.default || _traverse;
1678
+ var traverse3 = _traverse.default || _traverse;
1572
1679
  var generate = _generate.default || _generate;
1573
1680
  var ATPCompiler = class {
1574
1681
  static {
@@ -1620,7 +1727,7 @@ var ATPCompiler = class {
1620
1727
  this.loopTransformer.resetTransformCount();
1621
1728
  this.arrayTransformer.resetTransformCount();
1622
1729
  this.promiseTransformer.resetTransformCount();
1623
- traverse2(ast, {
1730
+ traverse3(ast, {
1624
1731
  ForOfStatement: /* @__PURE__ */ __name((path) => {
1625
1732
  this.loopTransformer.transformForOfLoop(path);
1626
1733
  }, "ForOfStatement"),
@@ -2303,7 +2410,7 @@ function createTransformPlugin(config) {
2303
2410
  };
2304
2411
  }
2305
2412
  __name(createTransformPlugin, "createTransformPlugin");
2306
- var traverse3 = _traverse.default || _traverse;
2413
+ var traverse4 = _traverse.default || _traverse;
2307
2414
  var generate2 = _generate.default || _generate;
2308
2415
  var PluggableCompiler = class {
2309
2416
  static {
@@ -2424,7 +2531,7 @@ var PluggableCompiler = class {
2424
2531
  }
2425
2532
  }
2426
2533
  }
2427
- traverse3(ast, visitors);
2534
+ traverse4(ast, visitors);
2428
2535
  let optimizedAst = ast;
2429
2536
  const optimizers = this.registry.getOptimizers();
2430
2537
  for (const optimizer of optimizers) {
@@ -2816,7 +2923,7 @@ var AsyncTimeoutPlugin = class {
2816
2923
  return null;
2817
2924
  }
2818
2925
  };
2819
- var traverse4 = _traverse.default || _traverse;
2926
+ var traverse5 = _traverse.default || _traverse;
2820
2927
  var SecurityValidatorPlugin = class {
2821
2928
  static {
2822
2929
  __name(this, "SecurityValidatorPlugin");
@@ -2853,7 +2960,7 @@ var SecurityValidatorPlugin = class {
2853
2960
  }
2854
2961
  let maxNestingFound = 0;
2855
2962
  let complexityScore = 0;
2856
- traverse4(ast, {
2963
+ traverse5(ast, {
2857
2964
  enter(path) {
2858
2965
  const depth = path.scope.path.node ? getDepth(path) : 0;
2859
2966
  maxNestingFound = Math.max(maxNestingFound, depth);
@@ -2900,6 +3007,6 @@ function getDepth(path) {
2900
3007
  }
2901
3008
  __name(getDepth, "getDepth");
2902
3009
 
2903
- export { ATPCompiler, ArrayTransformer, AsyncIterationDetector, AsyncTimeoutPlugin, BatchOptimizer, BatchParallelDetector, BatchPauseExecutionError, CheckpointError, CheckpointManager, CheckpointOperation, DEFAULT_COMPILER_CONFIG, DefaultArrayTransformerPlugin, DefaultDetectionPlugin, DefaultLoopTransformerPlugin, DefaultPromiseTransformerPlugin, IN_ISOLATE_RUNTIME_FUNCTIONS, InfiniteLoopDetectionError, LoopTransformer, PAUSABLE_CALL_PATTERNS, PluggableCompiler, PluginRegistry, PromiseTransformer, RuntimeFunction, SecurityValidationError, SecurityValidatorPlugin, TransformationError, batchParallel, cleanupRuntime, clearCheckpointManager, clearRuntimeContext, containsAwait, containsPausableCall, createDefaultCompiler, createRuntimeCall, createTransformPlugin, extractForOfParamName, generateUniqueId, getCheckpointManager, getMemberExpressionPath, getNodeLocation, getRuntimeContext, hasCheckpointManager, hasRuntimeContext, initializeRuntime, isArrayMethod, isAsyncFunction, isBatchPauseError, isCheckpointError, isCompiler, isInIsolateRuntimeFunction, isPausableCall, isPausableCallExpression, isTransformationError, resetIdCounter, resumableEvery, resumableFilter, resumableFind, resumableFlatMap, resumableForEach, resumableForLoop, resumableForOf, resumableMap, resumablePromiseAll, resumablePromiseAllSettled, resumableReduce, resumableSome, resumableWhile, setCheckpointManager, setRuntimeContext, wrapInAsyncFunction };
3010
+ export { ATPCompiler, ArrayTransformer, AsyncIterationDetector, AsyncTimeoutPlugin, BatchOptimizer, BatchParallelDetector, BatchPauseExecutionError, CheckpointError, CheckpointManager, CheckpointOperation, DEFAULT_COMPILER_CONFIG, DefaultArrayTransformerPlugin, DefaultDetectionPlugin, DefaultLoopTransformerPlugin, DefaultPromiseTransformerPlugin, IN_ISOLATE_RUNTIME_FUNCTIONS, InfiniteLoopDetectionError, LoopTransformer, PAUSABLE_CALL_PATTERNS, PluggableCompiler, PluginRegistry, PromiseTransformer, RuntimeFunction, SecurityValidationError, SecurityValidatorPlugin, TransformationError, batchParallel, cleanupRuntime, clearCheckpointManager, clearRuntimeContext, containsAwait, containsPausableCall, createDefaultCompiler, createRuntimeCall, createTransformPlugin, extractForOfParamName, generateUniqueId, getCheckpointManager, getMemberExpressionPath, getNodeLocation, getRuntimeContext, hasCheckpointManager, hasRuntimeContext, initializeRuntime, isArrayMethod, isAsyncFunction, isBatchPauseError, isCheckpointError, isCompiler, isInIsolateRuntimeFunction, isPausableCall, isPausableCallExpression, isTransformationError, resetIdCounter, resumableEvery, resumableFilter, resumableFind, resumableFlatMap, resumableForEach, resumableForLoop, resumableForOf, resumableMap, resumablePromiseAll, resumablePromiseAllSettled, resumableReduce, resumableSome, resumableWhile, setCheckpointManager, setRuntimeContext, transformToBatchWithReconstruction, wrapInAsyncFunction };
2904
3011
  //# sourceMappingURL=index.js.map
2905
3012
  //# sourceMappingURL=index.js.map