@famgia/omnify-core 0.0.129 → 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.d.cts CHANGED
@@ -1210,7 +1210,7 @@ interface VersionIndexSnapshot {
1210
1210
  */
1211
1211
  interface VersionSchemaSnapshot {
1212
1212
  readonly name: string;
1213
- readonly kind: 'object' | 'enum' | 'partial';
1213
+ readonly kind: 'object' | 'enum' | 'partial' | 'pivot';
1214
1214
  readonly displayName?: string;
1215
1215
  readonly singular?: string;
1216
1216
  readonly plural?: string;
package/dist/index.d.ts CHANGED
@@ -1210,7 +1210,7 @@ interface VersionIndexSnapshot {
1210
1210
  */
1211
1211
  interface VersionSchemaSnapshot {
1212
1212
  readonly name: string;
1213
- readonly kind: 'object' | 'enum' | 'partial';
1213
+ readonly kind: 'object' | 'enum' | 'partial' | 'pivot';
1214
1214
  readonly displayName?: string;
1215
1215
  readonly singular?: string;
1216
1216
  readonly plural?: string;
package/dist/index.js CHANGED
@@ -535,6 +535,12 @@ function buildSchemaDefinition(data) {
535
535
  if (data.target !== void 0 && typeof data.target === "string") {
536
536
  schema.target = data.target;
537
537
  }
538
+ if (data.priority !== void 0 && typeof data.priority === "number") {
539
+ schema.priority = data.priority;
540
+ }
541
+ if (data.pivotFor !== void 0 && Array.isArray(data.pivotFor) && data.pivotFor.length === 2) {
542
+ schema.pivotFor = data.pivotFor;
543
+ }
538
544
  if (data.displayName !== void 0 && isLocalizedString(data.displayName)) {
539
545
  schema.displayName = data.displayName;
540
546
  }
@@ -899,6 +905,11 @@ function mergePartialSchemas(schemas, partials) {
899
905
  cleanSchemas[key] = schema;
900
906
  }
901
907
  }
908
+ partialSchemas.sort((a, b) => {
909
+ const priorityA = a.priority ?? 50;
910
+ const priorityB = b.priority ?? 50;
911
+ return priorityA - priorityB;
912
+ });
902
913
  for (const partial of partialSchemas) {
903
914
  const targetName = partial.target;
904
915
  if (!targetName) {
@@ -2951,6 +2962,25 @@ function validatePartialSchema(schema, filePath) {
2951
2962
  )
2952
2963
  );
2953
2964
  }
2965
+ if (schema.priority !== void 0) {
2966
+ if (typeof schema.priority !== "number") {
2967
+ errors.push(
2968
+ validationError(
2969
+ "Partial schema priority must be a number",
2970
+ buildLocation7(filePath),
2971
+ "Example: priority: 10 (lower = higher priority, default is 50)"
2972
+ )
2973
+ );
2974
+ } else if (schema.priority < 1 || schema.priority > 100) {
2975
+ errors.push(
2976
+ validationError(
2977
+ `Partial schema priority must be between 1 and 100 (got ${schema.priority})`,
2978
+ buildLocation7(filePath),
2979
+ "Use 1-49 for high priority, 51-100 for low priority (default is 50)"
2980
+ )
2981
+ );
2982
+ }
2983
+ }
2954
2984
  if (!schema.properties || Object.keys(schema.properties).length === 0) {
2955
2985
  errors.push(
2956
2986
  validationError(
@@ -2985,6 +3015,56 @@ function validatePartialSchema(schema, filePath) {
2985
3015
  }
2986
3016
  return errors;
2987
3017
  }
3018
+ function validatePivotSchema(schema, filePath, allSchemas) {
3019
+ const errors = [];
3020
+ if (schema.kind !== "pivot") {
3021
+ return errors;
3022
+ }
3023
+ const pivotFor = schema.pivotFor;
3024
+ if (!pivotFor) {
3025
+ errors.push(
3026
+ validationError(
3027
+ "Pivot schema requires pivotFor field with two schema names",
3028
+ buildLocation7(filePath),
3029
+ "Add pivotFor: [SchemaA, SchemaB] to specify the relationship"
3030
+ )
3031
+ );
3032
+ } else if (!Array.isArray(pivotFor) || pivotFor.length !== 2) {
3033
+ errors.push(
3034
+ validationError(
3035
+ "Pivot schema pivotFor must be an array of exactly two schema names",
3036
+ buildLocation7(filePath),
3037
+ "Example: pivotFor: [User, Role]"
3038
+ )
3039
+ );
3040
+ } else {
3041
+ if (allSchemas) {
3042
+ for (const targetName of pivotFor) {
3043
+ if (!allSchemas[targetName]) {
3044
+ errors.push(
3045
+ validationError(
3046
+ `Pivot schema references unknown schema '${targetName}'`,
3047
+ buildLocation7(filePath),
3048
+ `Create schema '${targetName}' or fix the pivotFor reference`
3049
+ )
3050
+ );
3051
+ }
3052
+ }
3053
+ }
3054
+ }
3055
+ if (schema.options?.id === true) {
3056
+ }
3057
+ if (schema.values?.length) {
3058
+ errors.push(
3059
+ validationError(
3060
+ "Pivot schema cannot have values (values are for enum schemas)",
3061
+ buildLocation7(filePath),
3062
+ "Remove values or change kind to enum"
3063
+ )
3064
+ );
3065
+ }
3066
+ return errors;
3067
+ }
2988
3068
  function validateLocalizedString(fieldName, value, filePath, localeConfig, context) {
2989
3069
  const warnings = [];
2990
3070
  if (value === void 0 || !isLocaleMap(value)) {
@@ -3063,6 +3143,10 @@ function validateSchema(schema, options = {}) {
3063
3143
  const partialErrors = validatePartialSchema(schema, schema.filePath);
3064
3144
  errors.push(...partialErrors);
3065
3145
  }
3146
+ if (schema.kind === "pivot") {
3147
+ const pivotErrors = validatePivotSchema(schema, schema.filePath);
3148
+ errors.push(...pivotErrors);
3149
+ }
3066
3150
  if (schema.titleIndex && schema.properties) {
3067
3151
  if (!schema.properties[schema.titleIndex]) {
3068
3152
  errors.push(