@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 +57 -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 +57 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
@@ -538,6 +538,9 @@ function buildSchemaDefinition(data) {
|
|
|
538
538
|
if (data.priority !== void 0 && typeof data.priority === "number") {
|
|
539
539
|
schema.priority = data.priority;
|
|
540
540
|
}
|
|
541
|
+
if (data.pivotFor !== void 0 && Array.isArray(data.pivotFor) && data.pivotFor.length === 2) {
|
|
542
|
+
schema.pivotFor = data.pivotFor;
|
|
543
|
+
}
|
|
541
544
|
if (data.displayName !== void 0 && isLocalizedString(data.displayName)) {
|
|
542
545
|
schema.displayName = data.displayName;
|
|
543
546
|
}
|
|
@@ -3012,6 +3015,56 @@ function validatePartialSchema(schema, filePath) {
|
|
|
3012
3015
|
}
|
|
3013
3016
|
return errors;
|
|
3014
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
|
+
}
|
|
3015
3068
|
function validateLocalizedString(fieldName, value, filePath, localeConfig, context) {
|
|
3016
3069
|
const warnings = [];
|
|
3017
3070
|
if (value === void 0 || !isLocaleMap(value)) {
|
|
@@ -3090,6 +3143,10 @@ function validateSchema(schema, options = {}) {
|
|
|
3090
3143
|
const partialErrors = validatePartialSchema(schema, schema.filePath);
|
|
3091
3144
|
errors.push(...partialErrors);
|
|
3092
3145
|
}
|
|
3146
|
+
if (schema.kind === "pivot") {
|
|
3147
|
+
const pivotErrors = validatePivotSchema(schema, schema.filePath);
|
|
3148
|
+
errors.push(...pivotErrors);
|
|
3149
|
+
}
|
|
3093
3150
|
if (schema.titleIndex && schema.properties) {
|
|
3094
3151
|
if (!schema.properties[schema.titleIndex]) {
|
|
3095
3152
|
errors.push(
|