@famgia/omnify-core 0.0.130 → 0.0.131

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
@@ -650,6 +650,9 @@ function buildSchemaDefinition(data) {
650
650
  if (data.priority !== void 0 && typeof data.priority === "number") {
651
651
  schema.priority = data.priority;
652
652
  }
653
+ if (data.pivotFor !== void 0 && Array.isArray(data.pivotFor) && data.pivotFor.length === 2) {
654
+ schema.pivotFor = data.pivotFor;
655
+ }
653
656
  if (data.displayName !== void 0 && (0, import_omnify_types.isLocalizedString)(data.displayName)) {
654
657
  schema.displayName = data.displayName;
655
658
  }
@@ -3124,6 +3127,56 @@ function validatePartialSchema(schema, filePath) {
3124
3127
  }
3125
3128
  return errors;
3126
3129
  }
3130
+ function validatePivotSchema(schema, filePath, allSchemas) {
3131
+ const errors = [];
3132
+ if (schema.kind !== "pivot") {
3133
+ return errors;
3134
+ }
3135
+ const pivotFor = schema.pivotFor;
3136
+ if (!pivotFor) {
3137
+ errors.push(
3138
+ validationError(
3139
+ "Pivot schema requires pivotFor field with two schema names",
3140
+ buildLocation7(filePath),
3141
+ "Add pivotFor: [SchemaA, SchemaB] to specify the relationship"
3142
+ )
3143
+ );
3144
+ } else if (!Array.isArray(pivotFor) || pivotFor.length !== 2) {
3145
+ errors.push(
3146
+ validationError(
3147
+ "Pivot schema pivotFor must be an array of exactly two schema names",
3148
+ buildLocation7(filePath),
3149
+ "Example: pivotFor: [User, Role]"
3150
+ )
3151
+ );
3152
+ } else {
3153
+ if (allSchemas) {
3154
+ for (const targetName of pivotFor) {
3155
+ if (!allSchemas[targetName]) {
3156
+ errors.push(
3157
+ validationError(
3158
+ `Pivot schema references unknown schema '${targetName}'`,
3159
+ buildLocation7(filePath),
3160
+ `Create schema '${targetName}' or fix the pivotFor reference`
3161
+ )
3162
+ );
3163
+ }
3164
+ }
3165
+ }
3166
+ }
3167
+ if (schema.options?.id === true) {
3168
+ }
3169
+ if (schema.values?.length) {
3170
+ errors.push(
3171
+ validationError(
3172
+ "Pivot schema cannot have values (values are for enum schemas)",
3173
+ buildLocation7(filePath),
3174
+ "Remove values or change kind to enum"
3175
+ )
3176
+ );
3177
+ }
3178
+ return errors;
3179
+ }
3127
3180
  function validateLocalizedString(fieldName, value, filePath, localeConfig, context) {
3128
3181
  const warnings = [];
3129
3182
  if (value === void 0 || !(0, import_omnify_types2.isLocaleMap)(value)) {
@@ -3202,6 +3255,10 @@ function validateSchema(schema, options = {}) {
3202
3255
  const partialErrors = validatePartialSchema(schema, schema.filePath);
3203
3256
  errors.push(...partialErrors);
3204
3257
  }
3258
+ if (schema.kind === "pivot") {
3259
+ const pivotErrors = validatePivotSchema(schema, schema.filePath);
3260
+ errors.push(...pivotErrors);
3261
+ }
3205
3262
  if (schema.titleIndex && schema.properties) {
3206
3263
  if (!schema.properties[schema.titleIndex]) {
3207
3264
  errors.push(