@teamkeel/functions-runtime 0.415.0 → 0.415.2

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
@@ -2482,22 +2482,16 @@ async function page(options, data, action) {
2482
2482
  }
2483
2483
  }
2484
2484
  const contentUiConfig = await Promise.all(
2485
- content.map(async (content2) => {
2486
- let c = await content2;
2487
- const isInput = "__type" in c && c.__type == "input";
2488
- const hasData = data && c.uiConfig.name in data;
2489
- if (isInput && hasData && "validate" in c && c.validate) {
2490
- const validationError2 = await c.validate(data[c.uiConfig.name]);
2491
- if (typeof validationError2 === "string") {
2492
- hasValidationErrors = true;
2493
- return {
2494
- ...c.uiConfig,
2495
- validationError: validationError2
2496
- };
2497
- }
2498
- }
2499
- return c.uiConfig;
2500
- }).filter(Boolean)
2485
+ content.map(async (c) => {
2486
+ const resolvedC = await c;
2487
+ const elementData = data && typeof data === "object" && resolvedC.uiConfig.name in data ? data[resolvedC.uiConfig.name] : void 0;
2488
+ const { uiConfig, validationErrors } = await recursivelyProcessElement(
2489
+ c,
2490
+ elementData
2491
+ );
2492
+ if (validationErrors) hasValidationErrors = true;
2493
+ return uiConfig;
2494
+ })
2501
2495
  );
2502
2496
  if (data && options.validate) {
2503
2497
  const validationResult = await options.validate(data);
@@ -2528,6 +2522,101 @@ async function page(options, data, action) {
2528
2522
  };
2529
2523
  }
2530
2524
  __name(page, "page");
2525
+ var recursivelyProcessElement = /* @__PURE__ */ __name(async (c, data) => {
2526
+ const resolvedC = await c;
2527
+ const elementType = "__type" in resolvedC ? resolvedC.__type : null;
2528
+ switch (elementType) {
2529
+ case "input":
2530
+ return processInputElement(
2531
+ resolvedC,
2532
+ data
2533
+ );
2534
+ case "iterator":
2535
+ return processIteratorElement(
2536
+ resolvedC,
2537
+ data
2538
+ );
2539
+ default:
2540
+ return {
2541
+ uiConfig: { ...resolvedC.uiConfig },
2542
+ validationErrors: false
2543
+ };
2544
+ }
2545
+ }, "recursivelyProcessElement");
2546
+ var processInputElement = /* @__PURE__ */ __name(async (element, data) => {
2547
+ const hasData = data !== void 0 && data !== null;
2548
+ if (!hasData || !element.validate) {
2549
+ return {
2550
+ uiConfig: { ...element.uiConfig },
2551
+ validationErrors: false
2552
+ };
2553
+ }
2554
+ const validationError = await element.validate(data);
2555
+ const hasValidationErrors = typeof validationError === "string";
2556
+ return {
2557
+ uiConfig: {
2558
+ ...element.uiConfig,
2559
+ validationError: hasValidationErrors ? validationError : void 0
2560
+ },
2561
+ validationErrors: hasValidationErrors
2562
+ };
2563
+ }, "processInputElement");
2564
+ var processIteratorElement = /* @__PURE__ */ __name(async (element, data) => {
2565
+ const elements = element.uiConfig.content;
2566
+ const dataArr = data;
2567
+ const ui = [];
2568
+ for (const el of elements) {
2569
+ const result = await recursivelyProcessElement(el, void 0);
2570
+ ui.push(result.uiConfig);
2571
+ }
2572
+ const validationErrors = await validateIteratorData(elements, dataArr);
2573
+ let hasValidationErrors = validationErrors.length > 0;
2574
+ let validationError = void 0;
2575
+ if (dataArr && element.validate) {
2576
+ const v = await element.validate(dataArr);
2577
+ if (typeof v === "string") {
2578
+ hasValidationErrors = true;
2579
+ validationError = v;
2580
+ }
2581
+ }
2582
+ return {
2583
+ uiConfig: {
2584
+ ...element.uiConfig,
2585
+ content: ui,
2586
+ validationError,
2587
+ contentValidationErrors: hasValidationErrors ? validationErrors : void 0
2588
+ },
2589
+ validationErrors: hasValidationErrors
2590
+ };
2591
+ }, "processIteratorElement");
2592
+ var validateIteratorData = /* @__PURE__ */ __name(async (elements, dataArr) => {
2593
+ const validationErrors = [];
2594
+ if (!dataArr || dataArr.length === 0) {
2595
+ return validationErrors;
2596
+ }
2597
+ for (let i = 0; i < dataArr.length; i++) {
2598
+ const rowData = dataArr[i];
2599
+ for (const el of elements) {
2600
+ const resolvedEl = await el;
2601
+ if ("__type" in resolvedEl && resolvedEl.__type === "input" && "validate" in resolvedEl && resolvedEl.validate && typeof resolvedEl.validate === "function") {
2602
+ const fieldName = resolvedEl.uiConfig.name;
2603
+ if (rowData && typeof rowData === "object" && fieldName in rowData) {
2604
+ const validationError = await resolvedEl.validate(
2605
+ rowData[fieldName]
2606
+ );
2607
+ if (typeof validationError === "string") {
2608
+ validationErrors.push({
2609
+ index: i,
2610
+ name: fieldName,
2611
+ validationError
2612
+ });
2613
+ }
2614
+ }
2615
+ }
2616
+ }
2617
+ }
2618
+ return validationErrors;
2619
+ }, "validateIteratorData");
2531
2620
 
2532
2621
  // src/flows/disrupts.ts
2533
2622
  var FlowDisrupt = class {
@@ -2730,6 +2819,22 @@ var dataGridInput = /* @__PURE__ */ __name((name, options) => {
2730
2819
  };
2731
2820
  }, "dataGridInput");
2732
2821
 
2822
+ // src/flows/ui/elements/iterator.ts
2823
+ var iterator = /* @__PURE__ */ __name((name, options) => {
2824
+ return {
2825
+ __type: "iterator",
2826
+ uiConfig: {
2827
+ __type: "ui.iterator",
2828
+ name,
2829
+ content: options.content,
2830
+ max: options.max,
2831
+ min: options.min
2832
+ },
2833
+ validate: options?.validate,
2834
+ getData: /* @__PURE__ */ __name((x) => x, "getData")
2835
+ };
2836
+ }, "iterator");
2837
+
2733
2838
  // src/flows/ui/elements/interactive/print.ts
2734
2839
  var print = /* @__PURE__ */ __name(async (options) => {
2735
2840
  const dataConfig = Array.isArray(options.jobs) ? options.jobs : [options.jobs];
@@ -3019,6 +3124,7 @@ function createFlowContext(runId, data, action, spanId, ctx) {
3019
3124
  one: selectOne,
3020
3125
  table: selectTable
3021
3126
  },
3127
+ iterator,
3022
3128
  interactive: {
3023
3129
  print,
3024
3130
  pickList