@famgia/omnify-core 0.0.114 → 0.0.116

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
@@ -2750,6 +2750,62 @@ function validateEnumSchema(schema, filePath) {
2750
2750
  }
2751
2751
  return errors;
2752
2752
  }
2753
+ function validatePartialSchema(schema, filePath) {
2754
+ const errors = [];
2755
+ if (schema.kind !== "partial") {
2756
+ return errors;
2757
+ }
2758
+ if (!schema.target) {
2759
+ errors.push(
2760
+ validationError(
2761
+ "Partial schema requires a target schema name",
2762
+ buildLocation7(filePath),
2763
+ "Add target: SchemaName to specify which schema to extend"
2764
+ )
2765
+ );
2766
+ } else if (typeof schema.target !== "string") {
2767
+ errors.push(
2768
+ validationError(
2769
+ "Partial schema target must be a string",
2770
+ buildLocation7(filePath),
2771
+ "Example: target: User"
2772
+ )
2773
+ );
2774
+ }
2775
+ if (!schema.properties || Object.keys(schema.properties).length === 0) {
2776
+ errors.push(
2777
+ validationError(
2778
+ "Partial schema requires at least one property to extend the target",
2779
+ buildLocation7(filePath),
2780
+ "Add properties to extend the target schema"
2781
+ )
2782
+ );
2783
+ }
2784
+ if (schema.values && schema.values.length > 0) {
2785
+ errors.push(
2786
+ validationError(
2787
+ "Partial schema cannot have values (values are for enum schemas)",
2788
+ buildLocation7(filePath),
2789
+ "Remove values or change kind to enum"
2790
+ )
2791
+ );
2792
+ }
2793
+ if (schema.options) {
2794
+ const invalidOptions = ["id", "timestamps", "softDelete", "tableName"];
2795
+ for (const opt of invalidOptions) {
2796
+ if (schema.options[opt] !== void 0) {
2797
+ errors.push(
2798
+ validationError(
2799
+ `Partial schema cannot have option '${opt}' (table options belong to the target schema)`,
2800
+ buildLocation7(filePath),
2801
+ `Remove options.${opt} - table-level options should be in the target schema`
2802
+ )
2803
+ );
2804
+ }
2805
+ }
2806
+ }
2807
+ return errors;
2808
+ }
2753
2809
  function validateLocalizedString(fieldName, value, filePath, localeConfig, context) {
2754
2810
  const warnings = [];
2755
2811
  if (value === void 0 || !isLocaleMap(value)) {
@@ -2824,6 +2880,10 @@ function validateSchema(schema, options = {}) {
2824
2880
  const enumErrors = validateEnumSchema(schema, schema.filePath);
2825
2881
  errors.push(...enumErrors);
2826
2882
  }
2883
+ if (schema.kind === "partial") {
2884
+ const partialErrors = validatePartialSchema(schema, schema.filePath);
2885
+ errors.push(...partialErrors);
2886
+ }
2827
2887
  if (schema.titleIndex && schema.properties) {
2828
2888
  if (!schema.properties[schema.titleIndex]) {
2829
2889
  errors.push(
@@ -2900,6 +2960,29 @@ function validateSchemas(schemas, options = {}) {
2900
2960
  }
2901
2961
  }
2902
2962
  }
2963
+ for (const schema of Object.values(schemas)) {
2964
+ if (schema.kind === "partial" && schema.target) {
2965
+ const targetExists = schemas[schema.target] !== void 0;
2966
+ if (!targetExists) {
2967
+ const error = validationError(
2968
+ `Partial schema '${schema.name}' targets non-existent schema '${schema.target}'`,
2969
+ buildLocation7(schema.filePath),
2970
+ `Available schemas: ${Object.keys(schemas).filter((n) => n !== schema.name).join(", ")}`
2971
+ );
2972
+ allErrors.push(error);
2973
+ const existingResult = schemaResults.find((r) => r.schemaName === schema.name);
2974
+ if (existingResult) {
2975
+ const updatedResult = {
2976
+ ...existingResult,
2977
+ valid: false,
2978
+ errors: [...existingResult.errors, error]
2979
+ };
2980
+ const index = schemaResults.indexOf(existingResult);
2981
+ schemaResults[index] = updatedResult;
2982
+ }
2983
+ }
2984
+ }
2985
+ }
2903
2986
  return {
2904
2987
  valid: allErrors.length === 0,
2905
2988
  errorCount: allErrors.length,