@kubuild/core 0.4.0 → 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.cjs CHANGED
@@ -2843,6 +2843,7 @@ function sanitizeHtml(rawHtml) {
2843
2843
  // src/validation/validator.ts
2844
2844
  function validateDocument(input, options = {}) {
2845
2845
  const errors = [];
2846
+ const warnings = [];
2846
2847
  if (!input || typeof input !== "object" || Array.isArray(input)) {
2847
2848
  return {
2848
2849
  valid: false,
@@ -2853,7 +2854,8 @@ function validateDocument(input, options = {}) {
2853
2854
  message: "Document must be a valid non-null object",
2854
2855
  path: ""
2855
2856
  }
2856
- ]
2857
+ ],
2858
+ warnings: []
2857
2859
  };
2858
2860
  }
2859
2861
  const doc = input;
@@ -2871,7 +2873,8 @@ function validateDocument(input, options = {}) {
2871
2873
  return {
2872
2874
  valid: false,
2873
2875
  success: false,
2874
- errors
2876
+ errors,
2877
+ warnings: []
2875
2878
  };
2876
2879
  }
2877
2880
  }
@@ -2898,7 +2901,8 @@ function validateDocument(input, options = {}) {
2898
2901
  return {
2899
2902
  valid: false,
2900
2903
  success: false,
2901
- errors
2904
+ errors,
2905
+ warnings
2902
2906
  };
2903
2907
  }
2904
2908
  const rootNode = doc.document;
@@ -2937,7 +2941,8 @@ function validateDocument(input, options = {}) {
2937
2941
  seenIds,
2938
2942
  visitedObjects,
2939
2943
  options,
2940
- errors
2944
+ errors,
2945
+ warnings
2941
2946
  );
2942
2947
  if (errors.length === 0) {
2943
2948
  const zodResult = import_schema5.PageDocumentSchema.safeParse(input);
@@ -2955,6 +2960,7 @@ function validateDocument(input, options = {}) {
2955
2960
  valid: true,
2956
2961
  success: true,
2957
2962
  errors: [],
2963
+ warnings,
2958
2964
  data: zodResult.data
2959
2965
  };
2960
2966
  }
@@ -2962,10 +2968,11 @@ function validateDocument(input, options = {}) {
2962
2968
  return {
2963
2969
  valid: errors.length === 0,
2964
2970
  success: errors.length === 0,
2965
- errors
2971
+ errors,
2972
+ warnings
2966
2973
  };
2967
2974
  }
2968
- function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visitedObjects, options, errors) {
2975
+ function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visitedObjects, options, errors, warnings) {
2969
2976
  if (visitedObjects.has(nodeObj)) {
2970
2977
  errors.push({
2971
2978
  code: "TREE_CYCLE_DETECTED",
@@ -3074,12 +3081,22 @@ function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visite
3074
3081
  const childIsKnown = !options.componentRegistry || options.componentRegistry.has(childType);
3075
3082
  const childCategory = options.componentRegistry?.get(childType)?.category;
3076
3083
  if (componentDef?.allowedChildren && childType && childIsKnown && !componentDef.allowedChildren.includes(childType) && !componentDef.allowedChildren.includes("*") && !(childCategory && componentDef.allowedChildren.includes(childCategory))) {
3077
- errors.push({
3078
- code: "CHILD_POLICY_VIOLATION",
3079
- message: `Component type "${childType}" is not allowed as a child of "${effectiveNodeType}". Allowed types: ${componentDef.allowedChildren.join(", ")}`,
3080
- path: `${childPath}/type`,
3081
- nodeId: typeof childRecord.id === "string" ? childRecord.id : void 0
3082
- });
3084
+ const violationMessage = `Component type "${childType}" is not allowed as a child of "${effectiveNodeType}". Allowed types: ${componentDef.allowedChildren.join(", ")}`;
3085
+ if (options.strictChildPolicy) {
3086
+ errors.push({
3087
+ code: "CHILD_POLICY_VIOLATION",
3088
+ message: violationMessage,
3089
+ path: `${childPath}/type`,
3090
+ nodeId: typeof childRecord.id === "string" ? childRecord.id : void 0
3091
+ });
3092
+ } else {
3093
+ warnings.push({
3094
+ code: "CHILD_POLICY_VIOLATION",
3095
+ message: violationMessage,
3096
+ path: `${childPath}/type`,
3097
+ nodeId: typeof childRecord.id === "string" ? childRecord.id : void 0
3098
+ });
3099
+ }
3083
3100
  }
3084
3101
  validateNodeRecursive(
3085
3102
  childRecord,
@@ -3088,7 +3105,8 @@ function validateNodeRecursive(nodeObj, currentPath, parentNode, seenIds, visite
3088
3105
  seenIds,
3089
3106
  visitedObjects,
3090
3107
  options,
3091
- errors
3108
+ errors,
3109
+ warnings
3092
3110
  );
3093
3111
  }
3094
3112
  }