@kubuild/core 0.3.1 → 0.5.0

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
@@ -2719,6 +2719,7 @@ function sanitizeHtml(rawHtml) {
2719
2719
  // src/validation/validator.ts
2720
2720
  function validateDocument(input, options = {}) {
2721
2721
  const errors = [];
2722
+ const warnings = [];
2722
2723
  if (!input || typeof input !== "object" || Array.isArray(input)) {
2723
2724
  return {
2724
2725
  valid: false,
@@ -2729,7 +2730,8 @@ function validateDocument(input, options = {}) {
2729
2730
  message: "Document must be a valid non-null object",
2730
2731
  path: ""
2731
2732
  }
2732
- ]
2733
+ ],
2734
+ warnings: []
2733
2735
  };
2734
2736
  }
2735
2737
  const doc = input;
@@ -2747,7 +2749,8 @@ function validateDocument(input, options = {}) {
2747
2749
  return {
2748
2750
  valid: false,
2749
2751
  success: false,
2750
- errors
2752
+ errors,
2753
+ warnings: []
2751
2754
  };
2752
2755
  }
2753
2756
  }
@@ -2774,7 +2777,8 @@ function validateDocument(input, options = {}) {
2774
2777
  return {
2775
2778
  valid: false,
2776
2779
  success: false,
2777
- errors
2780
+ errors,
2781
+ warnings
2778
2782
  };
2779
2783
  }
2780
2784
  const rootNode = doc.document;
@@ -2813,7 +2817,8 @@ function validateDocument(input, options = {}) {
2813
2817
  seenIds,
2814
2818
  visitedObjects,
2815
2819
  options,
2816
- errors
2820
+ errors,
2821
+ warnings
2817
2822
  );
2818
2823
  if (errors.length === 0) {
2819
2824
  const zodResult = PageDocumentSchema.safeParse(input);
@@ -2831,6 +2836,7 @@ function validateDocument(input, options = {}) {
2831
2836
  valid: true,
2832
2837
  success: true,
2833
2838
  errors: [],
2839
+ warnings,
2834
2840
  data: zodResult.data
2835
2841
  };
2836
2842
  }
@@ -2838,10 +2844,11 @@ function validateDocument(input, options = {}) {
2838
2844
  return {
2839
2845
  valid: errors.length === 0,
2840
2846
  success: errors.length === 0,
2841
- errors
2847
+ errors,
2848
+ warnings
2842
2849
  };
2843
2850
  }
2844
- function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visitedObjects, options, errors) {
2851
+ function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visitedObjects, options, errors, warnings) {
2845
2852
  if (visitedObjects.has(nodeObj)) {
2846
2853
  errors.push({
2847
2854
  code: "TREE_CYCLE_DETECTED",
@@ -2950,12 +2957,22 @@ function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visite
2950
2957
  const childIsKnown = !options.componentRegistry || options.componentRegistry.has(childType);
2951
2958
  const childCategory = options.componentRegistry?.get(childType)?.category;
2952
2959
  if (componentDef?.allowedChildren && childType && childIsKnown && !componentDef.allowedChildren.includes(childType) && !componentDef.allowedChildren.includes("*") && !(childCategory && componentDef.allowedChildren.includes(childCategory))) {
2953
- errors.push({
2954
- code: "CHILD_POLICY_VIOLATION",
2955
- message: `Component type "${childType}" is not allowed as a child of "${effectiveNodeType}". Allowed types: ${componentDef.allowedChildren.join(", ")}`,
2956
- path: `${childPath}/type`,
2957
- nodeId: typeof childRecord.id === "string" ? childRecord.id : void 0
2958
- });
2960
+ const violationMessage = `Component type "${childType}" is not allowed as a child of "${effectiveNodeType}". Allowed types: ${componentDef.allowedChildren.join(", ")}`;
2961
+ if (options.strictChildPolicy) {
2962
+ errors.push({
2963
+ code: "CHILD_POLICY_VIOLATION",
2964
+ message: violationMessage,
2965
+ path: `${childPath}/type`,
2966
+ nodeId: typeof childRecord.id === "string" ? childRecord.id : void 0
2967
+ });
2968
+ } else {
2969
+ warnings.push({
2970
+ code: "CHILD_POLICY_VIOLATION",
2971
+ message: violationMessage,
2972
+ path: `${childPath}/type`,
2973
+ nodeId: typeof childRecord.id === "string" ? childRecord.id : void 0
2974
+ });
2975
+ }
2959
2976
  }
2960
2977
  validateNodeRecursive(
2961
2978
  childRecord,
@@ -2964,7 +2981,8 @@ function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visite
2964
2981
  seenIds,
2965
2982
  visitedObjects,
2966
2983
  options,
2967
- errors
2984
+ errors,
2985
+ warnings
2968
2986
  );
2969
2987
  }
2970
2988
  }