@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.cjs +84 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -647,6 +647,12 @@ function buildSchemaDefinition(data) {
|
|
|
647
647
|
if (data.target !== void 0 && typeof data.target === "string") {
|
|
648
648
|
schema.target = data.target;
|
|
649
649
|
}
|
|
650
|
+
if (data.priority !== void 0 && typeof data.priority === "number") {
|
|
651
|
+
schema.priority = data.priority;
|
|
652
|
+
}
|
|
653
|
+
if (data.pivotFor !== void 0 && Array.isArray(data.pivotFor) && data.pivotFor.length === 2) {
|
|
654
|
+
schema.pivotFor = data.pivotFor;
|
|
655
|
+
}
|
|
650
656
|
if (data.displayName !== void 0 && (0, import_omnify_types.isLocalizedString)(data.displayName)) {
|
|
651
657
|
schema.displayName = data.displayName;
|
|
652
658
|
}
|
|
@@ -1011,6 +1017,11 @@ function mergePartialSchemas(schemas, partials) {
|
|
|
1011
1017
|
cleanSchemas[key] = schema;
|
|
1012
1018
|
}
|
|
1013
1019
|
}
|
|
1020
|
+
partialSchemas.sort((a, b) => {
|
|
1021
|
+
const priorityA = a.priority ?? 50;
|
|
1022
|
+
const priorityB = b.priority ?? 50;
|
|
1023
|
+
return priorityA - priorityB;
|
|
1024
|
+
});
|
|
1014
1025
|
for (const partial of partialSchemas) {
|
|
1015
1026
|
const targetName = partial.target;
|
|
1016
1027
|
if (!targetName) {
|
|
@@ -3063,6 +3074,25 @@ function validatePartialSchema(schema, filePath) {
|
|
|
3063
3074
|
)
|
|
3064
3075
|
);
|
|
3065
3076
|
}
|
|
3077
|
+
if (schema.priority !== void 0) {
|
|
3078
|
+
if (typeof schema.priority !== "number") {
|
|
3079
|
+
errors.push(
|
|
3080
|
+
validationError(
|
|
3081
|
+
"Partial schema priority must be a number",
|
|
3082
|
+
buildLocation7(filePath),
|
|
3083
|
+
"Example: priority: 10 (lower = higher priority, default is 50)"
|
|
3084
|
+
)
|
|
3085
|
+
);
|
|
3086
|
+
} else if (schema.priority < 1 || schema.priority > 100) {
|
|
3087
|
+
errors.push(
|
|
3088
|
+
validationError(
|
|
3089
|
+
`Partial schema priority must be between 1 and 100 (got ${schema.priority})`,
|
|
3090
|
+
buildLocation7(filePath),
|
|
3091
|
+
"Use 1-49 for high priority, 51-100 for low priority (default is 50)"
|
|
3092
|
+
)
|
|
3093
|
+
);
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3066
3096
|
if (!schema.properties || Object.keys(schema.properties).length === 0) {
|
|
3067
3097
|
errors.push(
|
|
3068
3098
|
validationError(
|
|
@@ -3097,6 +3127,56 @@ function validatePartialSchema(schema, filePath) {
|
|
|
3097
3127
|
}
|
|
3098
3128
|
return errors;
|
|
3099
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
|
+
}
|
|
3100
3180
|
function validateLocalizedString(fieldName, value, filePath, localeConfig, context) {
|
|
3101
3181
|
const warnings = [];
|
|
3102
3182
|
if (value === void 0 || !(0, import_omnify_types2.isLocaleMap)(value)) {
|
|
@@ -3175,6 +3255,10 @@ function validateSchema(schema, options = {}) {
|
|
|
3175
3255
|
const partialErrors = validatePartialSchema(schema, schema.filePath);
|
|
3176
3256
|
errors.push(...partialErrors);
|
|
3177
3257
|
}
|
|
3258
|
+
if (schema.kind === "pivot") {
|
|
3259
|
+
const pivotErrors = validatePivotSchema(schema, schema.filePath);
|
|
3260
|
+
errors.push(...pivotErrors);
|
|
3261
|
+
}
|
|
3178
3262
|
if (schema.titleIndex && schema.properties) {
|
|
3179
3263
|
if (!schema.properties[schema.titleIndex]) {
|
|
3180
3264
|
errors.push(
|