@famgia/omnify-core 0.0.114 → 0.0.115

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
@@ -2861,6 +2861,62 @@ function validateEnumSchema(schema, filePath) {
2861
2861
  }
2862
2862
  return errors;
2863
2863
  }
2864
+ function validatePartialSchema(schema, filePath) {
2865
+ const errors = [];
2866
+ if (schema.kind !== "partial") {
2867
+ return errors;
2868
+ }
2869
+ if (!schema.target) {
2870
+ errors.push(
2871
+ validationError(
2872
+ "Partial schema requires a target schema name",
2873
+ buildLocation7(filePath),
2874
+ "Add target: SchemaName to specify which schema to extend"
2875
+ )
2876
+ );
2877
+ } else if (typeof schema.target !== "string") {
2878
+ errors.push(
2879
+ validationError(
2880
+ "Partial schema target must be a string",
2881
+ buildLocation7(filePath),
2882
+ "Example: target: User"
2883
+ )
2884
+ );
2885
+ }
2886
+ if (!schema.properties || Object.keys(schema.properties).length === 0) {
2887
+ errors.push(
2888
+ validationError(
2889
+ "Partial schema requires at least one property to extend the target",
2890
+ buildLocation7(filePath),
2891
+ "Add properties to extend the target schema"
2892
+ )
2893
+ );
2894
+ }
2895
+ if (schema.values && schema.values.length > 0) {
2896
+ errors.push(
2897
+ validationError(
2898
+ "Partial schema cannot have values (values are for enum schemas)",
2899
+ buildLocation7(filePath),
2900
+ "Remove values or change kind to enum"
2901
+ )
2902
+ );
2903
+ }
2904
+ if (schema.options) {
2905
+ const invalidOptions = ["id", "timestamps", "softDelete", "tableName"];
2906
+ for (const opt of invalidOptions) {
2907
+ if (schema.options[opt] !== void 0) {
2908
+ errors.push(
2909
+ validationError(
2910
+ `Partial schema cannot have option '${opt}' (table options belong to the target schema)`,
2911
+ buildLocation7(filePath),
2912
+ `Remove options.${opt} - table-level options should be in the target schema`
2913
+ )
2914
+ );
2915
+ }
2916
+ }
2917
+ }
2918
+ return errors;
2919
+ }
2864
2920
  function validateLocalizedString(fieldName, value, filePath, localeConfig, context) {
2865
2921
  const warnings = [];
2866
2922
  if (value === void 0 || !(0, import_omnify_types2.isLocaleMap)(value)) {
@@ -2935,6 +2991,10 @@ function validateSchema(schema, options = {}) {
2935
2991
  const enumErrors = validateEnumSchema(schema, schema.filePath);
2936
2992
  errors.push(...enumErrors);
2937
2993
  }
2994
+ if (schema.kind === "partial") {
2995
+ const partialErrors = validatePartialSchema(schema, schema.filePath);
2996
+ errors.push(...partialErrors);
2997
+ }
2938
2998
  if (schema.titleIndex && schema.properties) {
2939
2999
  if (!schema.properties[schema.titleIndex]) {
2940
3000
  errors.push(
@@ -3011,6 +3071,29 @@ function validateSchemas(schemas, options = {}) {
3011
3071
  }
3012
3072
  }
3013
3073
  }
3074
+ for (const schema of Object.values(schemas)) {
3075
+ if (schema.kind === "partial" && schema.target) {
3076
+ const targetExists = schemas[schema.target] !== void 0;
3077
+ if (!targetExists) {
3078
+ const error = validationError(
3079
+ `Partial schema '${schema.name}' targets non-existent schema '${schema.target}'`,
3080
+ buildLocation7(schema.filePath),
3081
+ `Available schemas: ${Object.keys(schemas).filter((n) => n !== schema.name).join(", ")}`
3082
+ );
3083
+ allErrors.push(error);
3084
+ const existingResult = schemaResults.find((r) => r.schemaName === schema.name);
3085
+ if (existingResult) {
3086
+ const updatedResult = {
3087
+ ...existingResult,
3088
+ valid: false,
3089
+ errors: [...existingResult.errors, error]
3090
+ };
3091
+ const index = schemaResults.indexOf(existingResult);
3092
+ schemaResults[index] = updatedResult;
3093
+ }
3094
+ }
3095
+ }
3096
+ }
3014
3097
  return {
3015
3098
  valid: allErrors.length === 0,
3016
3099
  errorCount: allErrors.length,