@maykonpaulo/maestro-core 0.2.1 → 0.3.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 CHANGED
@@ -66,6 +66,40 @@ declare class ConsoleLogger implements Logger {
66
66
  private serializeError;
67
67
  }
68
68
 
69
+ type OperationLogStatus = 'success' | 'failure' | 'partial';
70
+
71
+ interface StructuredLogEntry {
72
+ correlationId?: string;
73
+ operation?: string;
74
+ entity?: string;
75
+ entityId?: string;
76
+ actor?: string;
77
+ durationMs?: number;
78
+ status?: OperationLogStatus;
79
+ severity?: string;
80
+ message?: string;
81
+ metadata?: Metadata;
82
+ error?: unknown;
83
+ }
84
+
85
+ interface StructuredLogger {
86
+ debug(entry: StructuredLogEntry): void;
87
+ info(entry: StructuredLogEntry): void;
88
+ warn(entry: StructuredLogEntry): void;
89
+ error(entry: StructuredLogEntry): void;
90
+ }
91
+
92
+ declare class ConsoleStructuredLogger implements StructuredLogger {
93
+ private readonly minLevel;
94
+ constructor(minLevel?: LogLevel);
95
+ debug(entry: StructuredLogEntry): void;
96
+ info(entry: StructuredLogEntry): void;
97
+ warn(entry: StructuredLogEntry): void;
98
+ error(entry: StructuredLogEntry): void;
99
+ private log;
100
+ private serializeError;
101
+ }
102
+
69
103
  type AuditLevel = 'debug' | 'info' | 'warn' | 'error' | 'critical';
70
104
 
