Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions .github/workflows/runtime-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,42 @@ jobs:
node_modules
oclif.manifest.json

typescript:
name: Runtime Testing TypeScript
typescript-runtime-tests:
name: Runtime Testing TypeScript - ${{ matrix.test-type }}
runs-on: ubuntu-latest
needs: 'build'
strategy:
fail-fast: false
matrix:
include:
- test-type: 'Kafka'
service: 'kafka'
test-command: 'test:kafka'
needs-service: true
- test-type: 'NATS'
service: 'nats'
test-command: 'test:nats'
needs-service: true
- test-type: 'MQTT'
service: 'mqtt'
test-command: 'test:mqtt'
needs-service: true
- test-type: 'AMQP'
service: 'amqp'
test-command: 'test:amqp'
needs-service: true
- test-type: 'EventSource'
service: ''
test-command: 'test:eventsource'
needs-service: false
- test-type: 'HTTP'
service: ''
test-command: 'test:http'
needs-service: false
- test-type: 'Regular Tests'
service: ''
test-command: 'test:regular'
needs-service: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -53,7 +85,13 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: "${{ steps.lockversion.outputs.version }}"
- name: Setup for runtime test
run: npm run runtime:typescript:setup
- name: Run runtime tests
run: npm run runtime:typescript:test
- name: Setup for runtime test
run: |
npm run runtime:prepare
${{ matrix.needs-service == true && format('npm run runtime:{0}:start', matrix.service) || '' }}
npm run runtime:typescript:generate
- name: Run ${{ matrix.test-type }} runtime tests
run: cd test/runtime/typescript && npm run ${{ matrix.test-command }}
- name: Stop ${{ matrix.service }} services
if: always() && matrix.needs-service == true
run: npm run runtime:${{ matrix.service }}:stop
38 changes: 38 additions & 0 deletions examples/ecommerce-asyncapi-channels/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# E-commerce Order Lifecycle Events
A focused example showing how to generate protocol-specific messaging functions from AsyncAPI specifications for order lifecycle management in an e-commerce system.

**Files:**
- `ecommerce-event-channels.yaml` - AsyncAPI specification with order lifecycle channel definitions, operations, and parameterized routing
- `codegen.config.js` - Configuration for generating protocol-specific messaging functions
- `src/index.ts` - Demo script showing order lifecycle event patterns
- `src/generated` - All the generated files

**Features demonstrated:**
- Protocol-specific functions for NATS and Kafka
- Order lifecycle events (created, updated, cancelled, shipped, delivered)
- Parameterized channel addresses (orders.{action})
- Operation-based function generation
- Type-safe order event publishing and subscription
- Comprehensive order data modeling (items, addresses, money)
- Multi-protocol support (NATS for real-time, Kafka for analytics)
- Automatic parameter handling and message validation
- Order workflow orchestration patterns

**Order Lifecycle Flow:**
- `OrderCreated` - New order placed by customer
- `OrderUpdated` - Order status changes (pending → processing → shipped → delivered)
- `OrderCancelled` - Order cancelled with refund processing

**Usage:**
```bash
# Install dependencies
npm install

# Generate protocol-specific functions
npm run generate

# Run the order lifecycle demo
npm run demo
```

The generated protocol functions provide type-safe order event handling with automatic parameter substitution for channel addressing and comprehensive order data validation.
12 changes: 12 additions & 0 deletions examples/ecommerce-asyncapi-channels/codegen.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
inputType: 'asyncapi',
inputPath: './ecommerce-event-channels.yaml',
generators: [
{
preset: 'channels',
outputPath: './src/generated',
language: 'typescript',
protocols: ['nats', 'kafka']
}
]
};
212 changes: 212 additions & 0 deletions examples/ecommerce-asyncapi-channels/ecommerce-event-channels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
asyncapi: 3.0.0
info:
title: E-commerce Order Lifecycle Events
version: 1.0.0
description: Event-driven order management system with comprehensive lifecycle tracking

channels:
# Order Management Channels
order-lifecycle:
address: orders.{action}
parameters:
action:
$ref: '#/components/parameters/OrderAction'
messages:
OrderCreated:
$ref: '#/components/messages/OrderCreated'
OrderUpdated:
$ref: '#/components/messages/OrderUpdated'
OrderCancelled:
$ref: '#/components/messages/OrderCancelled'

