npm package: @noukha-technologies/mdm-core
Description: Core MDM functionality for group, schema, and record management
Author: Noukha
Latest version: 1.0.8

# @noukha/mdm-core

Core MDM (Master Data Management) functionality for groups, schemas, and records management.

## Installation

```bash
npm install @noukha/mdm-core
```

## Features

- **Group Management**: Create, read, update, and delete groups
- **Schema Management**: Dynamic schema creation and management
- **Record Management**: CRUD operations for dynamic records
- **Master Data Relationships**: Support for master data relationships
- **Bulk Operations**: Bulk create, update, and delete operations
- **Pagination**: Built-in pagination support
- **Search**: Full-text search capabilities
- **Validation**: Comprehensive data validation

## Quick Start

### 1. Import the Module

```typescript
import { MdmCoreModule } from '@noukha/mdm-core';

@Module({
  imports: [
    MdmCoreModule.forRoot({
      database: {
        connectionString: 'mongodb://localhost:27017/mdm'
      },
      schema: {
        collectionName: 'schemas',
        cacheEnabled: true,
        autoCreateCollections: true
      },
      logging: {
        enabled: true,
        level: 'info'
      }
    })
  ]
})
export class AppModule {}
```

### 2. Use the Services

```typescript
import { GroupService, SchemaService, RecordService } from '@noukha/mdm-core';

@Injectable()
export class MyService {
  constructor(
    private readonly groupService: GroupService,
    private readonly schemaService: SchemaService,
    private readonly recordService: RecordService
  ) {}

  async createGroup() {
    return await this.groupService.create({
      groupName: 'products',
      displayName: 'Products'
    });
  }

  async createSchema() {
    return await this.schemaService.createSchema({
      name: 'product',
      displayName: 'Product',
      fields: [
        {
          name: 'name',
          type: FieldType.STRING,
          required: true,
          unique: true
        },
        {
          name: 'price',
          type: FieldType.NUMBER,
          required: true
        }
      ]
    });
  }

  async createRecord() {
    return await this.recordService.createRecord('product', {
      data: {
        name: 'Sample Product',
        price: 99.99
      }
    });
  }
}
```

## API Reference

### GroupService

- `create(createGroupDto: CreateGroupDto): Promise<Group>`
- `findAll(): Promise<Group[]>`
- `findOne(groupId: string): Promise<Group>`
- `update(groupId: string, updateGroupDto: UpdateGroupDto): Promise<Group>`
- `remove(groupId: string): Promise<void>`

### SchemaService

- `createSchema(createSchemaDto: CreateSchemaDto): Promise<any>`
- `getSchema(schemaName: string): Promise<CreateSchemaDto>`
- `getAllSchemas(query: FindSchemasQueryDto): Promise<PaginatedResponse<CreateSchemaDto>>`
- `deleteSchema(schemaName: string, force?: boolean): Promise<any>`
- `getSchemasByGroupId(groupId: string): Promise<CreateSchemaDto[]>`

### RecordService

- `createRecord(schemaName: string, createRecordDto: CreateRecordDto): Promise<any>`
- `findAll(schemaName: string, query: FindRecordsQueryDto): Promise<PaginatedResponse<any>>`
- `findOne(schemaName: string, id: string): Promise<any>`
- `updateRecord(schemaName: string, id: string, updateRecordDto: UpdateRecordDto): Promise<any>`
- `removeRecord(schemaName: string, id: string): Promise<any>`
- `bulkCreate(schemaName: string, records: CreateRecordDto[]): Promise<any[]>`
- `bulkUpdate(schemaName: string, updates: Array<{ id: string; data: any }>): Promise<any>`
- `bulkDelete(schemaName: string, ids: string[]): Promise<any>`

## Field Types

- `STRING`: Text data
- `NUMBER`: Numeric data
- `BOOLEAN`: True/false values
- `DATE`: Date and time values
- `OBJECT`: Complex objects
- `ARRAY`: Arrays of data
- `MASTER`: References to other schemas

## Relationship Types

- `ONE_TO_ONE`: Single reference to another record
- `ONE_TO_MANY`: Array of references from one record
- `MANY_TO_ONE`: Single reference from multiple records
- `MANY_TO_MANY`: Array of references from multiple records

## Configuration

```typescript
interface MdmConfig {
  database?: {
    connectionString?: string;
    host?: string;
    port?: number;
    database?: string;
    username?: string;
    password?: string;
  };
  schema?: {
    collectionName?: string;
    cacheEnabled?: boolean;
    autoCreateCollections?: boolean;
  };
  logging?: {
    enabled?: boolean;
    level?: 'debug' | 'info' | 'warn' | 'error';
  };
}
```

## License

MIT