71
105
  interface AuditEvent {
@@ -74,6 +108,8 @@ interface AuditEvent {
74
108
  action: string;
75
109
  actor: Actor;
76
110
  resource?: ResourceRef;
111
+ entity?: string;
112
+ entityId?: string;
77
113
  level: AuditLevel;
78
114
  before?: Metadata;
79
115
  after?: Metadata;
@@ -87,6 +123,8 @@ interface AuditEvent {
87
123
  interface AuditFilter {
88
124
  actorId?: string;
89
125
  action?: string;
126
+ entity?: string;
127
+ entityId?: string;
90
128
  resourceType?: string;
91
129
  resourceId?: string;
92
130
  level?: AuditLevel;
@@ -99,11 +137,17 @@ interface AuditRepository {
99
137
  list(filter?: AuditFilter): Promise<AuditEvent[]>;
100
138
  }
101
139
 
140
+ interface AuditTimeline {
141
+ query(filter?: AuditFilter): Promise<AuditEvent[]>;
142
+ }
143
+
102
144
  interface RecordAuditInput {
103
145
  action: string;
104
146
  actor: Actor;
105
147
  level?: AuditLevel;
106
148
  resource?: ResourceRef;
149
+ entity?: string;
150
+ entityId?: string;
107
151
  before?: Metadata;
108
152
  after?: Metadata;
109
153
  metadata?: Metadata;
@@ -118,10 +162,11 @@ declare class AuditRecorder {
118
162
  record(input: RecordAuditInput): Promise<AuditEvent>;
119
163
  }
120
164
 
121
- declare class InMemoryAuditRepository implements AuditRepository {
165
+ declare class InMemoryAuditRepository implements AuditRepository, AuditTimeline {
122
166
  private readonly store;
123
167
  record(event: AuditEvent): Promise<void>;
124
168
  list(filter?: AuditFilter): Promise<AuditEvent[]>;
169
+ query(filter?: AuditFilter): Promise<AuditEvent[]>;
125
170
  }
126
171
 
127
172
  type Permission = string;
@@ -206,4 +251,999 @@ declare class InMemoryEventBus implements EventBus {
206
251
  unsubscribe<TPayload>(eventType: string, handler: EventHandler<TPayload>): void;
207
252
  }
208
253
 
209
- export { type Actor, type ActorType, type AuditEvent, type AuditFilter, type AuditLevel, AuditRecorder, type AuditRepository, type ConfigProvider, ConsoleLogger, type DomainEvent, ErrorCode, type EventBus, type EventHandler, type FeatureFlag, type FeatureFlagProvider, InMemoryAuditRepository, InMemoryConfigProvider, InMemoryEventBus, InMemoryFeatureFlagProvider, type LogEntry, type LogLevel, type Logger, MaestroError, type Metadata, type MetadataValue, type Permission, RbacEngine, type RbacPolicy, type RecordAuditInput, type ResourceRef, type Role };
254
+ type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'startsWith' | 'endsWith' | 'in' | 'notIn' | 'gt' | 'gte' | 'lt' | 'lte' | 'between' | 'isNull' | 'isNotNull' | 'isTrue' | 'isFalse';
255
+
256
+ interface FilterDescriptor {
257
+ field: string;
258
+ operator: FilterOperator;
259
+ value?: unknown;
260
+ }
261
+
262
+ type SortDirection = 'asc' | 'desc';
263
+ interface SortDescriptor {
264
+ field: string;
265
+ direction: SortDirection;
266
+ }
267
+
268
+ interface PagePagination {
269
+ strategy: 'page';
270
+ page: number;
271
+ pageSize: number;
272
+ }
273
+ interface OffsetPagination {
274
+ strategy: 'offset';
275
+ offset: number;
276
+ limit: number;
277
+ }
278
+ interface CursorPagination {
279
+ strategy: 'cursor';
280
+ cursor?: string;
281
+ limit: number;
282
+ }
283
+ type PaginationInput = PagePagination | OffsetPagination | CursorPagination;
284
+
285
+ interface SearchInput {
286
+ term: string;
287
+ fields: string[];
288
+ }
289
+
290
+ interface QueryInput {
291
+ filters?: FilterDescriptor[];
292
+ sort?: SortDescriptor[];
293
+ pagination?: PaginationInput;
294
+ search?: SearchInput;
295
+ }
296
+
297
+ interface ListResult<T = Record<string, unknown>> {
298
+ records: T[];
299
+ total: number;
300
+ page?: number;
301
+ pageSize?: number;
302
+ totalPages?: number;
303
+ nextCursor?: string;
304
+ }
305
+
306
+ type FieldType = 'string' | 'text' | 'number' | 'integer' | 'decimal' | 'currency' | 'boolean' | 'date' | 'datetime' | 'time' | 'email' | 'phone' | 'url' | 'document' | 'uuid' | 'enum' | 'json' | 'relation' | 'array';
307
+
308
+ interface EnumOption {
309
+ value: string | number;
310
+ label: string;
311
+ }
312
+ interface FieldListConfig {
313
+ visible: boolean;
314
+ width?: number;
315
+ align?: 'left' | 'center' | 'right';
316
+ order?: number;
317
+ }
318
+ interface FieldDetailConfig {
319
+ visible: boolean;
320
+ group?: string;
321
+ order?: number;
322
+ }
323
+ interface FieldFormConfig {
324
+ creatable: boolean;
325
+ editable: boolean;
326
+ cloneable: boolean;
327
+ placeholder?: string;
328
+ helpText?: string;
329
+ section?: string;
330
+ order?: number;
331
+ }
332
+ interface FieldMetadata {
333
+ name: string;
334
+ label: string;
335
+ type: FieldType;
336
+ required: boolean;
337
+ readonly: boolean;
338
+ hidden: boolean;
339
+ sensitive: boolean;
340
+ searchable: boolean;
341
+ sortable: boolean;
342
+ filterable: boolean;
343
+ exportable: boolean;
344
+ filterOperators: FilterOperator[];
345
+ description?: string;
346
+ enumOptions?: EnumOption[];
347
+ relationEntity?: string;
348
+ mask?: string;
349
+ list: FieldListConfig;
350
+ detail: FieldDetailConfig;
351
+ form: FieldFormConfig;
352
+ }
353
+
354
+ interface EntityCapabilities {
355
+ list: boolean;
356
+ detail: boolean;
357
+ create: boolean;
358
+ update: boolean;
359
+ clone: boolean;
360
+ delete: boolean;
361
+ softDelete: boolean;
362
+ export: boolean;
363
+ bulkActions: boolean;
364
+ }
365
+ declare const DEFAULT_CAPABILITIES: EntityCapabilities;
366
+
367
+ interface SoftDeleteConfig {
368
+ field: string;
369
+ activeValue: unknown;
370
+ inactiveValue: unknown;
371
+ }
372
+
373
+ interface SearchConfig {
374
+ fields: string[];
375
+ }
376
+
377
+ type ContextActionCondition = 'always' | 'when-active' | 'when-inactive';
378
+ type ContextActionStyle = 'default' | 'warning' | 'danger';
379
+ interface ContextAction {
380
+ id: string;
381
+ label: string;
382
+ permission: string;
383
+ condition?: ContextActionCondition;
384
+ style?: ContextActionStyle;
385
+ operationId?: string;
386
+ }
387
+
388
+ interface ExportConfig {
389
+ filename?: string;
390
+ }
391
+
392
+ interface EntityMetadata {
393
+ id: string;
394
+ label: {
395
+ singular: string;
396
+ plural: string;
397
+ };
398
+ description?: string;
399
+ datasource: string;
400
+ table: string;
401
+ primaryKey: string;
402
+ displayField: string;
403
+ fields: FieldMetadata[];
404
+ capabilities: EntityCapabilities;
405
+ softDelete?: SoftDeleteConfig;
406
+ defaultSort?: SortDescriptor;
407
+ search?: SearchConfig;
408
+ relations: string[];
409
+ contextActions: ContextAction[];
410
+ bulkOperations: string[];
411
+ exportConfig?: ExportConfig;
412
+ }
413
+
414
+ type RelationType = 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many';
415
+ interface RelationEndpoint {
416
+ entity: string;
417
+ field: string;
418
+ }
419
+ interface RelationDisplayConfig {
420
+ tab: boolean;
421
+ label?: string;
422
+ }
423
+ interface RelationMetadata {
424
+ id: string;
425
+ type: RelationType;
426
+ from: RelationEndpoint;
427
+ to: RelationEndpoint;
428
+ label: string;
429
+ display?: RelationDisplayConfig;
430
+ }
431
+
432
+ type OperationScope = 'global' | 'entity' | 'record' | 'bulk';
433
+ interface OperationMetadata {
434
+ id: string;
435
+ label: string;
436
+ description?: string;
437
+ entity?: string;
438
+ scope: OperationScope;
439
+ requiresConfirmation: boolean;
440
+ confirmationMessage?: string;
441
+ requiresTypedConfirmation: boolean;
442
+ requiredPermission?: string;
443
+ }
444
+
445
+ interface MaestroMetadata {
446
+ entities: EntityMetadata[];
447
+ relations: RelationMetadata[];
448
+ operations: OperationMetadata[];
449
+ policies: RbacPolicy;
450
+ }
451
+
452
+ interface DatasourceQueryContext {
453
+ table: string;
454
+ primaryKey: string;
455
+ filters?: FilterDescriptor[];
456
+ sort?: SortDescriptor[];
457
+ pagination?: PaginationInput;
458
+ search?: SearchInput;
459
+ }
460
+ interface DatasourceFindContext {
461
+ table: string;
462
+ primaryKey: string;
463
+ id: string;
464
+ }
465
+ interface DatasourceWriteContext {
466
+ table: string;
467
+ primaryKey: string;
468
+ data: Record<string, unknown>;
469
+ }
470
+ interface DatasourceUpdateContext {
471
+ table: string;
472
+ primaryKey: string;
473
+ id: string;
474
+ data: Record<string, unknown>;
475
+ }
476
+ interface DatasourceDeleteContext {
477
+ table: string;
478
+ primaryKey: string;
479
+ id: string;
480
+ }
481
+
482
+ interface DatasourceProvider {
483
+ list(context: DatasourceQueryContext): Promise<ListResult<Record<string, unknown>>>;
484
+ findById(context: DatasourceFindContext): Promise<Record<string, unknown> | null>;
485
+ create(context: DatasourceWriteContext): Promise<Record<string, unknown>>;
486
+ update(context: DatasourceUpdateContext): Promise<Record<string, unknown>>;
487
+ delete(context: DatasourceDeleteContext): Promise<void>;
488
+ count(context: DatasourceQueryContext): Promise<number>;
489
+ }
490
+
491
+ declare class DatasourceRegistry {
492
+ private readonly registry;
493
+ register(id: string, provider: DatasourceProvider): void;
494
+ get(id: string): DatasourceProvider;
495
+ has(id: string): boolean;
496
+ ids(): string[];
497
+ }
498
+
499
+ declare class InMemoryDatasourceProvider implements DatasourceProvider {
500
+ private readonly tables;
501
+ seed(table: string, records: Record<string, unknown>[], primaryKey?: string): void;
502
+ list(context: DatasourceQueryContext): Promise<ListResult<Record<string, unknown>>>;
503
+ findById(context: DatasourceFindContext): Promise<Record<string, unknown> | null>;
504
+ create(context: DatasourceWriteContext): Promise<Record<string, unknown>>;
505
+ update(context: DatasourceUpdateContext): Promise<Record<string, unknown>>;
506
+ delete(context: DatasourceDeleteContext): Promise<void>;
507
+ count(context: DatasourceQueryContext): Promise<number>;
508
+ private getStore;
509
+ private applyFilters;
510
+ private matchFilter;
511
+ private applySort;
512
+ }
513
+
514
+ interface OperationContext<TInput = unknown> {
515
+ actor: Actor;
516
+ entityId?: string;
517
+ record?: Record<string, unknown>;
518
+ records?: Record<string, unknown>[];
519
+ input?: TInput;
520
+ correlationId?: string;
521
+ metadata?: Metadata;
522
+ }
523
+
524
+ interface OperationResult<TOutput = unknown> {
525
+ success: boolean;
526
+ output?: TOutput;
527
+ message?: string;
528
+ error?: string;
529
+ metadata?: Metadata;
530
+ }
531
+
532
+ interface OperationDef<TInput = unknown, TOutput = unknown> {
533
+ id: string;
534
+ label: string;
535
+ description?: string;
536
+ entity?: string;
537
+ scope: OperationScope;
538
+ requiresConfirmation?: boolean;
539
+ confirmationMessage?: string;
540
+ requiresTypedConfirmation?: boolean;
541
+ requiredPermission?: string;
542
+ execute: (context: OperationContext<TInput>) => Promise<OperationResult<TOutput>>;
543
+ }
544
+
545
+ declare class OperationRegistry {
546
+ private readonly operations;
547
+ register(operation: OperationDef): void;
548
+ get(id: string): OperationDef;
549
+ find(id: string): OperationDef | undefined;
550
+ forEntity(entityId: string, scope?: OperationScope): OperationDef[];
551
+ all(): OperationDef[];
552
+ }
553
+
554
+ interface FieldSchemaListConfig {
555
+ visible?: boolean;
556
+ width?: number;
557
+ align?: 'left' | 'center' | 'right';
558
+ order?: number;
559
+ }
560
+ interface FieldSchemaDetailConfig {
561
+ visible?: boolean;
562
+ group?: string;
563
+ order?: number;
564
+ }
565
+ interface FieldSchemaFormConfig {
566
+ creatable?: boolean;
567
+ editable?: boolean;
568
+ cloneable?: boolean;
569
+ placeholder?: string;
570
+ helpText?: string;
571
+ section?: string;
572
+ order?: number;
573
+ }
574
+ interface FieldSchemaEnumOption {
575
+ value: string | number;
576
+ label: string;
577
+ }
578
+ interface FieldSchema {
579
+ name: string;
580
+ label: string;
581
+ type: FieldType;
582
+ required?: boolean;
583
+ readonly?: boolean;
584
+ hidden?: boolean;
585
+ sensitive?: boolean;
586
+ searchable?: boolean;
587
+ sortable?: boolean;
588
+ filterable?: boolean;
589
+ exportable?: boolean;
590
+ filterOperators?: FilterOperator[];
591
+ description?: string;
592
+ enumOptions?: FieldSchemaEnumOption[];
593
+ relationEntity?: string;
594
+ mask?: string;
595
+ list?: FieldSchemaListConfig;
596
+ detail?: FieldSchemaDetailConfig;
597
+ form?: FieldSchemaFormConfig;
598
+ }
599
+
600
+ interface EntitySourceConfig {
601
+ datasource: string;
602
+ table: string;
603
+ primaryKey?: string;
604
+ }
605
+ interface EntityLabelConfig {
606
+ singular: string;
607
+ plural: string;
608
+ }
609
+ interface EntityExportConfig {
610
+ filename?: string;
611
+ }
612
+ interface EntitySchema {
613
+ id: string;
614
+ label: EntityLabelConfig;
615
+ description?: string;
616
+ source: EntitySourceConfig;
617
+ displayField?: string;
618
+ capabilities?: Partial<EntityCapabilities>;
619
+ softDelete?: SoftDeleteConfig;
620
+ defaultSort?: SortDescriptor;
621
+ search?: SearchConfig;
622
+ exportConfig?: EntityExportConfig;
623
+ fields: FieldSchema[];
624
+ }
625
+
626
+ interface RelationSchema {
627
+ id: string;
628
+ type: RelationType;
629
+ from: RelationEndpoint;
630
+ to: RelationEndpoint;
631
+ label: string;
632
+ display?: RelationDisplayConfig;
633
+ }
634
+
635
+ interface MaestroConfig {
636
+ datasources: Record<string, DatasourceProvider>;
637
+ entities: EntitySchema[];
638
+ relations?: RelationSchema[];
639
+ operations?: OperationDef[];
640
+ policies?: RbacPolicy;
641
+ audit?: AuditRepository;
642
+ logger?: Logger;
643
+ }
644
+
645
+ interface SchemaValidationError {
646
+ path: string;
647
+ message: string;
648
+ }
649
+ interface SchemaValidationResult {
650
+ valid: boolean;
651
+ errors: SchemaValidationError[];
652
+ }
653
+ declare function validateMaestroConfig(config: MaestroConfig): SchemaValidationResult;
654
+
655
+ declare class MetadataEngine {
656
+ normalize(config: MaestroConfig): MaestroMetadata;
657
+ private normalizeEntity;
658
+ private normalizeField;
659
+ }
660
+
661
+ type ExportFormat = 'csv' | 'json';
662
+
663
+ interface ExportResult {
664
+ format: ExportFormat;
665
+ data: string;
666
+ filename: string;
667
+ recordCount: number;
668
+ mimeType: string;
669
+ }
670
+
671
+ declare class MaestroEngine {
672
+ private readonly metadata;
673
+ private readonly datasources;
674
+ private readonly operations;
675
+ private readonly audit?;
676
+ private readonly rbac;
677
+ constructor(metadata: MaestroMetadata, datasources: DatasourceRegistry, operations: OperationRegistry, audit?: AuditRecorder | undefined);
678
+ getMetadata(): MaestroMetadata;
679
+ list(entityId: string, query: QueryInput, actor: Actor): Promise<ListResult<Record<string, unknown>>>;
680
+ findById(entityId: string, id: string, actor: Actor): Promise<Record<string, unknown> | null>;
681
+ create(entityId: string, data: Record<string, unknown>, actor: Actor): Promise<Record<string, unknown>>;
682
+ update(entityId: string, id: string, data: Record<string, unknown>, actor: Actor): Promise<Record<string, unknown>>;
683
+ clone(entityId: string, id: string, actor: Actor): Promise<Record<string, unknown>>;
684
+ softDelete(entityId: string, id: string, actor: Actor): Promise<void>;
685
+ restore(entityId: string, id: string, actor: Actor): Promise<void>;
686
+ hardDelete(entityId: string, id: string, actor: Actor): Promise<void>;
687
+ export(entityId: string, query: QueryInput, actor: Actor, format?: ExportFormat): Promise<ExportResult>;
688
+ executeOperation(operationId: string, context: OperationContext, actor: Actor): Promise<OperationResult>;
689
+ private requireEntity;
690
+ private requireCapability;
691
+ private recordAudit;
692
+ }
693
+
694
+ declare function createMaestro(config: MaestroConfig): MaestroEngine;
695
+
696
+ interface FieldIntrospectionSchema {
697
+ name: string;
698
+ nativeType: string;
699
+ type: FieldType;
700
+ nullable: boolean;
701
+ isPrimaryKey: boolean;
702
+ isUnique?: boolean;
703
+ isForeignKey?: boolean;
704
+ referencesTable?: string;
705
+ referencesField?: string;
706
+ defaultValue?: unknown;
707
+ maxLength?: number;
708
+ isIndexed?: boolean;
709
+ candidateForSearch?: boolean;
710
+ candidateForSoftDelete?: boolean;
711
+ isTimestamp?: boolean;
712
+ }
713
+ interface IndexIntrospectionSchema {
714
+ name?: string;
715
+ fields: string[];
716
+ isUnique: boolean;
717
+ }
718
+ interface EntityIntrospectionSchema {
719
+ table: string;
720
+ fields: FieldIntrospectionSchema[];
721
+ indices?: IndexIntrospectionSchema[];
722
+ }
723
+ interface RelationIntrospectionSchema {
724
+ id: string;
725
+ type: RelationType;
726
+ from: {
727
+ table: string;
728
+ field: string;
729
+ };
730
+ to: {
731
+ table: string;
732
+ field: string;
733
+ };
734
+ confidence: 'definite' | 'inferred';
735
+ }
736
+ interface IntrospectionResult {
737
+ entities: EntityIntrospectionSchema[];
738
+ relations: RelationIntrospectionSchema[];
739
+ }
740
+
741
+ interface IntrospectionProvider {
742
+ introspect(): Promise<IntrospectionResult>;
743
+ }
744
+
745
+ interface YamlParser {
746
+ parse(content: string): unknown;
747
+ }
748
+
749
+ interface FileSystemReader {
750
+ readFile(path: string): Promise<string>;
751
+ readDir(path: string): Promise<string[]>;
752
+ exists(path: string): Promise<boolean>;
753
+ }
754
+ interface MaestroFileLoaderOptions {
755
+ rootDir: string;
756
+ yamlParser?: YamlParser;
757
+ fileReader?: FileSystemReader;
758
+ }
759
+ interface LoadedConfig {
760
+ entities: EntitySchema[];
761
+ relations: RelationSchema[];
762
+ policies?: RbacPolicy;
763
+ }
764
+ declare function loadMaestroConfig(options: MaestroFileLoaderOptions): Promise<LoadedConfig>;
765
+
766
+ type MergeStrategy = 'extend' | 'override';
767
+ interface MergeIntrospectionOptions {
768
+ introspection: IntrospectionResult;
769
+ overrides: LoadedConfig;
770
+ datasources: Record<string, DatasourceProvider>;
771
+ defaultDatasource: string;
772
+ strategy?: MergeStrategy;
773
+ operations?: OperationDef[];
774
+ audit?: AuditRepository;
775
+ logger?: Logger;
776
+ }
777
+ declare function mergeIntrospectionWithOverrides(options: MergeIntrospectionOptions): MaestroConfig;
778
+
779
+ interface CreateMaestroFromIntrospectionOptions {
780
+ provider: IntrospectionProvider;
781
+ overrides?: LoadedConfig;
782
+ mergeStrategy?: MergeStrategy;
783
+ datasources?: Record<string, DatasourceProvider>;
784
+ defaultDatasource?: string;
785
+ policies?: RbacPolicy;
786
+ operations?: OperationDef[];
787
+ audit?: AuditRepository;
788
+ logger?: Logger;
789
+ }
790
+ declare function createMaestroFromIntrospection(options: CreateMaestroFromIntrospectionOptions): Promise<MaestroEngine>;
791
+
792
+ interface ExportOptions {
793
+ format: ExportFormat;
794
+ includeFields?: string[];
795
+ excludeFields?: string[];
796
+ dateFormat?: string;
797
+ bom?: boolean;
798
+ }
799
+
800
+ interface ExportProvider {
801
+ export(entity: EntityMetadata, records: Record<string, unknown>[], options: ExportOptions): ExportResult;
802
+ }
803
+
804
+ declare class CsvExportProvider implements ExportProvider {
805
+ export(entity: EntityMetadata, records: Record<string, unknown>[], options: ExportOptions): ExportResult;
806
+ private resolveFields;
807
+ private formatValue;
808
+ private formatDate;
809
+ private escapeCsvCell;
810
+ }
811
+
812
+ interface MaestroHttpRequest {
813
+ params: Record<string, string>;
814
+ query: Record<string, string | string[]>;
815
+ body: unknown;
816
+ headers: Record<string, string | string[] | undefined>;
817
+ method: string;
818
+ path: string;
819
+ }
820
+ interface MaestroHttpResponse {
821
+ status: number;
822
+ body: unknown;
823
+ headers?: Record<string, string>;
824
+ }
825
+ type MaestroHttpHandler = (request: MaestroHttpRequest) => Promise<MaestroHttpResponse>;
826
+
827
+ interface MaestroRequestContext {
828
+ actor: Actor;
829
+ correlationId?: string;
830
+ }
831
+ type MaestroActorResolver = (request: MaestroHttpRequest) => Promise<MaestroRequestContext>;
832
+ interface MaestroHttpOptions {
833
+ actorResolver: MaestroActorResolver;
834
+ }
835
+
836
+ interface MaestroHttpHandlers {
837
+ list: MaestroHttpHandler;
838
+ findById: MaestroHttpHandler;
839
+ create: MaestroHttpHandler;
840
+ update: MaestroHttpHandler;
841
+ clone: MaestroHttpHandler;
842
+ softDelete: MaestroHttpHandler;
843
+ restore: MaestroHttpHandler;
844
+ hardDelete: MaestroHttpHandler;
845
+ export: MaestroHttpHandler;
846
+ executeOperation: MaestroHttpHandler;
847
+ getMetadata: MaestroHttpHandler;
848
+ getEntityMetadata: MaestroHttpHandler;
849
+ health: MaestroHttpHandler;
850
+ }
851
+
852
+ declare function parseQueryInput(query: Record<string, string | string[]>): QueryInput;
853
+
854
+ declare function createMaestroHttpHandlers(engine: MaestroEngine, options: MaestroHttpOptions): MaestroHttpHandlers;
855
+
856
+ declare function inferFieldType(nativeType: string, fieldName: string): FieldType;
857
+ declare function isTimestampField(fieldName: string, fieldType: FieldType): boolean;
858
+ declare function isSoftDeleteCandidate(fieldName: string, fieldType: FieldType, nullable: boolean): boolean;
859
+ declare function isSearchCandidate(fieldName: string, fieldType: FieldType, isPrimaryKey: boolean): boolean;
860
+ declare function tableNameToEntityId(table: string): string;
861
+ declare function tableNameToLabel(table: string): {
862
+ singular: string;
863
+ plural: string;
864
+ };
865
+ declare function humanizeFieldName(name: string): string;
866
+ declare function detectDisplayField(fields: Array<{
867
+ name: string;
868
+ type: FieldType;
869
+ isPrimaryKey: boolean;
870
+ }>): string | undefined;
871
+
872
+ interface GeneratedConfig {
873
+ entities: Record<string, EntitySchema>;
874
+ relations: Record<string, RelationSchema>;
875
+ }
876
+ declare function generateEntityConfig(entity: EntityIntrospectionSchema, datasource: string): EntitySchema;
877
+ declare function generateRelationConfig(relation: RelationIntrospectionSchema, entityIdByTable: Map<string, string>): RelationSchema | null;
878
+ declare function generateAllConfigs(result: IntrospectionResult, datasource: string): GeneratedConfig;
879
+
880
+ type ImpactLevel = 'SAFE' | 'WARNING' | 'BREAKING';
881
+ type EntityDiffChangeKind = 'entity_added' | 'entity_removed' | 'entity_label_changed' | 'entity_primary_key_changed';
882
+ type FieldDiffChangeKind = 'field_added' | 'field_removed' | 'field_type_changed' | 'field_nullable_changed' | 'field_index_added' | 'field_index_removed' | 'field_metadata_changed';
883
+ type RelationDiffChangeKind = 'relation_added' | 'relation_removed' | 'relation_cardinality_changed' | 'relation_fields_changed';
884
+ type DiffChangeKind = EntityDiffChangeKind | FieldDiffChangeKind | RelationDiffChangeKind;
885
+ interface EntityDiffChange {
886
+ category: 'entity';
887
+ kind: EntityDiffChangeKind;
888
+ impact: ImpactLevel;
889
+ entityTable: string;
890
+ previous?: unknown;
891
+ current?: unknown;
892
+ }
893
+ interface FieldDiffChange {
894
+ category: 'field';
895
+ kind: FieldDiffChangeKind;
896
+ impact: ImpactLevel;
897
+ entityTable: string;
898
+ fieldName: string;
899
+ previous?: unknown;
900
+ current?: unknown;
901
+ }
902
+ interface RelationDiffChange {
903
+ category: 'relation';
904
+ kind: RelationDiffChangeKind;
905
+ impact: ImpactLevel;
906
+ relationId: string;
907
+ previous?: unknown;
908
+ current?: unknown;
909
+ }
910
+ type DiffChange = EntityDiffChange | FieldDiffChange | RelationDiffChange;
911
+ interface DiffSummary {
912
+ total: number;
913
+ safe: number;
914
+ warnings: number;
915
+ breaking: number;
916
+ }
917
+ interface IntrospectionDiff {
918
+ changes: DiffChange[];
919
+ summary: DiffSummary;
920
+ hasBreaking: boolean;
921
+ hasWarnings: boolean;
922
+ }
923
+
924
+ interface DiffEngineOptions {
925
+ /**
926
+ * Optional explicit label maps (table → label) for detecting label changes
927
+ * across two introspection snapshots. When omitted, labels are derived
928
+ * from table names via tableNameToLabel — making entity_label_changed
929
+ * only fire when the table name itself changes its derived label.
930
+ */
931
+ previousEntityLabels?: Map<string, string>;
932
+ currentEntityLabels?: Map<string, string>;
933
+ }
934
+ declare class DiffEngine {
935
+ compare(previous: IntrospectionResult, current: IntrospectionResult, options?: DiffEngineOptions): IntrospectionDiff;
936
+ private compareFields;
937
+ }
938
+
939
+ interface IntrospectionReportStats {
940
+ entitiesDiscovered: number;
941
+ relationsDiscovered: number;
942
+ totalChanges: number;
943
+ safeChanges: number;
944
+ warnings: number;
945
+ breakingChanges: number;
946
+ }
947
+ interface IntrospectionReportChange {
948
+ impact: ImpactLevel;
949
+ description: string;
950
+ recommendation?: string;
951
+ }
952
+ interface IntrospectionReport {
953
+ completedAt: string;
954
+ stats: IntrospectionReportStats;
955
+ changes: IntrospectionReportChange[];
956
+ hasDiff: boolean;
957
+ text: string;
958
+ }
959
+
960
+ declare class ReportGenerator {
961
+ generate(result: IntrospectionResult, diff?: IntrospectionDiff): IntrospectionReport;
962
+ private describeChange;
963
+ private generateText;
964
+ }
965
+
966
+ interface IntrospectionSnapshot {
967
+ id: string;
968
+ timestamp: string;
969
+ result: IntrospectionResult;
970
+ label?: string;
971
+ }
972
+
973
+ interface SnapshotRepository {
974
+ save(snapshot: IntrospectionSnapshot): Promise<void>;
975
+ load(id: string): Promise<IntrospectionSnapshot | null>;
976
+ }
977
+
978
+ declare class InMemorySnapshotRepository implements SnapshotRepository {
979
+ private readonly store;
980
+ save(snapshot: IntrospectionSnapshot): Promise<void>;
981
+ load(id: string): Promise<IntrospectionSnapshot | null>;
982
+ }
983
+
984
+ interface IntrospectionRuntimeRunOptions {
985
+ provider: IntrospectionProvider;
986
+ overrides?: LoadedConfig;
987
+ mergeStrategy?: MergeStrategy;
988
+ datasources?: Record<string, DatasourceProvider>;
989
+ defaultDatasource?: string;
990
+ /** ID of a previously saved snapshot to diff against */
991
+ snapshotId?: string;
992
+ /** Whether to automatically save the new snapshot after running. Defaults to true when a repository is configured. */
993
+ saveSnapshot?: boolean;
994
+ operations?: OperationDef[];
995
+ audit?: AuditRepository;
996
+ logger?: Logger;
997
+ policies?: RbacPolicy;
998
+ }
999
+ interface IntrospectionRuntimeResult {
1000
+ metadata: MaestroMetadata;
1001
+ diff?: IntrospectionDiff;
1002
+ report: IntrospectionReport;
1003
+ snapshot: IntrospectionSnapshot;
1004
+ }
1005
+ declare class IntrospectionRuntime {
1006
+ private readonly snapshotRepository?;
1007
+ private lastProvider?;
1008
+ constructor(snapshotRepository?: SnapshotRepository | undefined);
1009
+ run(options: IntrospectionRuntimeRunOptions): Promise<IntrospectionRuntimeResult>;
1010
+ saveSnapshot(snapshot: IntrospectionSnapshot): Promise<void>;
1011
+ loadSnapshot(id: string): Promise<IntrospectionSnapshot | null>;
1012
+ compareWithSnapshot(snapshotId: string, provider?: IntrospectionProvider): Promise<IntrospectionDiff | null>;
1013
+ }
1014
+
1015
+ type CorrelationId = string;
1016
+ declare function generateCorrelationId(): CorrelationId;
1017
+
1018
+ interface CorrelationContext {
1019
+ correlationId: CorrelationId;
1020
+ }
1021
+
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
+ type AuthorizationDecision = 'ALLOW' | 'DENY' | 'REQUIRES_CONFIRMATION';
1041
+
1042
+ interface AuthorizationContext {
1043
+ actor: Actor;
1044
+ operation: string;
1045
+ resource?: ResourceRef;
1046
+ metadata?: Metadata;
1047
+ riskLevel?: OperationalRisk;
1048
+ correlationId?: string;
1049
+ }
1050
+
1051
+ interface AuthorizationResult {
1052
+ decision: AuthorizationDecision;
1053
+ reason?: string;
1054
+ metadata?: Metadata;
1055
+ }
1056
+
1057
+ interface AuthorizationProvider {
1058
+ evaluate(context: AuthorizationContext): Promise<AuthorizationResult>;
1059
+ }
1060
+
1061
+ declare class ContextualAuthorizationEngine implements AuthorizationProvider {
1062
+ private readonly criticalOperations;
1063
+ private readonly rbac;
1064
+ constructor(policy: RbacPolicy, criticalOperations?: ReadonlySet<string>);
1065
+ evaluate(context: AuthorizationContext): Promise<AuthorizationResult>;
1066
+ }
1067
+
1068
+ type PolicyDecision = 'ALLOW' | 'DENY' | 'REQUIRES_CONFIRMATION';
1069
+
1070
+ interface PolicyContext {
1071
+ actor: Actor;
1072
+ operation: string;
1073
+ resource?: ResourceRef;
1074
+ metadata?: Metadata;
1075
+ riskLevel?: OperationalRisk;
1076
+ correlationId?: string;
1077
+ }
1078
+
1079
+ interface PolicyRuleResult {
1080
+ decision: PolicyDecision;
1081
+ reason?: string;
1082
+ }
1083
+ interface PolicyRule {
1084
+ id: string;
1085
+ description?: string;
1086
+ evaluate(context: PolicyContext): PolicyRuleResult | null;
1087
+ }
1088
+
1089
+ interface PolicyViolation {
1090
+ ruleId: string;
1091
+ reason?: string;
1092
+ context: PolicyContext;
1093
+ occurredAt: Date;
1094
+ }
1095
+
1096
+ interface PolicyEvaluationResult {
1097
+ decision: PolicyDecision;
1098
+ violations: PolicyViolation[];
1099
+ reason?: string;
1100
+ }
1101
+
1102
+ interface PolicyProvider {
1103
+ rules(): PolicyRule[];
1104
+ }
1105
+
1106
+ declare class PolicyEngine {
1107
+ private readonly provider;
1108
+ constructor(provider: PolicyProvider);
1109
+ evaluate(context: PolicyContext): PolicyEvaluationResult;
1110
+ }
1111
+
1112
+ declare class InMemoryPolicyProvider implements PolicyProvider {
1113
+ private readonly _rules;
1114
+ constructor(rules?: PolicyRule[]);
1115
+ rules(): PolicyRule[];
1116
+ }
1117
+
1118
+ type ConfirmationStatus = 'REQUESTED' | 'AWAITING_CONFIRMATION' | 'APPROVED' | 'REJECTED' | 'EXECUTED' | 'EXPIRED';
1119
+
1120
+ interface ConfirmationApproval {
1121
+ approver: Actor;
1122
+ approvedAt: Date;
1123
+ comment?: string;
1124
+ }
1125
+
1126
+ interface ConfirmationRequest {
1127
+ id: string;
1128
+ operation: string;
1129
+ actor: Actor;
1130
+ resource?: ResourceRef;
1131
+ status: ConfirmationStatus;
1132
+ requiredApprovals: number;
1133
+ approvals: ConfirmationApproval[];
1134
+ rejections: ConfirmationApproval[];
1135
+ requestedAt: Date;
1136
+ executedAt?: Date;
1137
+ expiresAt?: Date;
1138
+ metadata?: Metadata;
1139
+ correlationId?: string;
1140
+ }
1141
+
1142
+ interface ConfirmationRepository {
1143
+ save(request: ConfirmationRequest): Promise<void>;
1144
+ findById(id: string): Promise<ConfirmationRequest | undefined>;
1145
+ listPending(): Promise<ConfirmationRequest[]>;
1146
+ }
1147
+
1148
+ interface RequestConfirmationInput {
1149
+ operation: string;
1150
+ actor: Actor;
1151
+ resource?: ResourceRef;
1152
+ requiredApprovals?: number;
1153
+ metadata?: Metadata;
1154
+ correlationId?: string;
1155
+ expiresAt?: Date;
1156
+ }
1157
+ declare class ConfirmationEngine {
1158
+ private readonly repository;
1159
+ constructor(repository: ConfirmationRepository);
1160
+ request(input: RequestConfirmationInput): Promise<ConfirmationRequest>;
1161
+ approve(requestId: string, approver: Actor, comment?: string): Promise<ConfirmationRequest>;
1162
+ reject(requestId: string, approver: Actor, comment?: string): Promise<ConfirmationRequest>;
1163
+ execute(requestId: string): Promise<ConfirmationRequest>;
1164
+ getPending(): Promise<ConfirmationRequest[]>;
1165
+ private findOrThrow;
1166
+ private assertActive;
1167
+ }
1168
+
1169
+ declare class InMemoryConfirmationRepository implements ConfirmationRepository {
1170
+ private readonly store;
1171
+ save(request: ConfirmationRequest): Promise<void>;
1172
+ findById(id: string): Promise<ConfirmationRequest | undefined>;
1173
+ listPending(): Promise<ConfirmationRequest[]>;
1174
+ }
1175
+
1176
+ declare const GOVERNANCE_EVENT_TYPES: {
1177
+ readonly OPERATION_EXECUTED: "governance.operation.executed";
1178
+ readonly AUTHORIZATION_DENIED: "governance.authorization.denied";
1179
+ readonly POLICY_TRIGGERED: "governance.policy.triggered";
1180
+ readonly CONFIRMATION_REQUESTED: "governance.confirmation.requested";
1181
+ readonly CONFIRMATION_APPROVED: "governance.confirmation.approved";
1182
+ readonly CONFIRMATION_REJECTED: "governance.confirmation.rejected";
1183
+ readonly AUDIT_RECORDED: "governance.audit.recorded";
1184
+ };
1185
+ type GovernanceEventType = (typeof GOVERNANCE_EVENT_TYPES)[keyof typeof GOVERNANCE_EVENT_TYPES];
1186
+
1187
+ interface OperationExecutedPayload {
1188
+ operation: string;
1189
+ actor: Actor;
1190
+ resource?: ResourceRef;
1191
+ correlationId?: string;
1192
+ durationMs?: number;
1193
+ }
1194
+ interface AuthorizationDeniedPayload {
1195
+ context: AuthorizationContext;
1196
+ reason?: string;
1197
+ }
1198
+ interface PolicyTriggeredPayload {
1199
+ violations: PolicyViolation[];
1200
+ correlationId?: string;
1201
+ }
1202
+ interface ConfirmationRequestedPayload {
1203
+ request: ConfirmationRequest;
1204
+ }
1205
+ interface ConfirmationApprovedPayload {
1206
+ request: ConfirmationRequest;
1207
+ approver: Actor;
1208
+ }
1209
+ interface ConfirmationRejectedPayload {
1210
+ request: ConfirmationRequest;
1211
+ approver: Actor;
1212
+ }
1213
+ interface AuditRecordedPayload {
1214
+ event: AuditEvent;
1215
+ }
1216
+
1217
+ interface GovernanceEventBus extends EventBus {
1218
+ publishGovernance<TPayload>(type: GovernanceEventType, payload: TPayload, correlationId?: string): Promise<DomainEvent<TPayload>>;
1219
+ }
1220
+
1221
+ declare class InMemoryGovernanceEventBus extends InMemoryEventBus implements GovernanceEventBus {
1222
+ publishGovernance<TPayload>(type: GovernanceEventType, payload: TPayload, correlationId?: string): Promise<DomainEvent<TPayload>>;
1223
+ }
1224
+
1225
+ interface PolicyViolationFilter {
1226
+ ruleId?: string;
1227
+ correlationId?: string;
1228
+ from?: Date;
1229
+ to?: Date;
1230
+ }
1231
+ interface GovernanceApi {
1232
+ getAuditTimeline(filter?: AuditFilter): Promise<AuditEvent[]>;
1233
+ getCorrelationTrace(correlationId: string): Promise<AuditEvent[]>;
1234
+ getPendingConfirmations(): Promise<ConfirmationRequest[]>;
1235
+ getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
1236
+ }
1237
+
1238
+ declare class DefaultGovernanceApi implements GovernanceApi {
1239
+ private readonly auditRepository;
1240
+ private readonly confirmationRepository;
1241
+ private readonly violationLog;
1242
+ constructor(auditRepository: AuditRepository, confirmationRepository: ConfirmationRepository, violationLog?: PolicyViolation[]);
1243
+ getAuditTimeline(filter?: AuditFilter): Promise<AuditEvent[]>;
1244
+ getCorrelationTrace(correlationId: string): Promise<AuditEvent[]>;
1245
+ getPendingConfirmations(): Promise<ConfirmationRequest[]>;
1246
+ getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
1247
+ }
1248
+
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 };