@famgia/omnify-core 0.0.127 → 0.0.129

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
@@ -85,6 +85,7 @@ __export(index_exports, {
85
85
  jsonSyntaxError: () => jsonSyntaxError,
86
86
  loadSchema: () => loadSchema,
87
87
  loadSchemas: () => loadSchemas,
88
+ mergePartialSchemas: () => mergePartialSchemas,
88
89
  missingConfigFieldError: () => missingConfigFieldError,
89
90
  missingFieldError: () => missingFieldError,
90
91
  notImplementedError: () => notImplementedError,
@@ -955,7 +956,8 @@ async function findSchemaFiles(dirPath, extensions, recursive) {
955
956
  async function loadSchemas(directoryPath, options = {}) {
956
957
  const {
957
958
  extensions = [".yaml", ".yml", ".json"],
958
- recursive = true
959
+ recursive = true,
960
+ skipPartialResolution = false
959
961
  } = options;
960
962
  const absoluteDir = path.resolve(directoryPath);
961
963
  try {
@@ -990,16 +992,35 @@ async function loadSchemas(directoryPath, options = {}) {
990
992
  schemas[schema.name] = schema;
991
993
  schemaLocations[schema.name] = filePath;
992
994
  }
995
+ if (skipPartialResolution) {
996
+ for (const partial of partialSchemas) {
997
+ const partialKey = `__partial__${partial.name}`;
998
+ schemas[partialKey] = partial;
999
+ }
1000
+ return schemas;
1001
+ }
1002
+ return mergePartialSchemas(schemas, partialSchemas);
1003
+ }
1004
+ function mergePartialSchemas(schemas, partials) {
1005
+ const partialSchemas = partials ?? [];
1006
+ const cleanSchemas = {};
1007
+ for (const [key, schema] of Object.entries(schemas)) {
1008
+ if (key.startsWith("__partial__")) {
1009
+ partialSchemas.push(schema);
1010
+ } else {
1011
+ cleanSchemas[key] = schema;
1012
+ }
1013
+ }
993
1014
  for (const partial of partialSchemas) {
994
1015
  const targetName = partial.target;
995
1016
  if (!targetName) {
996
1017
  console.warn(`Partial schema '${partial.name}' has no target, skipping`);
997
1018
  continue;
998
1019
  }
999
- const target = schemas[targetName];
1020
+ const target = cleanSchemas[targetName];
1000
1021
  if (!target) {
1001
1022
  if (partial.name === targetName) {
1002
- schemas[partial.name] = {
1023
+ cleanSchemas[partial.name] = {
1003
1024
  ...partial,
1004
1025
  kind: "object"
1005
1026
  };
@@ -1012,12 +1033,12 @@ async function loadSchemas(directoryPath, options = {}) {
1012
1033
  ...partial.properties ?? {},
1013
1034
  ...target.properties ?? {}
1014
1035
  };
1015
- schemas[targetName] = {
1036
+ cleanSchemas[targetName] = {
1016
1037
  ...target,
1017
1038
  properties: mergedProperties
1018
1039
  };
1019
1040
  }
1020
- return schemas;
1041
+ return cleanSchemas;
1021
1042
  }
1022
1043
  var FILE_SCHEMA_NAME = "File";
1023
1044
  function schemasHaveFileProperties(schemas) {
@@ -2460,6 +2481,9 @@ function validateDefaultValue(typeName, value, property) {
2460
2481
 
2461
2482
  // src/validation/validator.ts
2462
2483
  var VALID_ID_TYPES = ["Int", "BigInt", "Uuid", "String"];
2484
+ function toSnakeCase(str) {
2485
+ return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
2486
+ }
2463
2487
  function buildLocation7(file, line, column) {
2464
2488
  const loc = { file };
2465
2489
  if (line !== void 0) {
@@ -2895,6 +2919,20 @@ function validateAssociations(schema, allSchemas) {
2895
2919
  )
2896
2920
  );
2897
2921
  }
2922
+ if (relation === "ManyToOne" || relation === "OneToOne" && !assocProp.mappedBy) {
2923
+ const expectedFkColumn = `${toSnakeCase(name)}_id`;
2924
+ if (schema.properties[expectedFkColumn]) {
2925
+ errors.push(
2926
+ validationError(
2927
+ `Duplicate FK definition: Property '${expectedFkColumn}' conflicts with Association '${name}'`,
2928
+ buildLocation7(schema.filePath),
2929
+ `Both create the same column '${expectedFkColumn}'. Choose one approach:
2930
+ 1. Use Association only (remove '${expectedFkColumn}' property) - recommended
2931
+ 2. Use explicit FK only (remove '${name}' Association)`
2932
+ )
2933
+ );
2934
+ }
2935
+ }
2898
2936
  }
2899
2937
  return errors;
2900
2938
  }
@@ -4768,6 +4806,7 @@ function createVersionStore(config) {
4768
4806
  jsonSyntaxError,
4769
4807
  loadSchema,
4770
4808
  loadSchemas,
4809
+ mergePartialSchemas,
4771
4810
  missingConfigFieldError,
4772
4811
  missingFieldError,
4773
4812
  notImplementedError,