@maykonpaulo/maestro-core 0.3.0 → 0.5.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 CHANGED
@@ -1355,6 +1355,33 @@ declare function resolveConsumerProjections(consumers: ConsumerDeclaration[], me
1355
1355
  declare function validateEntityDeclaration(input: unknown): SchemaValidationResult;
1356
1356
  declare function validateConsumerDeclaration(input: unknown, entity?: EntityDeclaration): SchemaValidationResult;
1357
1357
 
1358
+ type DeclarativeFileFormat = 'yaml' | 'json';
1359
+ /**
1360
+ * Canonical shape of a declarative config file — structurally identical to `DeclarativeConfig`,
1361
+ * so it can be passed directly as `createMaestro({ declarations })`.
1362
+ * `entities` defaults to `[]` when the file omits it.
1363
+ */
1364
+ interface DeclarativeFileConfig {
1365
+ entities: EntityDeclaration[];
1366
+ consumers?: ConsumerDeclaration[];
1367
+ }
1368
+ interface LoadDeclarativeConfigFromStringOptions {
1369
+ format: DeclarativeFileFormat;
1370
+ /** Required for `format: 'yaml'`. The core has no YAML runtime dependency — pass a parser (e.g. `{ parse: YAML.parse }` from the `yaml` package). */
1371
+ yamlParser?: YamlParser;
1372
+ /** Optional label (e.g. a file path) included in error messages to help pinpoint the source. */
1373
+ source?: string;
1374
+ }
1375
+ interface LoadDeclarativeConfigFromFileOptions {
1376
+ /** Overrides the format that would otherwise be detected from the file extension. */
1377
+ format?: DeclarativeFileFormat;
1378
+ yamlParser?: YamlParser;
1379
+ }
1380
+ /** Parses and validates a declarative config from textual content. Does not perform I/O. */
1381
+ declare function loadDeclarativeConfigFromString(content: string, options: LoadDeclarativeConfigFromStringOptions): DeclarativeFileConfig;
1382
+ /** Reads, parses and validates a declarative config from a file path. Format is detected from the extension unless overridden. */
1383
+ declare function loadDeclarativeConfigFromFile(filePath: string, options?: LoadDeclarativeConfigFromFileOptions): Promise<DeclarativeFileConfig>;
1384
+
1358
1385
  declare const GOVERNANCE_EVENT_TYPES: {
1359
1386
  readonly OPERATION_EXECUTED: "governance.operation.executed";
1360
1387
  readonly AUTHORIZATION_DENIED: "governance.authorization.denied";
@@ -1428,4 +1455,4 @@ declare class DefaultGovernanceApi implements GovernanceApi {
1428
1455
  getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
1429
1456
  }
1430
1457
 
1431
- 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, 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 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 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 };
1458
+ 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, 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 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, loadDeclarativeConfigFromFile, loadDeclarativeConfigFromString, loadMaestroConfig, mergeIntrospectionWithOverrides, parseQueryInput, resolveConsumerProjections, tableNameToEntityId, tableNameToLabel, validateConsumerDeclaration, validateEntityDeclaration, validateMaestroConfig };
package/dist/index.js CHANGED
@@ -3292,6 +3292,125 @@ var InMemoryConfirmationRepository = class {
3292
3292
  }
3293
3293
  };
3294
3294
 
