diff --git a/bun.lockb b/bun.lockb index c9c934d..1877527 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/common/src/lib/errors.ts b/common/src/lib/errors.ts index d614ba8..8d5592f 100644 --- a/common/src/lib/errors.ts +++ b/common/src/lib/errors.ts @@ -1,4 +1,4 @@ import { entity } from '@deepkit/type'; -@entity.name('@error/unsupported-state-transition-exception') +@entity.name('@error/UnsupportedStateTransitionException') export class UnsupportedStateTransitionException extends Error {} diff --git a/customer-service-api/src/lib/replies.ts b/customer-service-api/src/lib/replies.ts index 188437b..022e4a3 100644 --- a/customer-service-api/src/lib/replies.ts +++ b/customer-service-api/src/lib/replies.ts @@ -1,17 +1,20 @@ -import { UUID } from '@deepkit/type'; +import { entity, UUID } from '@deepkit/type'; +@entity.name('@error/CustomerNotFound') export class CustomerNotFound extends Error { constructor(public readonly id: UUID) { super(); } } +@entity.name('@error/CustomerVerificationFailed') export class CustomerVerificationFailed extends Error { constructor(public readonly id: UUID) { super(); } } +@entity.name('@error/CustomerDisabled') export class CustomerDisabled extends Error { constructor(public readonly id: UUID) { super(); diff --git a/customer-service/src/customer.service.ts b/customer-service/src/customer.service.ts index c2c022b..d8dae5a 100644 --- a/customer-service/src/customer.service.ts +++ b/customer-service/src/customer.service.ts @@ -1,5 +1,5 @@ import { restate, RestateEventsPublisher } from 'deepkit-restate'; -import { cast, Email, float, UUID } from '@deepkit/type'; +import { cast, Email, UUID } from '@deepkit/type'; import { Money, PersonName } from '@ftgo/common'; import { diff --git a/kitchen-service-api/src/lib/replies.ts b/kitchen-service-api/src/lib/replies.ts index 22dbae9..b7b2a5d 100644 --- a/kitchen-service-api/src/lib/replies.ts +++ b/kitchen-service-api/src/lib/replies.ts @@ -1,7 +1,10 @@ -import { UUID } from '@deepkit/type'; +import { entity, UUID } from '@deepkit/type'; -export class TicketNotFound { - constructor(public readonly ticketId: UUID) {} +@entity.name('@error/TicketNotFound') +export class TicketNotFound extends Error { + constructor(public readonly ticketId: UUID) { + super(); + } } export class TicketConfirmed { diff --git a/kitchen-service-api/src/lib/services.ts b/kitchen-service-api/src/lib/services.ts index 7db8865..f21ef8b 100644 --- a/kitchen-service-api/src/lib/services.ts +++ b/kitchen-service-api/src/lib/services.ts @@ -1,7 +1,7 @@ import { RestateService } from 'deepkit-restate'; import { UUID } from '@deepkit/type'; -import { TicketCreated, TicketNotFound } from './replies'; +import { TicketCreated } from './replies'; import { TicketDetails } from './types'; export interface KitchenServiceHandlers { @@ -20,6 +20,5 @@ export interface KitchenServiceHandlers { export type KitchenServiceApi = RestateService< 'Kitchen', - KitchenServiceHandlers, - [TicketNotFound] + KitchenServiceHandlers >; diff --git a/order-service-api/src/index.ts b/order-service-api/src/index.ts index 810f716..2d49cea 100644 --- a/order-service-api/src/index.ts +++ b/order-service-api/src/index.ts @@ -3,3 +3,4 @@ export * from './lib/entities'; export * from './lib/replies'; export * from './lib/sagas'; export * from './lib/services'; +export * from './lib/events'; diff --git a/order-service-api/src/lib/replies.ts b/order-service-api/src/lib/replies.ts index d551011..05dc2c5 100644 --- a/order-service-api/src/lib/replies.ts +++ b/order-service-api/src/lib/replies.ts @@ -2,20 +2,19 @@ import { entity, UUID } from '@deepkit/type'; import { LineItemQuantityChange, OrderRevision } from './entities'; +@entity.name('@error/OrderMinimumNotMet') export class OrderMinimumNotMet extends Error {} +@entity.name('@error/OrderLineItemNotFound') export class OrderLineItemNotFound extends Error {} +@entity.name('@error/OrderNotFound') export class OrderNotFound extends Error { constructor(public readonly orderId: UUID) { super(); } } -export class OrderCreatedEvent { - constructor(public readonly orderId: UUID) {} -} - export class OrderApproved {} export class OrderRejected {} diff --git a/order-service-api/src/lib/services.ts b/order-service-api/src/lib/services.ts index ad4afc5..2b993f2 100644 --- a/order-service-api/src/lib/services.ts +++ b/order-service-api/src/lib/services.ts @@ -4,12 +4,7 @@ import { UUID } from '@deepkit/type'; import { RestaurantCreatedEvent } from '@ftgo/restaurant-service-api'; import { OrderDetails } from './entities'; -import { - OrderApproved, - OrderMinimumNotMet, - OrderNotFound, - OrderRejected, -} from './replies'; +import { OrderApproved, OrderRejected } from './replies'; export interface OrderServiceHandlers { create(orderId: UUID, details: OrderDetails): Promise; @@ -24,8 +19,4 @@ export interface OrderServiceHandlers { reviseMenu(event: RestaurantCreatedEvent): Promise; } -export type OrderServiceApi = RestateService< - 'Order', - OrderServiceHandlers, - [OrderNotFound, OrderMinimumNotMet] ->; +export type OrderServiceApi = RestateService<'Order', OrderServiceHandlers>; diff --git a/order-service/src/order.service.ts b/order-service/src/order.service.ts index 15b64bf..a04921f 100644 --- a/order-service/src/order.service.ts +++ b/order-service/src/order.service.ts @@ -1,10 +1,9 @@ -import { restate, RestateEventsPublisher } from 'deepkit-restate'; +import { restate } from 'deepkit-restate'; import { UUID } from '@deepkit/type'; import { RestaurantCreatedEvent } from '@ftgo/restaurant-service-api'; import { OrderApproved, - OrderCreatedEvent, OrderDetails, OrderRejected, OrderServiceApi, @@ -15,10 +14,7 @@ import { OrderRepository } from './order.repository'; @restate.service() export class OrderService implements OrderServiceHandlers { - constructor( - private readonly order: OrderRepository, - private readonly events: RestateEventsPublisher, - ) {} + constructor(private readonly order: OrderRepository) {} // @ts-expect-error invalid number of arguments @(restate.event().handler()) @@ -79,9 +75,6 @@ export class OrderService implements OrderServiceHandlers { restaurantId, lineItems, ); - await this.events.publish<[OrderCreatedEvent]>([ - new OrderCreatedEvent(order.id), - ]); return order.id; } } diff --git a/package.json b/package.json index 6b41f03..40d62ca 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@deepkit/sql": "^1.0.1-alpha.153", "@deepkit/type": "^1.0.1-alpha.153", "@restatedev/restate-sdk": "1.2.1", - "deepkit-restate": "0.0.70", + "deepkit-restate": "0.0.71", "kafkajs": "2.2.4", "stripe": "^16.8.0", "tslib": "2.6.3" diff --git a/payment-service-api/src/lib/replies.ts b/payment-service-api/src/lib/replies.ts index b835bf4..3bc9a16 100644 --- a/payment-service-api/src/lib/replies.ts +++ b/payment-service-api/src/lib/replies.ts @@ -8,6 +8,7 @@ export class PaymentAuthorizationReversed { constructor(public readonly paymentId: UUID) {} } +@entity.name('@error/PaymentAuthorizationFailed') export class PaymentAuthorizationFailed extends Error { constructor( public readonly customerId: UUID, @@ -17,12 +18,14 @@ export class PaymentAuthorizationFailed extends Error { } } +@entity.name('@error/PaymentNotFound') export class PaymentNotFound extends Error { constructor(public readonly paymentId: UUID) { super(); } } +@entity.name('@error/PaymentCustomerNotFound') export class PaymentCustomerNotFound extends Error { constructor(public readonly customerId: UUID) { super(); diff --git a/payment-service-api/src/lib/services.ts b/payment-service-api/src/lib/services.ts index 41c5070..7485381 100644 --- a/payment-service-api/src/lib/services.ts +++ b/payment-service-api/src/lib/services.ts @@ -1,14 +1,10 @@ import { RestateService } from 'deepkit-restate'; -import { float, UUID } from '@deepkit/type'; +import { UUID } from '@deepkit/type'; import { Money } from '@ftgo/common'; import { PaymentCustomer } from './entities'; -import { - PaymentAuthorizationFailed, - PaymentAuthorized, - PaymentCustomerNotFound, -} from './replies'; +import { PaymentAuthorized } from './replies'; export interface PaymentServiceHandlers { authorize( @@ -22,6 +18,5 @@ export interface PaymentServiceHandlers { export type PaymentServiceApi = RestateService< 'Payment', - PaymentServiceHandlers, - [PaymentAuthorizationFailed, PaymentCustomerNotFound] + PaymentServiceHandlers >;