operations:
# Order Management Operations
publishOrderCreated:
action: send
channel:
$ref: '#/channels/order-lifecycle'
messages:
- $ref: '#/channels/order-lifecycle/messages/OrderCreated'

publishOrderUpdated:
action: send
channel:
$ref: '#/channels/order-lifecycle'
messages:
- $ref: '#/channels/order-lifecycle/messages/OrderUpdated'

publishOrderCancelled:
action: send
channel:
$ref: '#/channels/order-lifecycle'
messages:
- $ref: '#/channels/order-lifecycle/messages/OrderCancelled'

subscribeToOrderEvents:
action: receive
channel:
$ref: '#/channels/order-lifecycle'
messages:
- $ref: '#/channels/order-lifecycle/messages/OrderCreated'
- $ref: '#/channels/order-lifecycle/messages/OrderUpdated'
- $ref: '#/channels/order-lifecycle/messages/OrderCancelled'

components:
# Reusable Parameters
parameters:
OrderAction:
enum: [created, updated, cancelled, shipped, delivered]
description: Order lifecycle action

# Reusable Messages
messages:
OrderCreated:
name: OrderCreated
title: Order Created Event
summary: Published when a new order is created
payload:
$ref: '#/components/schemas/OrderCreatedPayload'
headers:
$ref: '#/components/schemas/OrderHeaders'

OrderUpdated:
name: OrderUpdated
title: Order Updated Event
summary: Published when order details are modified
payload:
$ref: '#/components/schemas/OrderUpdatedPayload'
headers:
$ref: '#/components/schemas/OrderHeaders'

OrderCancelled:
name: OrderCancelled
title: Order Cancelled Event
summary: Published when an order is cancelled
payload:
$ref: '#/components/schemas/OrderCancelledPayload'
headers:
$ref: '#/components/schemas/OrderHeaders'

schemas:
# Order Payload Schemas
OrderCreatedPayload:
type: object
required: [orderId, customerId, items, totalAmount]
properties:
orderId:
type: string
format: uuid
customerId:
type: string
format: uuid
items:
type: array
items:
$ref: '#/components/schemas/OrderItem'
totalAmount:
$ref: '#/components/schemas/Money'
shippingAddress:
$ref: '#/components/schemas/Address'
createdAt:
type: string
format: date-time

OrderUpdatedPayload:
type: object
required: [orderId, status, updatedAt]
properties:
orderId:
type: string
format: uuid
status:
$ref: '#/components/schemas/OrderStatus'
updatedAt:
type: string
format: date-time
reason:
type: string
updatedFields:
type: array
items:
type: string

OrderStatus:
type: string
enum: [pending, confirmed, processing, shipped, delivered, cancelled]
OrderCancelledPayload:
type: object
required: [orderId, reason, cancelledAt]
properties:
orderId:
type: string
format: uuid
reason:
type: string
cancelledAt:
type: string
format: date-time
refundAmount:
$ref: '#/components/schemas/Money'

# Order Header Schema
OrderHeaders:
type: object
required: [x-correlation-id, x-order-id, x-customer-id]
properties:
x-correlation-id:
type: string
format: uuid
x-order-id:
type: string
format: uuid
x-customer-id:
type: string
format: uuid
x-source-service:
type: string

# Supporting Schemas
OrderItem:
type: object
required: [productId, quantity, unitPrice]
properties:
productId:
type: string
format: uuid
quantity:
type: integer
minimum: 1
unitPrice:
$ref: '#/components/schemas/Money'
productName:
type: string
productCategory:
type: string

Money:
type: object
required: [amount, currency]
properties:
amount:
type: integer
minimum: 0
description: Amount in smallest currency unit (e.g., cents for USD)
currency:
$ref: '#/components/schemas/Currency'
Currency:
type: string
enum: [USD, EUR, GBP]
Address:
type: object
required: [street, city, country, postalCode]
properties:
street:
type: string
city:
type: string
state:
type: string
country:
type: string
postalCode:
type: string
Loading