Runtime library for DDD components generated by @ddd-components/scaffolder
npm install @ddd-components/runtimeA runtime library providing shared utilities for Domain-Driven Design (DDD) components generated by the mcp4ddd MCP server.
This package contains essential types and functions used by DDD components to ensure consistent error handling, type safety, and workflow management across your domain models.
#### Types
- SingleError: Represents a single error with a specific error code and message
- ValidationError: Represents validation errors with an array of error messages
- TechError: A specialized single error for technical issues
#### Functions
- singleError: Creates a SingleError with the given code and message(code, message)
- validationError(messages): Creates a ValidationError from an array of error messages
- zodValidationError(error): Converts a Zod validation error to a ValidationError
- techError(message): Creates a technical error with the message
#### Types
- Branded: A branded type that adds a unique brand to prevent mixing incompatible types at compile time
#### Constants
- dynamoDBClientConfiguration: Client configuration for DynamoDB, automatically configured for local development if AWS_ENDPOINT_URL_DYNAMODB is set
- documentClientConfig: Document client configuration with marshalling options optimized for ElectroDB
#### Functions
- beginWith: Starts an asynchronous result workflow with the given value, returning an AsyncResult. This is the entry point for functional error handling patterns using the ts-results-es library.
- safeAsync: Wraps an async function to return a Result type, converting exceptions to TechError. Allows async operations to be composed using the Result monad pattern.
``typescript
import {
singleError,
validationError,
techError,
beginWith,
safeAsync,
type Branded,
dynamoDBClientConfiguration
} from '@ddd-components/runtime';
// Error handling
const error = singleError('not-found', 'Item not found');
// Type branding for domain safety
type UserId = Branded
// Workflow starting
const result = await beginWith(initialParameters)
.andThen(processStep)
.andThen(anotherStep);
// Using safeAsync in a workflow chain for a step that might throw
const resultWithAsync = await beginWith(initialParameters)
.andThen((params) => safeAsync(() => fetchData(params)))
.andThen(processData);
`
- ts-results-es: For functional error handlingzod`: For schema validation (used in error conversion)
-
MIT