3295
+ // src/declarative/loader/DeclarativeFileLoader.ts
3296
+ import { readFile as readFile2 } from "fs/promises";
3297
+ import { extname as extname2 } from "path";
3298
+ var KNOWN_KEYS = /* @__PURE__ */ new Set(["entities", "consumers"]);
3299
+ function parseContent2(content, format, yamlParser, source) {
3300
+ const origin = source ? ` (${source})` : "";
3301
+ if (format === "yaml") {
3302
+ if (!yamlParser) {
3303
+ throw new MaestroError(
3304
+ "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */,
3305
+ `Cannot parse YAML declarative config${origin}: a "yamlParser" must be provided. The core has no bundled YAML dependency \u2014 install a YAML library (e.g. "yaml") and pass { yamlParser: { parse: YAML.parse } }.`
3306
+ );
3307
+ }
3308
+ try {
3309
+ return yamlParser.parse(content);
3310
+ } catch (cause) {
3311
+ throw new MaestroError(
3312
+ "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */,
3313
+ `Failed to parse YAML declarative config${origin}: ${cause.message}`,
3314
+ { cause }
3315
+ );
3316
+ }
3317
+ }
3318
+ try {
3319
+ return JSON.parse(content);
3320
+ } catch (cause) {
3321
+ throw new MaestroError(
3322
+ "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */,
3323
+ `Failed to parse JSON declarative config${origin}: ${cause.message}`,
3324
+ { cause }
3325
+ );
3326
+ }
3327
+ }
3328
+ function normalizeAndValidate(raw, source) {
3329
+ const origin = source ? ` in ${source}` : "";
3330
+ if (raw === null || raw === void 0) {
3331
+ return { entities: [] };
3332
+ }
3333
+ if (typeof raw !== "object" || Array.isArray(raw)) {
3334
+ throw new MaestroError(
3335
+ "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */,
3336
+ `Declarative config${origin} must be an object with optional "entities" and "consumers" arrays.`
3337
+ );
3338
+ }
3339
+ const obj = raw;
3340
+ const errors = [];
3341
+ for (const key of Object.keys(obj)) {
3342
+ if (!KNOWN_KEYS.has(key)) {
3343
+ errors.push({
3344
+ path: key,
3345
+ message: `Unknown declarative config key "${key}". Only "entities" and "consumers" are supported.`
3346
+ });
3347
+ }
3348
+ }
3349
+ let entities;
3350
+ if (obj["entities"] !== void 0) {
3351
+ if (!Array.isArray(obj["entities"])) {
3352
+ errors.push({ path: "entities", message: '"entities" must be an array of entity declarations.' });
3353
+ } else {
3354
+ entities = obj["entities"];
3355
+ entities.forEach((entity, index) => {
3356
+ const result = validateEntityDeclaration(entity);
3357
+ if (!result.valid) {
3358
+ for (const err of result.errors) {
3359
+ const path = err.path ? `entities[${index}].${err.path}` : `entities[${index}]`;
3360
+ errors.push({ path, message: err.message });
3361
+ }
3362
+ }
3363
+ });
3364
+ }
3365
+ }
3366
+ let consumers;
3367
+ if (obj["consumers"] !== void 0) {
3368
+ if (!Array.isArray(obj["consumers"])) {
3369
+ errors.push({ path: "consumers", message: '"consumers" must be an array of consumer declarations.' });
3370
+ } else {
3371
+ consumers = obj["consumers"];
3372
+ const entityByName = new Map((entities ?? []).map((entity) => [entity.entity, entity]));
3373
+ consumers.forEach((consumer, index) => {
3374
+ const relatedEntity = consumer && typeof consumer === "object" ? entityByName.get(consumer["entity"]) : void 0;
3375
+ const result = validateConsumerDeclaration(consumer, relatedEntity);
3376
+ if (!result.valid) {
3377
+ for (const err of result.errors) {
3378
+ const path = err.path ? `consumers[${index}].${err.path}` : `consumers[${index}]`;
3379
+ errors.push({ path, message: err.message });
3380
+ }
3381
+ }
3382
+ });
3383
+ }
3384
+ }
3385
+ if (errors.length > 0) {
3386
+ const details = errors.map((err) => `${err.path}: ${err.message}`).join("; ");
3387
+ throw new MaestroError(
3388
+ "VALIDATION_ERROR" /* VALIDATION_ERROR */,
3389
+ `Invalid declarative config${origin}: ${details}`,
3390
+ { details: { errors } }
3391
+ );
3392
+ }
3393
+ return { entities: entities ?? [], consumers };
3394
+ }
3395
+ function loadDeclarativeConfigFromString(content, options) {
3396
+ const raw = parseContent2(content, options.format, options.yamlParser, options.source);
3397
+ return normalizeAndValidate(raw, options.source);
3398
+ }
3399
+ function detectFormatFromExtension(filePath) {
3400
+ const ext = extname2(filePath).toLowerCase();
3401
+ if (ext === ".yaml" || ext === ".yml") return "yaml";
3402
+ if (ext === ".json") return "json";
3403
+ throw new MaestroError(
3404
+ "CONFIGURATION_ERROR" /* CONFIGURATION_ERROR */,
3405
+ `Cannot detect declarative config format from file extension "${ext}" (${filePath}). Supported extensions: .yaml, .yml, .json. Pass { format } explicitly to override.`
3406
+ );
3407
+ }
3408
+ async function loadDeclarativeConfigFromFile(filePath, options = {}) {
3409
+ const format = options.format ?? detectFormatFromExtension(filePath);
3410
+ const content = await readFile2(filePath, "utf-8");
3411
+ return loadDeclarativeConfigFromString(content, { format, yamlParser: options.yamlParser, source: filePath });
3412
+ }
3413
+
3295
3414
  // src/governance/GovernanceEventType.ts
3296
3415
  var GOVERNANCE_EVENT_TYPES = {
3297
3416
  OPERATION_EXECUTED: "governance.operation.executed",
@@ -3402,6 +3521,8 @@ export {
3402
3521
  isSearchCandidate,
3403
3522
  isSoftDeleteCandidate,
3404
3523
  isTimestampField,
3524
+ loadDeclarativeConfigFromFile,
3525
+ loadDeclarativeConfigFromString,
3405
3526
  loadMaestroConfig,
3406
3527
  mergeIntrospectionWithOverrides,
3407
3528
  parseQueryInput,