@swoft/platform-contracts
Version:
DDD-compliant dependency injection contracts for Swoft platform - Defines clean architecture boundaries
115 lines (101 loc) • 4.33 kB
text/typescript
/**
* Contract Registry - Single Source of Truth
*
* Central registry that aggregates all DI contracts across layers.
* This provides a single import point for all dependency injection symbols,
* ensuring consistency and preventing symbol duplication.
*
* Usage:
* ```typescript
* import { CONTRACTS } from '@swoft/platform-contracts';
*
* @inject(CONTRACTS.INFRASTRUCTURE.MONGO_CLIENT)
* @inject(CONTRACTS.DOMAIN.SCHEMA_REPOSITORY)
* @inject(CONTRACTS.APPLICATION.CAS_SERVICE)
* ```
*/
import { INFRASTRUCTURE_CONTRACTS } from './infrastructure';
import { DOMAIN_CONTRACTS, DOMAIN_SERVICE_CONTRACTS } from './domain';
import { APPLICATION_CONTRACTS, CQRS_CONTRACTS, USE_CASE_CONTRACTS } from './application';
import { LOGGING_CONTRACTS, SECURITY_CONTRACTS, CONFIGURATION_CONTRACTS } from './shared';
// ============================================
// UNIFIED CONTRACT REGISTRY
// ============================================
/**
* The CONTRACTS registry - single source of truth for all DI symbols
*
* Organized by architectural layer following DDD principles:
* - INFRASTRUCTURE: External adapters (databases, APIs, file systems)
* - DOMAIN: Core business logic ports (repositories, domain services)
* - APPLICATION: Use cases and application services
* - SHARED: Cross-cutting concerns (logging, security, config)
*/
export const CONTRACTS = {
// Infrastructure Layer (External dependencies)
INFRASTRUCTURE: INFRASTRUCTURE_CONTRACTS,
// Domain Layer (Business logic ports)
DOMAIN: {
REPOSITORIES: DOMAIN_CONTRACTS,
SERVICES: DOMAIN_SERVICE_CONTRACTS,
},
// Application Layer (Use cases and orchestration)
APPLICATION: {
SERVICES: APPLICATION_CONTRACTS,
CQRS: CQRS_CONTRACTS,
USE_CASES: USE_CASE_CONTRACTS,
},
// Shared Layer (Cross-cutting concerns)
SHARED: {
LOGGING: LOGGING_CONTRACTS,
SECURITY: SECURITY_CONTRACTS,
CONFIGURATION: CONFIGURATION_CONTRACTS,
},
} as const;
// ============================================
// LEGACY COMPATIBILITY EXPORTS
// ============================================
/**
* Legacy exports for backward compatibility during migration
* TODO: Remove after all packages are migrated to CONTRACTS registry
*
* @deprecated Use CONTRACTS.INFRASTRUCTURE.* instead
*/
export const DI_MONGO_CLIENT = CONTRACTS.INFRASTRUCTURE.MONGO_CLIENT;
export const DI_DATABASE_NAME = CONTRACTS.INFRASTRUCTURE.DATABASE_NAME;
export const DI_MONGO_CONNECTION_STRING = CONTRACTS.INFRASTRUCTURE.MONGO_CONNECTION_STRING;
/**
* @deprecated Use CONTRACTS.DOMAIN.REPOSITORIES.* instead
*/
export const DI_SCHEMA_REPOSITORY = CONTRACTS.DOMAIN.REPOSITORIES.SCHEMA_REPOSITORY;
export const DI_DOCUMENTATION_REPOSITORY = CONTRACTS.DOMAIN.REPOSITORIES.DOCUMENTATION_REPOSITORY;
/**
* @deprecated Use CONTRACTS.APPLICATION.SERVICES.* instead
*/
export const DI_CAS_SERVICE = CONTRACTS.APPLICATION.SERVICES.CAS_SERVICE;
export const DI_SERVICE_MANAGER = CONTRACTS.APPLICATION.SERVICES.SERVICE_MANAGER;
// ============================================
// TYPE UTILITIES
// ============================================
/**
* Extract all contract symbols as a union type
* Useful for type-safe container registration
*/
export type AllContracts =
| (typeof CONTRACTS.INFRASTRUCTURE)[keyof typeof CONTRACTS.INFRASTRUCTURE]
| (typeof CONTRACTS.DOMAIN.REPOSITORIES)[keyof typeof CONTRACTS.DOMAIN.REPOSITORIES]
| (typeof CONTRACTS.DOMAIN.SERVICES)[keyof typeof CONTRACTS.DOMAIN.SERVICES]
| (typeof CONTRACTS.APPLICATION.SERVICES)[keyof typeof CONTRACTS.APPLICATION.SERVICES]
| (typeof CONTRACTS.APPLICATION.CQRS)[keyof typeof CONTRACTS.APPLICATION.CQRS]
| (typeof CONTRACTS.APPLICATION.USE_CASES)[keyof typeof CONTRACTS.APPLICATION.USE_CASES]
| (typeof CONTRACTS.SHARED.LOGGING)[keyof typeof CONTRACTS.SHARED.LOGGING]
| (typeof CONTRACTS.SHARED.SECURITY)[keyof typeof CONTRACTS.SHARED.SECURITY]
| (typeof CONTRACTS.SHARED.CONFIGURATION)[keyof typeof CONTRACTS.SHARED.CONFIGURATION];
/**
* Contract metadata for documentation and tooling
*/
export const CONTRACT_METADATA = {
version: '1.0.0',
totalContracts: Object.keys(CONTRACTS).length,
layers: ['INFRASTRUCTURE', 'DOMAIN', 'APPLICATION', 'SHARED'] as const,
description: 'DDD-compliant dependency injection contracts for Swoft platform',
} as const;