@maykonpaulo/maestro-core 0.6.0 → 0.7.0-next.0
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 +33 -1
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1040,6 +1040,38 @@ declare function detectDisplayField(fields: Array<{
|
|
|
1040
1040
|
isPrimaryKey: boolean;
|
|
1041
1041
|
}>): string | undefined;
|
|
1042
1042
|
|
|
1043
|
+
/**
|
|
1044
|
+
* Public structural validator for the `IntrospectionResult` contract. Accepts unknown/untrusted input
|
|
1045
|
+
* (e.g. a parsed JSON file) and checks it against the required (non-optional) fields of
|
|
1046
|
+
* `IntrospectionResult`/`EntityIntrospectionSchema`/`FieldIntrospectionSchema`/`RelationIntrospectionSchema`.
|
|
1047
|
+
* Optional derived fields (`isUnique`, `candidateForSearch`, `isTimestamp`, …) are not validated —
|
|
1048
|
+
* they pass through untouched when present.
|
|
1049
|
+
*/
|
|
1050
|
+
interface IntrospectionValidationIssue {
|
|
1051
|
+
/** Logical path of the offending field, e.g. `entities[0].fields[1].nullable`. */
|
|
1052
|
+
path: string;
|
|
1053
|
+
/** Human-readable reason, including expected vs. received type when applicable. */
|
|
1054
|
+
message: string;
|
|
1055
|
+
}
|
|
1056
|
+
interface IntrospectionValidationResult {
|
|
1057
|
+
valid: boolean;
|
|
1058
|
+
issues: IntrospectionValidationIssue[];
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Validates that an unknown value matches the `IntrospectionResult` contract closely enough to be
|
|
1062
|
+
* safely consumed downstream. Accumulates every issue found (rather than failing fast) so callers can
|
|
1063
|
+
* surface a complete, readable list of problems in one pass.
|
|
1064
|
+
*/
|
|
1065
|
+
declare function validateIntrospectionResult(value: unknown): IntrospectionValidationResult;
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
* Normalizes a valid `IntrospectionResult` into a deterministic, canonical form: entities sorted by
|
|
1069
|
+
* `table`, relations sorted by `id`. The internal order of `fields`/`indices` is preserved, since column
|
|
1070
|
+
* order is operationally meaningful. Never adds volatile data (timestamps, absolute paths, hashes) —
|
|
1071
|
+
* the same input always normalizes to the same output.
|
|
1072
|
+
*/
|
|
1073
|
+
declare function normalizeIntrospectionResult(result: IntrospectionResult): IntrospectionResult;
|
|
1074
|
+
|
|
1043
1075
|
interface GeneratedConfig {
|
|
1044
1076
|
entities: Record<string, EntitySchema>;
|
|
1045
1077
|
relations: Record<string, RelationSchema>;
|
|
@@ -1496,4 +1528,4 @@ declare class DefaultGovernanceApi implements GovernanceApi {
|
|
|
1496
1528
|
getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
|
|
1497
1529
|
}
|
|
1498
1530
|
|
|
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 };
|
|
1531
|
+
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 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 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, serializeDeclarativeConfig, serializeDeclarativeConfigToJson, serializeDeclarativeConfigToYaml, tableNameToEntityId, tableNameToLabel, validateConsumerDeclaration, validateEntityDeclaration, validateIntrospectionResult, validateMaestroConfig };
|
package/dist/index.js
CHANGED
|
@@ -2515,6 +2515,115 @@ 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
|
+
|
|
2518
2627
|
// src/config-generator/ConfigGenerator.ts
|
|
2519
2628
|
function detectSoftDelete2(fields) {
|
|
2520
2629
|
const PRIORITY = [
|
|
@@ -3710,6 +3819,7 @@ export {
|
|
|
3710
3819
|
loadDeclarativeConfigFromString,
|
|
3711
3820
|
loadMaestroConfig,
|
|
3712
3821
|
mergeIntrospectionWithOverrides,
|
|
3822
|
+
normalizeIntrospectionResult,
|
|
3713
3823
|
parseQueryInput,
|
|
3714
3824
|
resolveConsumerProjections,
|
|
3715
3825
|
serializeDeclarativeConfig,
|
|
@@ -3719,6 +3829,7 @@ export {
|
|
|
3719
3829
|
tableNameToLabel,
|
|
3720
3830
|
validateConsumerDeclaration,
|
|
3721
3831
|
validateEntityDeclaration,
|
|
3832
|
+
validateIntrospectionResult,
|
|
3722
3833
|
validateMaestroConfig
|
|
3723
3834
|
};
|
|
3724
3835
|
//# sourceMappingURL=index.js.map
|