@maykonpaulo/maestro-core 0.6.0 → 0.7.0-next.1
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.d.ts +68 -2
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -909,8 +909,29 @@ interface IntrospectionResult {
|
|
|
909
909
|
relations: RelationIntrospectionSchema[];
|
|
910
910
|
}
|
|
911
911
|
|
|
912
|
+
/**
|
|
913
|
+
* Execution context passed to an `IntrospectionProvider`. Intentionally generic and provider-agnostic:
|
|
914
|
+
* it carries cross-cutting concerns (who triggered the run, how to log, how to cancel) but never
|
|
915
|
+
* datasource-specific detail. Connection strings, hosts, ports, schemas, credentials and ORM/driver
|
|
916
|
+
* clients belong to the concrete provider's own constructor/options, not to this shared contract.
|
|
917
|
+
*/
|
|
918
|
+
interface IntrospectionContext {
|
|
919
|
+
correlationId?: string;
|
|
920
|
+
actor?: Actor;
|
|
921
|
+
metadata?: Metadata;
|
|
922
|
+
logger?: Logger;
|
|
923
|
+
signal?: AbortSignal;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Contract implemented by external adapters that discover the structure of a system or data source
|
|
928
|
+
* and report it back as an `IntrospectionResult`. The core only defines and executes this contract —
|
|
929
|
+
* it never implements a concrete provider (no database connection, driver or ORM).
|
|
930
|
+
*/
|
|
912
931
|
interface IntrospectionProvider {
|
|
913
|
-
|
|
932
|
+
/** Identifies the provider in logs and error messages, e.g. "postgres", "fake-in-memory". */
|
|
933
|
+
readonly name?: string;
|
|
934
|
+
introspect(context?: IntrospectionContext): Promise<IntrospectionResult> | IntrospectionResult;
|
|
914
935
|
}
|
|
915
936
|
|
|
916
937
|
interface YamlParser {
|
|
@@ -1040,6 +1061,51 @@ declare function detectDisplayField(fields: Array<{
|
|
|
1040
1061
|
isPrimaryKey: boolean;
|
|
1041
1062
|
}>): string | undefined;
|
|
1042
1063
|
|
|
1064
|
+
/**
|
|
1065
|
+
* Public structural validator for the `IntrospectionResult` contract. Accepts unknown/untrusted input
|
|
1066
|
+
* (e.g. a parsed JSON file) and checks it against the required (non-optional) fields of
|
|
1067
|
+
* `IntrospectionResult`/`EntityIntrospectionSchema`/`FieldIntrospectionSchema`/`RelationIntrospectionSchema`.
|
|
1068
|
+
* Optional derived fields (`isUnique`, `candidateForSearch`, `isTimestamp`, …) are not validated —
|
|
1069
|
+
* they pass through untouched when present.
|
|
1070
|
+
*/
|
|
1071
|
+
interface IntrospectionValidationIssue {
|
|
1072
|
+
/** Logical path of the offending field, e.g. `entities[0].fields[1].nullable`. */
|
|
1073
|
+
path: string;
|
|
1074
|
+
/** Human-readable reason, including expected vs. received type when applicable. */
|
|
1075
|
+
message: string;
|
|
1076
|
+
}
|
|
1077
|
+
interface IntrospectionValidationResult {
|
|
1078
|
+
valid: boolean;
|
|
1079
|
+
issues: IntrospectionValidationIssue[];
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Validates that an unknown value matches the `IntrospectionResult` contract closely enough to be
|
|
1083
|
+
* safely consumed downstream. Accumulates every issue found (rather than failing fast) so callers can
|
|
1084
|
+
* surface a complete, readable list of problems in one pass.
|
|
1085
|
+
*/
|
|
1086
|
+
declare function validateIntrospectionResult(value: unknown): IntrospectionValidationResult;
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Normalizes a valid `IntrospectionResult` into a deterministic, canonical form: entities sorted by
|
|
1090
|
+
* `table`, relations sorted by `id`. The internal order of `fields`/`indices` is preserved, since column
|
|
1091
|
+
* order is operationally meaningful. Never adds volatile data (timestamps, absolute paths, hashes) —
|
|
1092
|
+
* the same input always normalizes to the same output.
|
|
1093
|
+
*/
|
|
1094
|
+
declare function normalizeIntrospectionResult(result: IntrospectionResult): IntrospectionResult;
|
|
1095
|
+
|
|
1096
|
+
interface RunIntrospectionResult {
|
|
1097
|
+
/** The provider's `name`, or `"unknown"` when the provider does not declare one. */
|
|
1098
|
+
provider: string;
|
|
1099
|
+
result: IntrospectionResult;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Runs an `IntrospectionProvider`, then validates and normalizes its output before returning it. This
|
|
1103
|
+
* is the only sanctioned way to consume a provider's result: a provider can never hand back a
|
|
1104
|
+
* structurally invalid `IntrospectionResult` silently — `validateIntrospectionResult` failures and
|
|
1105
|
+
* provider exceptions both surface as a `MaestroError`.
|
|
1106
|
+
*/
|
|
1107
|
+
declare function runIntrospectionProvider(provider: IntrospectionProvider, context?: IntrospectionContext): Promise<RunIntrospectionResult>;
|
|
1108
|
+
|
|
1043
1109
|
interface GeneratedConfig {
|
|
1044
1110
|
entities: Record<string, EntitySchema>;
|
|
1045
1111
|
relations: Record<string, RelationSchema>;
|
|
@@ -1496,4 +1562,4 @@ declare class DefaultGovernanceApi implements GovernanceApi {
|
|
|
1496
1562
|
getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
|
|
1497
1563
|
}
|
|
1498
1564
|
|
|
1499
|
-
export { type Actor, type ActorType, type AuditEvent, type AuditFilter, type AuditLevel, type AuditRecordedPayload, AuditRecorder, type AuditRepository, type AuditTimeline, type AuthorizationContext, type AuthorizationDecision, type AuthorizationDeniedPayload, type AuthorizationProvider, type AuthorizationResult, type CompileDeclarationsOptions, type ConfigProvider, type ConfirmationApproval, type ConfirmationApprovedPayload, type ConfirmationDeclaration, ConfirmationEngine, type ConfirmationRejectedPayload, type ConfirmationRepository, type ConfirmationRequest, type ConfirmationRequestedPayload, type ConfirmationStatus, ConsoleLogger, ConsoleStructuredLogger, type ConsumerActionsConfig, type ConsumerDeclaration, type ConsumerDetailConfig, type ConsumerFormConfig, type ConsumerFormsConfig, type ConsumerListConfig, type ConsumerProjectionFields, type ConsumerProjectionOperations, type ContextAction, type ContextActionCondition, type ContextActionStyle, ContextualAuthorizationEngine, type CorrelationContext, type CorrelationId, type CreateMaestroFromIntrospectionOptions, CsvExportProvider, type CursorPagination, DEFAULT_CAPABILITIES, type DatasourceDeleteContext, type DatasourceFindContext, type DatasourceProvider, type DatasourceQueryContext, DatasourceRegistry, type DatasourceUpdateContext, type DatasourceWriteContext, type DeclarativeCompilationResult, type DeclarativeConfig, type DeclarativeFileConfig, type DeclarativeFileFormat, type DeclarativeGeneratorMetadataInput, type DeclarativeGeneratorOptions, type DeclarativeGeneratorSchemaInput, type DeclarativeSerializationFormat, DefaultGovernanceApi, type DiffChange, type DiffChangeKind, DiffEngine, type DiffEngineOptions, type DiffSummary, type DomainEvent, type EntityCapabilities, type EntityDeclaration, type EntityDiffChange, type EntityDiffChangeKind, type EntityExportConfig, type EntityIntrospectionSchema, type EntityLabelConfig, type EntityMetadata, type EntitySchema, type EntitySourceConfig, type EnumOption, type EnumOptionDeclaration, ErrorCode, type EventBus, type EventHandler, type ExportConfig, type ExportFormat, type ExportOptions, type ExportProvider, type ExportResult, type FeatureFlag, type FeatureFlagProvider, type FieldDeclaration, type FieldDetailConfig, type FieldDiffChange, type FieldDiffChangeKind, type FieldFormConfig, type FieldIntrospectionSchema, type FieldListConfig, type FieldMetadata, type FieldSchema, type FieldSchemaDetailConfig, type FieldSchemaEnumOption, type FieldSchemaFormConfig, type FieldSchemaListConfig, type FieldType, type FileSystemReader, type FilterDescriptor, type FilterOperator, GOVERNANCE_EVENT_TYPES, type GeneratedConfig, type GovernanceApi, type GovernanceEventBus, type GovernanceEventType, type ImpactLevel, InMemoryAuditRepository, InMemoryConfigProvider, InMemoryConfirmationRepository, InMemoryDatasourceProvider, InMemoryEventBus, InMemoryFeatureFlagProvider, InMemoryGovernanceEventBus, InMemoryPolicyProvider, InMemorySnapshotRepository, type IndexIntrospectionSchema, type IntrospectionDiff, type IntrospectionProvider, type IntrospectionReport, type IntrospectionReportChange, type IntrospectionReportStats, type IntrospectionResult, IntrospectionRuntime, type IntrospectionRuntimeResult, type IntrospectionRuntimeRunOptions, type IntrospectionSnapshot, type ListResult, type LoadDeclarativeConfigFromFileOptions, type LoadDeclarativeConfigFromStringOptions, type LoadedConfig, type LogEntry, type LogLevel, type Logger, type MaestroActorResolver, type MaestroConfig, MaestroEngine, MaestroError, type MaestroFileLoaderOptions, type MaestroHttpHandler, type MaestroHttpHandlers, type MaestroHttpOptions, type MaestroHttpRequest, type MaestroHttpResponse, type MaestroMetadata, type MaestroRequestContext, type MergeIntrospectionOptions, type MergeStrategy, type Metadata, MetadataEngine, MetadataRiskClassifier, type MetadataValue, type OffsetPagination, type OperationContext, type OperationDeclaration, type OperationDef, type OperationExecutedPayload, type OperationLogStatus, type OperationMetadata, OperationRegistry, type OperationResult, type OperationScope, type OperationalRisk, type PagePagination, type PaginationInput, type Permission, type PolicyContext, type PolicyDecision, PolicyEngine, type PolicyEvaluationResult, type PolicyProvider, type PolicyRule, type PolicyRuleResult, type PolicyTriggeredPayload, type PolicyViolation, type PolicyViolationFilter, type QueryInput, RbacEngine, type RbacPolicy, type RecordAuditInput, type RelationDeclaration, type RelationDiffChange, type RelationDiffChangeKind, type RelationDisplayConfig, type RelationEndpoint, type RelationIntrospectionSchema, type RelationMetadata, type RelationSchema, type RelationType, ReportGenerator, type RequestConfirmationInput, type ResolvedConsumerProjection, type ResourceRef, type RiskClassificationInput, type RiskClassifier, type Role, type SchemaValidationError, type SchemaValidationResult, type SearchConfig, type SearchInput, type SerializeDeclarativeConfigOptions, type SnapshotRepository, type SoftDeleteConfig, type SortDescriptor, type SortDirection, type StructuredLogEntry, type StructuredLogger, type YamlParser, type YamlSerializer, compileDeclarations, createMaestro, createMaestroFromIntrospection, createMaestroHttpHandlers, detectDisplayField, generateAllConfigs, generateCorrelationId, generateDeclarativeConfigFromMetadata, generateDeclarativeConfigFromSchema, generateEntityConfig, generateRelationConfig, humanizeFieldName, inferFieldType, isSearchCandidate, isSoftDeleteCandidate, isTimestampField, loadDeclarativeConfigFromFile, loadDeclarativeConfigFromString, loadMaestroConfig, mergeIntrospectionWithOverrides, parseQueryInput, resolveConsumerProjections, serializeDeclarativeConfig, serializeDeclarativeConfigToJson, serializeDeclarativeConfigToYaml, tableNameToEntityId, tableNameToLabel, validateConsumerDeclaration, validateEntityDeclaration, validateMaestroConfig };
|
|
1565
|
+
export { type Actor, type ActorType, type AuditEvent, type AuditFilter, type AuditLevel, type AuditRecordedPayload, AuditRecorder, type AuditRepository, type AuditTimeline, type AuthorizationContext, type AuthorizationDecision, type AuthorizationDeniedPayload, type AuthorizationProvider, type AuthorizationResult, type CompileDeclarationsOptions, type ConfigProvider, type ConfirmationApproval, type ConfirmationApprovedPayload, type ConfirmationDeclaration, ConfirmationEngine, type ConfirmationRejectedPayload, type ConfirmationRepository, type ConfirmationRequest, type ConfirmationRequestedPayload, type ConfirmationStatus, ConsoleLogger, ConsoleStructuredLogger, type ConsumerActionsConfig, type ConsumerDeclaration, type ConsumerDetailConfig, type ConsumerFormConfig, type ConsumerFormsConfig, type ConsumerListConfig, type ConsumerProjectionFields, type ConsumerProjectionOperations, type ContextAction, type ContextActionCondition, type ContextActionStyle, ContextualAuthorizationEngine, type CorrelationContext, type CorrelationId, type CreateMaestroFromIntrospectionOptions, CsvExportProvider, type CursorPagination, DEFAULT_CAPABILITIES, type DatasourceDeleteContext, type DatasourceFindContext, type DatasourceProvider, type DatasourceQueryContext, DatasourceRegistry, type DatasourceUpdateContext, type DatasourceWriteContext, type DeclarativeCompilationResult, type DeclarativeConfig, type DeclarativeFileConfig, type DeclarativeFileFormat, type DeclarativeGeneratorMetadataInput, type DeclarativeGeneratorOptions, type DeclarativeGeneratorSchemaInput, type DeclarativeSerializationFormat, DefaultGovernanceApi, type DiffChange, type DiffChangeKind, DiffEngine, type DiffEngineOptions, type DiffSummary, type DomainEvent, type EntityCapabilities, type EntityDeclaration, type EntityDiffChange, type EntityDiffChangeKind, type EntityExportConfig, type EntityIntrospectionSchema, type EntityLabelConfig, type EntityMetadata, type EntitySchema, type EntitySourceConfig, type EnumOption, type EnumOptionDeclaration, ErrorCode, type EventBus, type EventHandler, type ExportConfig, type ExportFormat, type ExportOptions, type ExportProvider, type ExportResult, type FeatureFlag, type FeatureFlagProvider, type FieldDeclaration, type FieldDetailConfig, type FieldDiffChange, type FieldDiffChangeKind, type FieldFormConfig, type FieldIntrospectionSchema, type FieldListConfig, type FieldMetadata, type FieldSchema, type FieldSchemaDetailConfig, type FieldSchemaEnumOption, type FieldSchemaFormConfig, type FieldSchemaListConfig, type FieldType, type FileSystemReader, type FilterDescriptor, type FilterOperator, GOVERNANCE_EVENT_TYPES, type GeneratedConfig, type GovernanceApi, type GovernanceEventBus, type GovernanceEventType, type ImpactLevel, InMemoryAuditRepository, InMemoryConfigProvider, InMemoryConfirmationRepository, InMemoryDatasourceProvider, InMemoryEventBus, InMemoryFeatureFlagProvider, InMemoryGovernanceEventBus, InMemoryPolicyProvider, InMemorySnapshotRepository, type IndexIntrospectionSchema, type IntrospectionContext, type IntrospectionDiff, type IntrospectionProvider, type IntrospectionReport, type IntrospectionReportChange, type IntrospectionReportStats, type IntrospectionResult, IntrospectionRuntime, type IntrospectionRuntimeResult, type IntrospectionRuntimeRunOptions, type IntrospectionSnapshot, type IntrospectionValidationIssue, type IntrospectionValidationResult, type ListResult, type LoadDeclarativeConfigFromFileOptions, type LoadDeclarativeConfigFromStringOptions, type LoadedConfig, type LogEntry, type LogLevel, type Logger, type MaestroActorResolver, type MaestroConfig, MaestroEngine, MaestroError, type MaestroFileLoaderOptions, type MaestroHttpHandler, type MaestroHttpHandlers, type MaestroHttpOptions, type MaestroHttpRequest, type MaestroHttpResponse, type MaestroMetadata, type MaestroRequestContext, type MergeIntrospectionOptions, type MergeStrategy, type Metadata, MetadataEngine, MetadataRiskClassifier, type MetadataValue, type OffsetPagination, type OperationContext, type OperationDeclaration, type OperationDef, type OperationExecutedPayload, type OperationLogStatus, type OperationMetadata, OperationRegistry, type OperationResult, type OperationScope, type OperationalRisk, type PagePagination, type PaginationInput, type Permission, type PolicyContext, type PolicyDecision, PolicyEngine, type PolicyEvaluationResult, type PolicyProvider, type PolicyRule, type PolicyRuleResult, type PolicyTriggeredPayload, type PolicyViolation, type PolicyViolationFilter, type QueryInput, RbacEngine, type RbacPolicy, type RecordAuditInput, type RelationDeclaration, type RelationDiffChange, type RelationDiffChangeKind, type RelationDisplayConfig, type RelationEndpoint, type RelationIntrospectionSchema, type RelationMetadata, type RelationSchema, type RelationType, ReportGenerator, type RequestConfirmationInput, type ResolvedConsumerProjection, type ResourceRef, type RiskClassificationInput, type RiskClassifier, type Role, type RunIntrospectionResult, type SchemaValidationError, type SchemaValidationResult, type SearchConfig, type SearchInput, type SerializeDeclarativeConfigOptions, type SnapshotRepository, type SoftDeleteConfig, type SortDescriptor, type SortDirection, type StructuredLogEntry, type StructuredLogger, type YamlParser, type YamlSerializer, compileDeclarations, createMaestro, createMaestroFromIntrospection, createMaestroHttpHandlers, detectDisplayField, generateAllConfigs, generateCorrelationId, generateDeclarativeConfigFromMetadata, generateDeclarativeConfigFromSchema, generateEntityConfig, generateRelationConfig, humanizeFieldName, inferFieldType, isSearchCandidate, isSoftDeleteCandidate, isTimestampField, loadDeclarativeConfigFromFile, loadDeclarativeConfigFromString, loadMaestroConfig, mergeIntrospectionWithOverrides, normalizeIntrospectionResult, parseQueryInput, resolveConsumerProjections, runIntrospectionProvider, serializeDeclarativeConfig, serializeDeclarativeConfigToJson, serializeDeclarativeConfigToYaml, tableNameToEntityId, tableNameToLabel, validateConsumerDeclaration, validateEntityDeclaration, validateIntrospectionResult, validateMaestroConfig };
|
package/dist/index.js
CHANGED
|
@@ -2515,6 +2515,147 @@ async function loadMaestroConfig(options) {
|
|
|
2515
2515
|
};
|
|
2516
2516
|
}
|
|
2517
2517
|
|
|
2518
|
+
// src/introspection/IntrospectionValidator.ts
|
|
2519
|
+
function isObject(value) {
|
|
2520
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2521
|
+
}
|
|
2522
|
+
function nonEmptyString(value) {
|
|
2523
|
+
return typeof value === "string" && value.length > 0;
|
|
2524
|
+
}
|
|
2525
|
+
function typeOf(value) {
|
|
2526
|
+
if (value === null) return "null";
|
|
2527
|
+
if (Array.isArray(value)) return "array";
|
|
2528
|
+
return typeof value;
|
|
2529
|
+
}
|
|
2530
|
+
function reject(issues, path, expected, received) {
|
|
2531
|
+
issues.push({ path, message: `expected ${expected}, received ${typeOf(received)}.` });
|
|
2532
|
+
}
|
|
2533
|
+
function validateEndpoint(endpoint, path, issues) {
|
|
2534
|
+
if (!isObject(endpoint)) {
|
|
2535
|
+
reject(issues, path, 'an object with "table" and "field"', endpoint);
|
|
2536
|
+
return;
|
|
2537
|
+
}
|
|
2538
|
+
if (!nonEmptyString(endpoint["table"])) {
|
|
2539
|
+
reject(issues, `${path}.table`, "a non-empty string", endpoint["table"]);
|
|
2540
|
+
}
|
|
2541
|
+
if (!nonEmptyString(endpoint["field"])) {
|
|
2542
|
+
reject(issues, `${path}.field`, "a non-empty string", endpoint["field"]);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
function validateField(entityIndex, fieldIndex, field, issues) {
|
|
2546
|
+
const path = `entities[${entityIndex}].fields[${fieldIndex}]`;
|
|
2547
|
+
if (!isObject(field)) {
|
|
2548
|
+
reject(issues, path, "an object", field);
|
|
2549
|
+
return;
|
|
2550
|
+
}
|
|
2551
|
+
if (!nonEmptyString(field["name"])) reject(issues, `${path}.name`, "a non-empty string", field["name"]);
|
|
2552
|
+
if (typeof field["nativeType"] !== "string") reject(issues, `${path}.nativeType`, "a string", field["nativeType"]);
|
|
2553
|
+
if (typeof field["type"] !== "string") reject(issues, `${path}.type`, "a string", field["type"]);
|
|
2554
|
+
if (typeof field["nullable"] !== "boolean") reject(issues, `${path}.nullable`, "a boolean", field["nullable"]);
|
|
2555
|
+
if (typeof field["isPrimaryKey"] !== "boolean") {
|
|
2556
|
+
reject(issues, `${path}.isPrimaryKey`, "a boolean", field["isPrimaryKey"]);
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
function validateEntity2(index, entity, issues) {
|
|
2560
|
+
const path = `entities[${index}]`;
|
|
2561
|
+
if (!isObject(entity)) {
|
|
2562
|
+
reject(issues, path, "an object", entity);
|
|
2563
|
+
return;
|
|
2564
|
+
}
|
|
2565
|
+
if (!nonEmptyString(entity["table"])) reject(issues, `${path}.table`, "a non-empty string", entity["table"]);
|
|
2566
|
+
if (!Array.isArray(entity["fields"])) {
|
|
2567
|
+
reject(issues, `${path}.fields`, "an array", entity["fields"]);
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
const fields = entity["fields"];
|
|
2571
|
+
for (let j = 0; j < fields.length; j++) {
|
|
2572
|
+
validateField(index, j, fields[j], issues);
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
function validateRelation2(index, relation, issues) {
|
|
2576
|
+
const path = `relations[${index}]`;
|
|
2577
|
+
if (!isObject(relation)) {
|
|
2578
|
+
reject(issues, path, "an object", relation);
|
|
2579
|
+
return;
|
|
2580
|
+
}
|
|
2581
|
+
if (!nonEmptyString(relation["id"])) reject(issues, `${path}.id`, "a non-empty string", relation["id"]);
|
|
2582
|
+
if (typeof relation["type"] !== "string") reject(issues, `${path}.type`, "a string", relation["type"]);
|
|
2583
|
+
validateEndpoint(relation["from"], `${path}.from`, issues);
|
|
2584
|
+
validateEndpoint(relation["to"], `${path}.to`, issues);
|
|
2585
|
+
if (relation["confidence"] !== "definite" && relation["confidence"] !== "inferred") {
|
|
2586
|
+
issues.push({
|
|
2587
|
+
path: `${path}.confidence`,
|
|
2588
|
+
message: `expected "definite" or "inferred", received ${JSON.stringify(relation["confidence"])}.`
|
|
2589
|
+
});
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
function validateIntrospectionResult(value) {
|
|
2593
|
+
const issues = [];
|
|
2594
|
+
if (!isObject(value)) {
|
|
2595
|
+
reject(issues, "", 'an object with "entities" and "relations" arrays', value);
|
|
2596
|
+
return { valid: false, issues };
|
|
2597
|
+
}
|
|
2598
|
+
if (!Array.isArray(value["entities"])) {
|
|
2599
|
+
reject(issues, "entities", "an array", value["entities"]);
|
|
2600
|
+
} else {
|
|
2601
|
+
const entities = value["entities"];
|
|
2602
|
+
for (let i = 0; i < entities.length; i++) {
|
|
2603
|
+
validateEntity2(i, entities[i], issues);
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
if (!Array.isArray(value["relations"])) {
|
|
2607
|
+
reject(issues, "relations", "an array", value["relations"]);
|
|
2608
|
+
} else {
|
|
2609
|
+
const relations = value["relations"];
|
|
2610
|
+
for (let i = 0; i < relations.length; i++) {
|
|
2611
|
+
validateRelation2(i, relations[i], issues);
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
return { valid: issues.length === 0, issues };
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
// src/introspection/IntrospectionNormalizer.ts
|
|
2618
|
+
function compareStrings(a, b) {
|
|
2619
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
2620
|
+
}
|
|
2621
|
+
function normalizeIntrospectionResult(result) {
|
|
2622
|
+
const entities = [...result.entities].sort((a, b) => compareStrings(a.table, b.table));
|
|
2623
|
+
const relations = [...result.relations].sort((a, b) => compareStrings(a.id, b.id));
|
|
2624
|
+
return { entities, relations };
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
// src/introspection/runIntrospectionProvider.ts
|
|
2628
|
+
function errorMessage(error) {
|
|
2629
|
+
return error instanceof Error ? error.message : String(error);
|
|
2630
|
+
}
|
|
2631
|
+
async function runIntrospectionProvider(provider, context) {
|
|
2632
|
+
const providerName = provider.name ?? "unknown";
|
|
2633
|
+
let raw;
|
|
2634
|
+
try {
|
|
2635
|
+
raw = await provider.introspect(context);
|
|
2636
|
+
} catch (cause) {
|
|
2637
|
+
throw new MaestroError(
|
|
2638
|
+
"INTERNAL_ERROR" /* INTERNAL_ERROR */,
|
|
2639
|
+
`Introspection provider "${providerName}" threw during introspect(): ${errorMessage(cause)}`,
|
|
2640
|
+
{ details: { provider: providerName }, cause }
|
|
2641
|
+
);
|
|
2642
|
+
}
|
|
2643
|
+
const validation = validateIntrospectionResult(raw);
|
|
2644
|
+
if (!validation.valid) {
|
|
2645
|
+
const issueSummary = validation.issues.map((issue) => `${issue.path}: ${issue.message}`).join("; ");
|
|
2646
|
+
const details = {
|
|
2647
|
+
provider: providerName,
|
|
2648
|
+
issues: validation.issues.map((issue) => ({ path: issue.path, message: issue.message }))
|
|
2649
|
+
};
|
|
2650
|
+
throw new MaestroError(
|
|
2651
|
+
"VALIDATION_ERROR" /* VALIDATION_ERROR */,
|
|
2652
|
+
`Introspection provider "${providerName}" returned an invalid IntrospectionResult: ${issueSummary}`,
|
|
2653
|
+
{ details }
|
|
2654
|
+
);
|
|
2655
|
+
}
|
|
2656
|
+
return { provider: providerName, result: normalizeIntrospectionResult(raw) };
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2518
2659
|
// src/config-generator/ConfigGenerator.ts
|
|
2519
2660
|
function detectSoftDelete2(fields) {
|
|
2520
2661
|
const PRIORITY = [
|
|
@@ -3710,8 +3851,10 @@ export {
|
|
|
3710
3851
|
loadDeclarativeConfigFromString,
|
|
3711
3852
|
loadMaestroConfig,
|
|
3712
3853
|
mergeIntrospectionWithOverrides,
|
|
3854
|
+
normalizeIntrospectionResult,
|
|
3713
3855
|
parseQueryInput,
|
|
3714
3856
|
resolveConsumerProjections,
|
|
3857
|
+
runIntrospectionProvider,
|
|
3715
3858
|
serializeDeclarativeConfig,
|
|
3716
3859
|
serializeDeclarativeConfigToJson,
|
|
3717
3860
|
serializeDeclarativeConfigToYaml,
|
|
@@ -3719,6 +3862,7 @@ export {
|
|
|
3719
3862
|
tableNameToLabel,
|
|
3720
3863
|
validateConsumerDeclaration,
|
|
3721
3864
|
validateEntityDeclaration,
|
|
3865
|
+
validateIntrospectionResult,
|
|
3722
3866
|
validateMaestroConfig
|
|
3723
3867
|
};
|
|
3724
3868
|
//# sourceMappingURL=index.js.map
|