@maykonpaulo/maestro-core 0.3.0-next.1 → 0.3.0-next.3

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 CHANGED
@@ -632,14 +632,121 @@ interface RelationSchema {
632
632
  display?: RelationDisplayConfig;
633
633
  }
634
634
 
635
+ type OperationalRisk = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
636
+
637
+ interface RiskClassificationInput {
638
+ operation: string;
639
+ resource?: ResourceRef;
640
+ metadata?: Metadata;
641
+ }
642
+ interface RiskClassifier {
643
+ classify(input: RiskClassificationInput): OperationalRisk;
644
+ }
645
+
646
+ declare class MetadataRiskClassifier implements RiskClassifier {
647
+ private readonly operationRiskMap;
648
+ private readonly defaultRisk;
649
+ constructor(operationRiskMap?: Record<string, OperationalRisk>, defaultRisk?: OperationalRisk);
650
+ classify(input: RiskClassificationInput): OperationalRisk;
651
+ }
652
+
653
+ interface FieldDeclaration {
654
+ type: FieldType;
655
+ label?: string;
656
+ required?: boolean;
657
+ readonly?: boolean;
658
+ primary?: boolean;
659
+ sensitive?: boolean;
660
+ visible?: boolean;
661
+ searchable?: boolean;
662
+ sortable?: boolean;
663
+ filterable?: boolean;
664
+ exportable?: boolean;
665
+ description?: string;
666
+ }
667
+ interface ConfirmationDeclaration {
668
+ required: boolean;
669
+ approvers?: number;
670
+ }
671
+ interface OperationDeclaration {
672
+ label: string;
673
+ description?: string;
674
+ scope?: OperationScope;
675
+ risk?: OperationalRisk;
676
+ audit?: boolean;
677
+ confirmation?: ConfirmationDeclaration;
678
+ permission?: string;
679
+ }
680
+ interface EntityDeclaration {
681
+ entity: string;
682
+ /** Human-readable singular label (e.g. "User"). */
683
+ label?: string;
684
+ /** Human-readable plural label (e.g. "Users"). Defaults to `label` when absent. */
685
+ pluralLabel?: string;
686
+ description?: string;
687
+ fields: Record<string, FieldDeclaration>;
688
+ operations?: Record<string, OperationDeclaration>;
689
+ }
690
+
691
+ interface ConsumerListConfig {
692
+ fields?: string[];
693
+ }
694
+ interface ConsumerDetailConfig {
695
+ fields?: string[];
696
+ }
697
+ interface ConsumerFormConfig {
698
+ fields?: string[];
699
+ }
700
+ interface ConsumerFormsConfig {
701
+ create?: ConsumerFormConfig;
702
+ update?: ConsumerFormConfig;
703
+ clone?: ConsumerFormConfig;
704
+ }
705
+ interface ConsumerActionsConfig {
706
+ row?: string[];
707
+ bulk?: string[];
708
+ global?: string[];
709
+ }
710
+ interface ConsumerDeclaration {
711
+ consumer: string;
712
+ entity: string;
713
+ list?: ConsumerListConfig;
714
+ detail?: ConsumerDetailConfig;
715
+ forms?: ConsumerFormsConfig;
716
+ actions?: ConsumerActionsConfig;
717
+ }
718
+
719
+ interface DeclarativeConfig {
720
+ entities: EntityDeclaration[];
721
+ consumers?: ConsumerDeclaration[];
722
+ /**
723
+ * Datasource ID to use for all declared entities that don't specify one.
724
+ * Required when more than one datasource is configured in the engine.
725
+ * When only one datasource is configured, it is used automatically.
726
+ */
727
+ defaultDatasource?: string;
728
+ }
729
+
635
730
  interface MaestroConfig {
636
731
  datasources: Record<string, DatasourceProvider>;
637
- entities: EntitySchema[];
732
+ /**
733
+ * Entities defined using the low-level EntitySchema format.
734
+ * Can be combined with `declarations.entities` or used alone.
735
+ * Required when `declarations` is not provided.
736
+ */
737
+ entities?: EntitySchema[];
638
738
  relations?: RelationSchema[];
639
739
  operations?: OperationDef[];
640
740
  policies?: RbacPolicy;
641
741
  audit?: AuditRepository;
642
742
  logger?: Logger;
743
+ /**
744
+ * Declarative entity and consumer definitions.
745
+ * Entities declared here are compiled to EntitySchema and merged with `entities`.
746
+ * Operations declared here are registered as stubs; provide real implementations in `operations`.
747
+ * Required when `entities` is not provided.
748
+ */
749
+ declarations?: DeclarativeConfig;
643
750
  }
