@famgia/omnify-core 0.0.113 → 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 +113 -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 +113 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1199,7 +1199,7 @@ interface VersionIndexSnapshot {
|
|
|
1199
1199
|
*/
|
|
1200
1200
|
interface VersionSchemaSnapshot {
|
|
1201
1201
|
readonly name: string;
|
|
1202
|
-
readonly kind: 'object' | 'enum';
|
|
1202
|
+
readonly kind: 'object' | 'enum' | 'partial';
|
|
1203
1203
|
readonly displayName?: string;
|
|
1204
1204
|
readonly singular?: string;
|
|
1205
1205
|
readonly plural?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1199,7 +1199,7 @@ interface VersionIndexSnapshot {
|
|
|
1199
1199
|
*/
|
|
1200
1200
|
interface VersionSchemaSnapshot {
|
|
1201
1201
|
readonly name: string;
|
|
1202
|
-
readonly kind: 'object' | 'enum';
|
|
1202
|
+
readonly kind: 'object' | 'enum' | 'partial';
|
|
1203
1203
|
readonly displayName?: string;
|
|
1204
1204
|
readonly singular?: string;
|
|
1205
1205
|
readonly plural?: string;
|
package/dist/index.js
CHANGED
|
@@ -494,6 +494,8 @@ function parseJsonSchema(content, filePath) {
|
|
|
494
494
|
}
|
|
495
495
|
var VALID_SCHEMA_FIELDS = /* @__PURE__ */ new Set([
|
|
496
496
|
"kind",
|
|
497
|
+
"target",
|
|
498
|
+
// For partial schemas
|
|
497
499
|
"displayName",
|
|
498
500
|
"titleIndex",
|
|
499
501
|
"group",
|
|
@@ -530,6 +532,9 @@ function buildSchemaDefinition(data) {
|
|
|
530
532
|
if (data.kind !== void 0) {
|
|
531
533
|
schema.kind = data.kind;
|
|
532
534
|
}
|
|
535
|
+
if (data.target !== void 0 && typeof data.target === "string") {
|
|
536
|
+
schema.target = data.target;
|
|
537
|
+
}
|
|
533
538
|
if (data.displayName !== void 0 && isLocalizedString(data.displayName)) {
|
|
534
539
|
schema.displayName = data.displayName;
|
|
535
540
|
}
|
|
@@ -855,9 +860,14 @@ async function loadSchemas(directoryPath, options = {}) {
|
|
|
855
860
|
}
|
|
856
861
|
const schemaFiles = await findSchemaFiles(absoluteDir, extensions, recursive);
|
|
857
862
|
const schemas = {};
|
|
863
|
+
const partialSchemas = [];
|
|
858
864
|
const schemaLocations = {};
|
|
859
865
|
for (const filePath of schemaFiles) {
|
|
860
866
|
const schema = await loadSchema(filePath, { baseDir: absoluteDir });
|
|
867
|
+
if (schema.kind === "partial") {
|
|
868
|
+
partialSchemas.push(schema);
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
861
871
|
const existingLocation = schemaLocations[schema.name];
|
|
862
872
|
if (existingLocation !== void 0) {
|
|
863
873
|
throw duplicateSchemaError(
|
|
@@ -869,6 +879,26 @@ async function loadSchemas(directoryPath, options = {}) {
|
|
|
869
879
|
schemas[schema.name] = schema;
|
|
870
880
|
schemaLocations[schema.name] = filePath;
|
|
871
881
|
}
|
|
882
|
+
for (const partial of partialSchemas) {
|
|
883
|
+
const targetName = partial.target;
|
|
884
|
+
if (!targetName) {
|
|
885
|
+
console.warn(`Partial schema '${partial.name}' has no target, skipping`);
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
const target = schemas[targetName];
|
|
889
|
+
if (!target) {
|
|
890
|
+
console.warn(`Partial schema '${partial.name}' targets unknown schema '${targetName}', skipping`);
|
|
891
|
+
continue;
|
|
892
|
+
}
|
|
893
|
+
const mergedProperties = {
|
|
894
|
+
...partial.properties ?? {},
|
|
895
|
+
...target.properties ?? {}
|
|
896
|
+
};
|
|
897
|
+
schemas[targetName] = {
|
|
898
|
+
...target,
|
|
899
|
+
properties: mergedProperties
|
|
900
|
+
};
|
|
901
|
+
}
|
|
872
902
|
return schemas;
|
|
873
903
|
}
|
|
874
904
|
var FILE_SCHEMA_NAME = "File";
|
|
@@ -2720,6 +2750,62 @@ function validateEnumSchema(schema, filePath) {
|
|
|
2720
2750
|
}
|
|
2721
2751
|
return errors;
|
|
2722
2752
|
}
|
|
2753
|
+
function validatePartialSchema(schema, filePath) {
|
|
2754
|
+
const errors = [];
|
|
2755
|
+
if (schema.kind !== "partial") {
|
|
2756
|
+
return errors;
|
|
2757
|
+
}
|
|
2758
|
+
if (!schema.target) {
|
|
2759
|
+
errors.push(
|
|
2760
|
+
validationError(
|
|
2761
|
+
"Partial schema requires a target schema name",
|
|
2762
|
+
buildLocation7(filePath),
|
|
2763
|
+
"Add target: SchemaName to specify which schema to extend"
|
|
2764
|
+
)
|
|
2765
|
+
);
|
|
2766
|
+
} else if (typeof schema.target !== "string") {
|
|
2767
|
+
errors.push(
|
|
2768
|
+
validationError(
|
|
2769
|
+
"Partial schema target must be a string",
|
|
2770
|
+
buildLocation7(filePath),
|
|
2771
|
+
"Example: target: User"
|
|
2772
|
+
)
|
|
2773
|
+
);
|
|
2774
|
+
}
|
|
2775
|
+
if (!schema.properties || Object.keys(schema.properties).length === 0) {
|
|
2776
|
+
errors.push(
|
|
2777
|
+
validationError(
|
|
2778
|
+
"Partial schema requires at least one property to extend the target",
|
|
2779
|
+
buildLocation7(filePath),
|
|
2780
|
+
"Add properties to extend the target schema"
|
|
2781
|
+
)
|
|
2782
|
+
);
|
|
2783
|
+
}
|
|
2784
|
+
if (schema.values && schema.values.length > 0) {
|
|
2785
|
+
errors.push(
|
|
2786
|
+
validationError(
|
|
2787
|
+
"Partial schema cannot have values (values are for enum schemas)",
|
|
2788
|
+
buildLocation7(filePath),
|
|
2789
|
+
"Remove values or change kind to enum"
|
|
2790
|
+
)
|
|
2791
|
+
);
|
|
2792
|
+
}
|
|
2793
|
+
if (schema.options) {
|
|
2794
|
+
const invalidOptions = ["id", "timestamps", "softDelete", "tableName"];
|
|
2795
|
+
for (const opt of invalidOptions) {
|
|
2796
|
+
if (schema.options[opt] !== void 0) {
|
|
2797
|
+
errors.push(
|
|
2798
|
+
validationError(
|
|
2799
|
+
`Partial schema cannot have option '${opt}' (table options belong to the target schema)`,
|
|
2800
|
+
buildLocation7(filePath),
|
|
2801
|
+
`Remove options.${opt} - table-level options should be in the target schema`
|
|
2802
|
+
)
|
|
2803
|
+
);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
return errors;
|
|
2808
|
+
}
|
|
2723
2809
|
function validateLocalizedString(fieldName, value, filePath, localeConfig, context) {
|
|
2724
2810
|
const warnings = [];
|
|
2725
2811
|
if (value === void 0 || !isLocaleMap(value)) {
|
|
@@ -2794,6 +2880,10 @@ function validateSchema(schema, options = {}) {
|
|
|
2794
2880
|
const enumErrors = validateEnumSchema(schema, schema.filePath);
|
|
2795
2881
|
errors.push(...enumErrors);
|
|
2796
2882
|
}
|
|
2883
|
+
if (schema.kind === "partial") {
|
|
2884
|
+
const partialErrors = validatePartialSchema(schema, schema.filePath);
|
|
2885
|
+
errors.push(...partialErrors);
|
|
2886
|
+
}
|
|
2797
2887
|
if (schema.titleIndex && schema.properties) {
|
|
2798
2888
|
if (!schema.properties[schema.titleIndex]) {
|
|
2799
2889
|
errors.push(
|
|
@@ -2870,6 +2960,29 @@ function validateSchemas(schemas, options = {}) {
|
|
|
2870
2960
|
}
|
|
2871
2961
|
}
|
|
2872
2962
|
}
|
|
2963
|
+
for (const schema of Object.values(schemas)) {
|
|
2964
|
+
if (schema.kind === "partial" && schema.target) {
|
|
2965
|
+
const targetExists = schemas[schema.target] !== void 0;
|
|
2966
|
+
if (!targetExists) {
|
|
2967
|
+
const error = validationError(
|
|
2968
|
+
`Partial schema '${schema.name}' targets non-existent schema '${schema.target}'`,
|
|
2969
|
+
buildLocation7(schema.filePath),
|
|
2970
|
+
`Available schemas: ${Object.keys(schemas).filter((n) => n !== schema.name).join(", ")}`
|
|
2971
|
+
);
|
|
2972
|
+
allErrors.push(error);
|
|
2973
|
+
const existingResult = schemaResults.find((r) => r.schemaName === schema.name);
|
|
2974
|
+
if (existingResult) {
|
|
2975
|
+
const updatedResult = {
|
|
2976
|
+
...existingResult,
|
|
2977
|
+
valid: false,
|
|
2978
|
+
errors: [...existingResult.errors, error]
|
|
2979
|
+
};
|
|
2980
|
+
const index = schemaResults.indexOf(existingResult);
|
|
2981
|
+
schemaResults[index] = updatedResult;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2873
2986
|
return {
|
|
2874
2987
|
valid: allErrors.length === 0,
|
|
2875
2988
|
errorCount: allErrors.length,
|