@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 +44 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +43 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -235,6 +235,8 @@ interface LoadSchemasOptions {
|
|
|
235
235
|
readonly extensions?: readonly string[];
|
|
236
236
|
/** Whether to load recursively from subdirectories (default: true) */
|
|
237
237
|
readonly recursive?: boolean;
|
|
238
|
+
/** Skip partial schema resolution (default: false) - use mergePartialSchemas later */
|
|
239
|
+
readonly skipPartialResolution?: boolean;
|
|
238
240
|
}
|
|
239
241
|
/**
|
|
240
242
|
* Converts a file name to a schema name (PascalCase).
|
|
@@ -284,6 +286,15 @@ declare function loadSchema(filePath: string, options?: LoadSchemaOptions): Prom
|
|
|
284
286
|
* @throws OmnifyError if duplicate schema names or invalid files
|
|
285
287
|
*/
|
|
286
288
|
declare function loadSchemas(directoryPath: string, options?: LoadSchemasOptions): Promise<SchemaCollection>;
|
|
289
|
+
/**
|
|
290
|
+
* Merges partial schemas into their target schemas.
|
|
291
|
+
* Call this after combining schemas from multiple sources.
|
|
292
|
+
*
|
|
293
|
+
* @param schemas - Collection of regular schemas
|
|
294
|
+
* @param partials - Array of partial schemas to merge (optional, extracted from schemas if not provided)
|
|
295
|
+
* @returns Schema collection with partials merged into targets
|
|
296
|
+
*/
|
|
297
|
+
declare function mergePartialSchemas(schemas: Record<string, LoadedSchema>, partials?: LoadedSchema[]): SchemaCollection;
|
|
287
298
|
/**
|
|
288
299
|
* The reserved name for the File schema (polymorphic file storage).
|
|
289
300
|
*/
|
|
@@ -1363,4 +1374,4 @@ declare class VersionStore {
|
|
|
1363
1374
|
*/
|
|
1364
1375
|
declare function createVersionStore(config: VersionStoreConfig): VersionStore;
|
|
1365
1376
|
|
|
1366
|
-
export { type AssociationMetadata, type ChangeAction, type CreateVersionOptions, type DefaultValueValidationResult, type DiffOperationResult, type ExpandedProperty, FILE_SCHEMA_NAME, type FormatOptions, type GenerateOptions, type GenerateResult, type GeneratedFile, type LoadResult, type LoadSchemaOptions, type LoadSchemasOptions, Omnify, OmnifyError, type OmnifyLogger, type OmnifyOptions, PluginManager, type PluginManagerOptions, type PluginRegistrationResult, type PluginRegistry, type PropertyMetadata, type RegisteredType, type SchemaError, type SchemaIntrospection, type SchemaMetadata, type SchemaValidationResult, type SchemaWarning, type ValidationOptions, type ValidationResult, type VersionChange, type VersionDiff, type VersionFile, type VersionIndexSnapshot, type VersionPropertySnapshot, type VersionSchemaSnapshot, VersionStore, type VersionStoreConfig, type VersionSummary, atlasError, atlasNotFoundError, circularReferenceError, configError, configNotFoundError, createFileLoadedSchema, createFileSchemaDefinition, createOmnify, createPluginManager, createVersionStore, duplicateSchemaError, ensureFileSchema, expandProperty, expandSchema, expandSchemaProperties, expandSchemas, fileNameToSchemaName, findReferencedSchemas, findReferencingSchemas, formatError, formatErrorPlain, formatErrorSummary, generateFileSchemaYaml, generationError, getAssociationMetadata, getCustomTypeNames, getEntitySchemas, getEnumSchemas, getExitCode, getGroups, getPropertyMetadata, getRelationshipGraph, getSchemaMetadata, getSchemaNames, getSchemasByGroup, getSchemasByKind, getTopologicalOrder, getTypeInfo, hasCircularReferences, internalError, introspectSchema, introspectSchemas, invalidAssociationTargetError, invalidConfigError, invalidPropertyTypeError, isCompoundType, jsonSyntaxError, loadSchema, loadSchemas, missingConfigFieldError, missingFieldError, notImplementedError, outputWriteError, parseJsonSchema, parseYamlSchema, pluginError, pluginNotFoundError, pluginTypeConflictError, schemaNotFoundError, schemaParseError, schemasHaveFileProperties, validateAssociations, validateDefaultValue, validateEnumSchema, validateOptions, validateProperties, validatePropertyType, validateSchema, validateSchemas, validationError, yamlSyntaxError };
|
|
1377
|
+
export { type AssociationMetadata, type ChangeAction, type CreateVersionOptions, type DefaultValueValidationResult, type DiffOperationResult, type ExpandedProperty, FILE_SCHEMA_NAME, type FormatOptions, type GenerateOptions, type GenerateResult, type GeneratedFile, type LoadResult, type LoadSchemaOptions, type LoadSchemasOptions, Omnify, OmnifyError, type OmnifyLogger, type OmnifyOptions, PluginManager, type PluginManagerOptions, type PluginRegistrationResult, type PluginRegistry, type PropertyMetadata, type RegisteredType, type SchemaError, type SchemaIntrospection, type SchemaMetadata, type SchemaValidationResult, type SchemaWarning, type ValidationOptions, type ValidationResult, type VersionChange, type VersionDiff, type VersionFile, type VersionIndexSnapshot, type VersionPropertySnapshot, type VersionSchemaSnapshot, VersionStore, type VersionStoreConfig, type VersionSummary, atlasError, atlasNotFoundError, circularReferenceError, configError, configNotFoundError, createFileLoadedSchema, createFileSchemaDefinition, createOmnify, createPluginManager, createVersionStore, duplicateSchemaError, ensureFileSchema, expandProperty, expandSchema, expandSchemaProperties, expandSchemas, fileNameToSchemaName, findReferencedSchemas, findReferencingSchemas, formatError, formatErrorPlain, formatErrorSummary, generateFileSchemaYaml, generationError, getAssociationMetadata, getCustomTypeNames, getEntitySchemas, getEnumSchemas, getExitCode, getGroups, getPropertyMetadata, getRelationshipGraph, getSchemaMetadata, getSchemaNames, getSchemasByGroup, getSchemasByKind, getTopologicalOrder, getTypeInfo, hasCircularReferences, internalError, introspectSchema, introspectSchemas, invalidAssociationTargetError, invalidConfigError, invalidPropertyTypeError, isCompoundType, jsonSyntaxError, loadSchema, loadSchemas, mergePartialSchemas, missingConfigFieldError, missingFieldError, notImplementedError, outputWriteError, parseJsonSchema, parseYamlSchema, pluginError, pluginNotFoundError, pluginTypeConflictError, schemaNotFoundError, schemaParseError, schemasHaveFileProperties, validateAssociations, validateDefaultValue, validateEnumSchema, validateOptions, validateProperties, validatePropertyType, validateSchema, validateSchemas, validationError, yamlSyntaxError };
|
package/dist/index.d.ts
CHANGED
|
@@ -235,6 +235,8 @@ interface LoadSchemasOptions {
|
|
|
235
235
|
readonly extensions?: readonly string[];
|
|
236
236
|
/** Whether to load recursively from subdirectories (default: true) */
|
|
237
237
|
readonly recursive?: boolean;
|
|
238
|
+
/** Skip partial schema resolution (default: false) - use mergePartialSchemas later */
|
|
239
|
+
readonly skipPartialResolution?: boolean;
|
|
238
240
|
}
|
|
239
241
|
/**
|
|
240
242
|
* Converts a file name to a schema name (PascalCase).
|
|
@@ -284,6 +286,15 @@ declare function loadSchema(filePath: string, options?: LoadSchemaOptions): Prom
|
|
|
284
286
|
* @throws OmnifyError if duplicate schema names or invalid files
|
|
285
287
|
*/
|
|
286
288
|
declare function loadSchemas(directoryPath: string, options?: LoadSchemasOptions): Promise<SchemaCollection>;
|
|
289
|
+
/**
|
|
290
|
+
* Merges partial schemas into their target schemas.
|
|
291
|
+
* Call this after combining schemas from multiple sources.
|
|
292
|
+
*
|
|
293
|
+
* @param schemas - Collection of regular schemas
|
|
294
|
+
* @param partials - Array of partial schemas to merge (optional, extracted from schemas if not provided)
|
|
295
|
+
* @returns Schema collection with partials merged into targets
|
|
296
|
+
*/
|
|
297
|
+
declare function mergePartialSchemas(schemas: Record<string, LoadedSchema>, partials?: LoadedSchema[]): SchemaCollection;
|
|
287
298
|
/**
|
|
288
299
|
* The reserved name for the File schema (polymorphic file storage).
|
|
289
300
|
*/
|
|
@@ -1363,4 +1374,4 @@ declare class VersionStore {
|
|
|
1363
1374
|
*/
|
|
1364
1375
|
declare function createVersionStore(config: VersionStoreConfig): VersionStore;
|
|
1365
1376
|
|
|
1366
|
-
export { type AssociationMetadata, type ChangeAction, type CreateVersionOptions, type DefaultValueValidationResult, type DiffOperationResult, type ExpandedProperty, FILE_SCHEMA_NAME, type FormatOptions, type GenerateOptions, type GenerateResult, type GeneratedFile, type LoadResult, type LoadSchemaOptions, type LoadSchemasOptions, Omnify, OmnifyError, type OmnifyLogger, type OmnifyOptions, PluginManager, type PluginManagerOptions, type PluginRegistrationResult, type PluginRegistry, type PropertyMetadata, type RegisteredType, type SchemaError, type SchemaIntrospection, type SchemaMetadata, type SchemaValidationResult, type SchemaWarning, type ValidationOptions, type ValidationResult, type VersionChange, type VersionDiff, type VersionFile, type VersionIndexSnapshot, type VersionPropertySnapshot, type VersionSchemaSnapshot, VersionStore, type VersionStoreConfig, type VersionSummary, atlasError, atlasNotFoundError, circularReferenceError, configError, configNotFoundError, createFileLoadedSchema, createFileSchemaDefinition, createOmnify, createPluginManager, createVersionStore, duplicateSchemaError, ensureFileSchema, expandProperty, expandSchema, expandSchemaProperties, expandSchemas, fileNameToSchemaName, findReferencedSchemas, findReferencingSchemas, formatError, formatErrorPlain, formatErrorSummary, generateFileSchemaYaml, generationError, getAssociationMetadata, getCustomTypeNames, getEntitySchemas, getEnumSchemas, getExitCode, getGroups, getPropertyMetadata, getRelationshipGraph, getSchemaMetadata, getSchemaNames, getSchemasByGroup, getSchemasByKind, getTopologicalOrder, getTypeInfo, hasCircularReferences, internalError, introspectSchema, introspectSchemas, invalidAssociationTargetError, invalidConfigError, invalidPropertyTypeError, isCompoundType, jsonSyntaxError, loadSchema, loadSchemas, missingConfigFieldError, missingFieldError, notImplementedError, outputWriteError, parseJsonSchema, parseYamlSchema, pluginError, pluginNotFoundError, pluginTypeConflictError, schemaNotFoundError, schemaParseError, schemasHaveFileProperties, validateAssociations, validateDefaultValue, validateEnumSchema, validateOptions, validateProperties, validatePropertyType, validateSchema, validateSchemas, validationError, yamlSyntaxError };
|
|
1377
|
+
export { type AssociationMetadata, type ChangeAction, type CreateVersionOptions, type DefaultValueValidationResult, type DiffOperationResult, type ExpandedProperty, FILE_SCHEMA_NAME, type FormatOptions, type GenerateOptions, type GenerateResult, type GeneratedFile, type LoadResult, type LoadSchemaOptions, type LoadSchemasOptions, Omnify, OmnifyError, type OmnifyLogger, type OmnifyOptions, PluginManager, type PluginManagerOptions, type PluginRegistrationResult, type PluginRegistry, type PropertyMetadata, type RegisteredType, type SchemaError, type SchemaIntrospection, type SchemaMetadata, type SchemaValidationResult, type SchemaWarning, type ValidationOptions, type ValidationResult, type VersionChange, type VersionDiff, type VersionFile, type VersionIndexSnapshot, type VersionPropertySnapshot, type VersionSchemaSnapshot, VersionStore, type VersionStoreConfig, type VersionSummary, atlasError, atlasNotFoundError, circularReferenceError, configError, configNotFoundError, createFileLoadedSchema, createFileSchemaDefinition, createOmnify, createPluginManager, createVersionStore, duplicateSchemaError, ensureFileSchema, expandProperty, expandSchema, expandSchemaProperties, expandSchemas, fileNameToSchemaName, findReferencedSchemas, findReferencingSchemas, formatError, formatErrorPlain, formatErrorSummary, generateFileSchemaYaml, generationError, getAssociationMetadata, getCustomTypeNames, getEntitySchemas, getEnumSchemas, getExitCode, getGroups, getPropertyMetadata, getRelationshipGraph, getSchemaMetadata, getSchemaNames, getSchemasByGroup, getSchemasByKind, getTopologicalOrder, getTypeInfo, hasCircularReferences, internalError, introspectSchema, introspectSchemas, invalidAssociationTargetError, invalidConfigError, invalidPropertyTypeError, isCompoundType, jsonSyntaxError, loadSchema, loadSchemas, mergePartialSchemas, missingConfigFieldError, missingFieldError, notImplementedError, outputWriteError, parseJsonSchema, parseYamlSchema, pluginError, pluginNotFoundError, pluginTypeConflictError, schemaNotFoundError, schemaParseError, schemasHaveFileProperties, validateAssociations, validateDefaultValue, validateEnumSchema, validateOptions, validateProperties, validatePropertyType, validateSchema, validateSchemas, validationError, yamlSyntaxError };
|
package/dist/index.js
CHANGED
|
@@ -844,7 +844,8 @@ async function findSchemaFiles(dirPath, extensions, recursive) {
|
|
|
844
844
|
async function loadSchemas(directoryPath, options = {}) {
|
|
845
845
|
const {
|
|
846
846
|
extensions = [".yaml", ".yml", ".json"],
|
|
847
|
-
recursive = true
|
|
847
|
+
recursive = true,
|
|
848
|
+
skipPartialResolution = false
|
|
848
849
|
} = options;
|
|
849
850
|
const absoluteDir = path.resolve(directoryPath);
|
|
850
851
|
try {
|
|
@@ -879,16 +880,35 @@ async function loadSchemas(directoryPath, options = {}) {
|
|
|
879
880
|
schemas[schema.name] = schema;
|
|
880
881
|
schemaLocations[schema.name] = filePath;
|
|
881
882
|
}
|
|
883
|
+
if (skipPartialResolution) {
|
|
884
|
+
for (const partial of partialSchemas) {
|
|
885
|
+
const partialKey = `__partial__${partial.name}`;
|
|
886
|
+
schemas[partialKey] = partial;
|
|
887
|
+
}
|
|
888
|
+
return schemas;
|
|
889
|
+
}
|
|
890
|
+
return mergePartialSchemas(schemas, partialSchemas);
|
|
891
|
+
}
|
|
892
|
+
function mergePartialSchemas(schemas, partials) {
|
|
893
|
+
const partialSchemas = partials ?? [];
|
|
894
|
+
const cleanSchemas = {};
|
|
895
|
+
for (const [key, schema] of Object.entries(schemas)) {
|
|
896
|
+
if (key.startsWith("__partial__")) {
|
|
897
|
+
partialSchemas.push(schema);
|
|
898
|
+
} else {
|
|
899
|
+
cleanSchemas[key] = schema;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
882
902
|
for (const partial of partialSchemas) {
|
|
883
903
|
const targetName = partial.target;
|
|
884
904
|
if (!targetName) {
|
|
885
905
|
console.warn(`Partial schema '${partial.name}' has no target, skipping`);
|
|
886
906
|
continue;
|
|
887
907
|
}
|
|
888
|
-
const target =
|
|
908
|
+
const target = cleanSchemas[targetName];
|
|
889
909
|
if (!target) {
|
|
890
910
|
if (partial.name === targetName) {
|
|
891
|
-
|
|
911
|
+
cleanSchemas[partial.name] = {
|
|
892
912
|
...partial,
|
|
893
913
|
kind: "object"
|
|
894
914
|
};
|
|
@@ -901,12 +921,12 @@ async function loadSchemas(directoryPath, options = {}) {
|
|
|
901
921
|
...partial.properties ?? {},
|
|
902
922
|
...target.properties ?? {}
|
|
903
923
|
};
|
|
904
|
-
|
|
924
|
+
cleanSchemas[targetName] = {
|
|
905
925
|
...target,
|
|
906
926
|
properties: mergedProperties
|
|
907
927
|
};
|
|
908
928
|
}
|
|
909
|
-
return
|
|
929
|
+
return cleanSchemas;
|
|
910
930
|
}
|
|
911
931
|
var FILE_SCHEMA_NAME = "File";
|
|
912
932
|
function schemasHaveFileProperties(schemas) {
|
|
@@ -2349,6 +2369,9 @@ function validateDefaultValue(typeName, value, property) {
|
|
|
2349
2369
|
|
|
2350
2370
|
// src/validation/validator.ts
|
|
2351
2371
|
var VALID_ID_TYPES = ["Int", "BigInt", "Uuid", "String"];
|
|
2372
|
+
function toSnakeCase(str) {
|
|
2373
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
2374
|
+
}
|
|
2352
2375
|
function buildLocation7(file, line, column) {
|
|
2353
2376
|
const loc = { file };
|
|
2354
2377
|
if (line !== void 0) {
|
|
@@ -2784,6 +2807,20 @@ function validateAssociations(schema, allSchemas) {
|
|
|
2784
2807
|
)
|
|
2785
2808
|
);
|
|
2786
2809
|
}
|
|
2810
|
+
if (relation === "ManyToOne" || relation === "OneToOne" && !assocProp.mappedBy) {
|
|
2811
|
+
const expectedFkColumn = `${toSnakeCase(name)}_id`;
|
|
2812
|
+
if (schema.properties[expectedFkColumn]) {
|
|
2813
|
+
errors.push(
|
|
2814
|
+
validationError(
|
|
2815
|
+
`Duplicate FK definition: Property '${expectedFkColumn}' conflicts with Association '${name}'`,
|
|
2816
|
+
buildLocation7(schema.filePath),
|
|
2817
|
+
`Both create the same column '${expectedFkColumn}'. Choose one approach:
|
|
2818
|
+
1. Use Association only (remove '${expectedFkColumn}' property) - recommended
|
|
2819
|
+
2. Use explicit FK only (remove '${name}' Association)`
|
|
2820
|
+
)
|
|
2821
|
+
);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2787
2824
|
}
|
|
2788
2825
|
return errors;
|
|
2789
2826
|
}
|
|
@@ -4656,6 +4693,7 @@ export {
|
|
|
4656
4693
|
jsonSyntaxError,
|
|
4657
4694
|
loadSchema,
|
|
4658
4695
|
loadSchemas,
|
|
4696
|
+
mergePartialSchemas,
|
|
4659
4697
|
missingConfigFieldError,
|
|
4660
4698
|
missingFieldError,
|
|
4661
4699
|
notImplementedError,
|