arvo-core
Version:
The core Arvo package which provides application tier core primitives and contract system for building production-grade event-driven application. Provides ArvoEvent (CloudEvents-compliant), ArvoContract for type-safe service interfaces, event factories, O
57 lines (56 loc) • 2.01 kB
TypeScript
import type { z } from 'zod';
import type { ArvoSemanticVersion } from '../../types';
import type { SimpleArvoContract } from './types';
/**
* Creates an ArvoContract with standardized naming conventions and a simplified event pattern.
* Use this to create contracts with one emit type only.
*
* @param param - Contract configuration
* @param param.uri - Contract identifier URI
* @param param.type - Base event type (will be prefixed with "com.")
* @param param.versions - Version-specific schema definitions
* @param param.metadata - Optional metadata for the contract
* @param param.description - Optional contract description
*
* @returns ArvoContract with standardized type formatting and metadata
*
* @throws {Error} If any of the validations in {@link ArvoContract} or {@link createArvoContract} fail
*
* @example
* ```typescript
* const contract = createSimpleArvoContract({
* uri: 'api.example/contracts/user',
* type: 'user.create',
* description: 'User creation contract',
* versions: {
* '1.0.0': {
* accepts: z.object({
* name: z.string(),
* email: z.string().email()
* }),
* emits: z.object({
* userId: z.string(),
* timestamp: z.date()
* })
* }
* }
* });
* ```
*
* @remarks
* Provides a simplified contract creation pattern with standardized conventions:
* - Automatically prefixes accept types with "com."
* - Creates a single emit type with "evt." prefix and ".success" suffix
* - Adds standard metadata identifying it as a SimpleArvoContract
*/
export declare const createSimpleArvoContract: <TUri extends string, TType extends string, TVersions extends Record<ArvoSemanticVersion, {
accepts: z.ZodTypeAny;
emits: z.ZodTypeAny;
}>, TMetaData extends Record<string, any>>(param: {
uri: TUri;
type: TType;
versions: TVersions;
domain?: string;
metadata?: TMetaData;
description?: string;
}) => SimpleArvoContract<TUri, TType, TVersions, TMetaData>;