644
751
 
645
752
  interface SchemaValidationError {
@@ -668,14 +775,49 @@ interface ExportResult {
668
775
  mimeType: string;
669
776
  }
670
777
 
778
+ interface ConsumerProjectionFields {
779
+ list: FieldMetadata[];
780
+ detail: FieldMetadata[];
781
+ create: FieldMetadata[];
782
+ update: FieldMetadata[];
783
+ clone: FieldMetadata[];
784
+ }
785
+ interface ConsumerProjectionOperations {
786
+ row: OperationMetadata[];
787
+ bulk: OperationMetadata[];
788
+ global: OperationMetadata[];
789
+ }
790
+ /**
791
+ * A resolved, runtime projection of a ConsumerDeclaration against a compiled EntityMetadata.
792
+ * Contains FieldMetadata and OperationMetadata objects — not raw names — ready for consumption
793
+ * by UI, API, or CLI layers.
794
+ */
795
+ interface ResolvedConsumerProjection {
796
+ consumer: string;
797
+ entity: string;
798
+ fields: ConsumerProjectionFields;
799
+ operations: ConsumerProjectionOperations;
800
+ }
801
+
671
802
  declare class MaestroEngine {
672
803
  private readonly metadata;
673
804
  private readonly datasources;
674
805
  private readonly operations;
675
806
  private readonly audit?;
676
807
  private readonly rbac;
677
- constructor(metadata: MaestroMetadata, datasources: DatasourceRegistry, operations: OperationRegistry, audit?: AuditRecorder | undefined);
808
+ private readonly consumerMap;
809
+ constructor(metadata: MaestroMetadata, datasources: DatasourceRegistry, operations: OperationRegistry, audit?: AuditRecorder | undefined, consumers?: ResolvedConsumerProjection[]);
678
810
  getMetadata(): MaestroMetadata;
811
+ /**
812
+ * Returns the resolved consumer projection for the given consumer ID, or undefined if not found.
813
+ * Each call returns an independent copy — mutations to the returned object do not affect internal state.
814
+ * Consumer projections are only available when declarations.consumers were provided to createMaestro().
815
+ */
816
+ getConsumer(consumerId: string): ResolvedConsumerProjection | undefined;
817
+ /**
818
+ * Returns the IDs of all registered consumer projections.
819
+ */
820
+ listConsumers(): string[];
679
821
  list(entityId: string, query: QueryInput, actor: Actor): Promise<ListResult<Record<string, unknown>>>;
680
822
  findById(entityId: string, id: string, actor: Actor): Promise<Record<string, unknown> | null>;
681
823
  create(entityId: string, data: Record<string, unknown>, actor: Actor): Promise<Record<string, unknown>>;
@@ -1019,24 +1161,6 @@ interface CorrelationContext {
1019
1161
  correlationId: CorrelationId;
1020
1162
  }
1021
1163
 
1022
- type OperationalRisk = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
1023
-
1024
- interface RiskClassificationInput {
1025
- operation: string;
1026
- resource?: ResourceRef;
1027
- metadata?: Metadata;
1028
- }
1029
- interface RiskClassifier {
1030
- classify(input: RiskClassificationInput): OperationalRisk;
1031
- }
1032
-
1033
- declare class MetadataRiskClassifier implements RiskClassifier {
1034
- private readonly operationRiskMap;
1035
- private readonly defaultRisk;
1036
- constructor(operationRiskMap?: Record<string, OperationalRisk>, defaultRisk?: OperationalRisk);
1037
- classify(input: RiskClassificationInput): OperationalRisk;
1038
- }
1039
-
1040
1164
  type AuthorizationDecision = 'ALLOW' | 'DENY' | 'REQUIRES_CONFIRMATION';
1041
1165
 
1042
1166
  interface AuthorizationContext {
@@ -1173,6 +1297,33 @@ declare class InMemoryConfirmationRepository implements ConfirmationRepository {
1173
1297
  listPending(): Promise<ConfirmationRequest[]>;
1174
1298
  }
1175
1299
 
1300
+ interface DeclarativeCompilationResult {
1301
+ valid: boolean;
1302
+ errors: SchemaValidationError[];
1303
+ entities: EntitySchema[];
1304
+ /** Operation stubs for declared operations. Real implementations in config.operations override these. */
1305
+ operations: OperationDef[];
1306
+ /** Validated consumer declarations ready for resolution after metadata is built. */
1307
+ consumers: ConsumerDeclaration[];
1308
+ }
1309
+ interface CompileDeclarationsOptions {
1310
+ datasourceIds: string[];
1311
+ /**
1312
+ * Datasource to assign to all declared entities.
1313
+ * Resolved by the caller: either declarations.defaultDatasource or the single available datasource.
1314
+ */
1315
+ defaultDatasource?: string;
1316
+ }
1317
+ declare function compileDeclarations(config: DeclarativeConfig, options: CompileDeclarationsOptions): DeclarativeCompilationResult;
1318
+ /**
1319
+ * Resolves validated ConsumerDeclarations against the fully-built MaestroMetadata.
1320
+ * Must be called after MetadataEngine.normalize() has produced the final EntityMetadata[].
1321
+ */
1322
+ declare function resolveConsumerProjections(consumers: ConsumerDeclaration[], metadata: MaestroMetadata): ResolvedConsumerProjection[];
1323
+
1324
+ declare function validateEntityDeclaration(input: unknown): SchemaValidationResult;
1325
+ declare function validateConsumerDeclaration(input: unknown, entity?: EntityDeclaration): SchemaValidationResult;
1326
+
1176
1327
  declare const GOVERNANCE_EVENT_TYPES: {
1177
1328
  readonly OPERATION_EXECUTED: "governance.operation.executed";
1178
1329
  readonly AUTHORIZATION_DENIED: "governance.authorization.denied";
@@ -1246,4 +1397,4 @@ declare class DefaultGovernanceApi implements GovernanceApi {
1246
1397
  getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
1247
1398
  }
1248
1399
 
1249
- 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 ConfigProvider, type ConfirmationApproval, type ConfirmationApprovedPayload, ConfirmationEngine, type ConfirmationRejectedPayload, type ConfirmationRepository, type ConfirmationRequest, type ConfirmationRequestedPayload, type ConfirmationStatus, ConsoleLogger, ConsoleStructuredLogger, 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, DefaultGovernanceApi, type DiffChange, type DiffChangeKind, DiffEngine, type DiffEngineOptions, type DiffSummary, type DomainEvent, type EntityCapabilities, type EntityDiffChange, type EntityDiffChangeKind, type EntityExportConfig, type EntityIntrospectionSchema, type EntityLabelConfig, type EntityMetadata, type EntitySchema, type EntitySourceConfig, type EnumOption, ErrorCode, type EventBus, type EventHandler, type ExportConfig, type ExportFormat, type ExportOptions, type ExportProvider, type ExportResult, type FeatureFlag, type FeatureFlagProvider, 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 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 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 RelationDiffChange, type RelationDiffChangeKind, type RelationDisplayConfig, type RelationEndpoint, type RelationIntrospectionSchema, type RelationMetadata, type RelationSchema, type RelationType, ReportGenerator, type RequestConfirmationInput, type ResourceRef, type RiskClassificationInput, type RiskClassifier, type Role, type SchemaValidationError, type SchemaValidationResult, type SearchConfig, type SearchInput, type SnapshotRepository, type SoftDeleteConfig, type SortDescriptor, type SortDirection, type StructuredLogEntry, type StructuredLogger, type YamlParser, createMaestro, createMaestroFromIntrospection, createMaestroHttpHandlers, detectDisplayField, generateAllConfigs, generateCorrelationId, generateEntityConfig, generateRelationConfig, humanizeFieldName, inferFieldType, isSearchCandidate, isSoftDeleteCandidate, isTimestampField, loadMaestroConfig, mergeIntrospectionWithOverrides, parseQueryInput, tableNameToEntityId, tableNameToLabel, validateMaestroConfig };
1400
+ 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, 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, 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 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 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 SnapshotRepository, type SoftDeleteConfig, type SortDescriptor, type SortDirection, type StructuredLogEntry, type StructuredLogger, type YamlParser, compileDeclarations, createMaestro, createMaestroFromIntrospection, createMaestroHttpHandlers, detectDisplayField, generateAllConfigs, generateCorrelationId, generateEntityConfig, generateRelationConfig, humanizeFieldName, inferFieldType, isSearchCandidate, isSoftDeleteCandidate, isTimestampField, loadMaestroConfig, mergeIntrospectionWithOverrides, parseQueryInput, resolveConsumerProjections, tableNameToEntityId, tableNameToLabel, validateConsumerDeclaration, validateEntityDeclaration, validateMaestroConfig };