@shirudo/ddd-kit 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Composable TypeScript toolkit for tactical Domain-Driven Design.
4
4
 
5
+ > **⚠️ BETA WARNING**
6
+ >
7
+ > This library is currently in beta. The API is subject to change until a stable 1.0.0 release. Breaking changes may occur in minor versions during the beta phase. Please pin your dependencies to specific versions.
8
+
5
9
  ## Badges
6
10
 
7
11
  ![npm version](https://img.shields.io/npm/v/@shirudo/ddd-kit)
@@ -474,7 +478,7 @@ import {
474
478
  type CreateOrderCommand = Command & {
475
479
  type: "CreateOrder";
476
480
  customerId: string;
477
- items: Array<{ productId: string; quantity: number }>;
481
+ items: Array<{ productId: string; quantity: number; price: number }>;
478
482
  };
479
483
 
480
484
  // Create a command handler
@@ -487,7 +491,14 @@ const createOrderHandler: CommandHandler<CreateOrderCommand, string> = async (
487
491
  }
488
492
 
489
493
  // Perform business logic
490
- const order = Order.create(cmd.customerId, cmd.items);
494
+ const orderId = `order-${Date.now()}` as OrderId;
495
+ const order = Order.create(orderId, cmd.customerId);
496
+
497
+ // Add items to the order
498
+ for (const item of cmd.items) {
499
+ order.addItem(item.productId, item.quantity, item.price);
500
+ }
501
+
491
502
  await repository.save(order);
492
503
 
493
504
  return ok(order.id);
@@ -497,7 +508,7 @@ const createOrderHandler: CommandHandler<CreateOrderCommand, string> = async (
497
508
  const result = await createOrderHandler({
498
509
  type: "CreateOrder",
499
510
  customerId: "customer-123",
500
- items: [{ productId: "product-1", quantity: 2 }],
511
+ items: [{ productId: "product-1", quantity: 2, price: 10.0 }],
501
512
  });
502
513
 
503
514
  if (result.ok) {
@@ -514,7 +525,7 @@ commandBus.register("CreateOrder", createOrderHandler);
514
525
  const busResult = await commandBus.execute({
515
526
  type: "CreateOrder",
516
527
  customerId: "customer-123",
517
- items: [{ productId: "product-1", quantity: 2 }],
528
+ items: [{ productId: "product-1", quantity: 2, price: 10.0 }],
518
529
  });
519
530
  ```
520
531
 
@@ -584,7 +595,14 @@ const createOrderHandler: CommandHandler<CreateOrderCommand, string> = async (
584
595
  return await withCommit(
585
596
  { outbox, bus, uow },
586
597
  async () => {
587
- const order = Order.create(cmd.customerId, cmd.items);
598
+ const orderId = `order-${Date.now()}` as OrderId;
599
+ const order = Order.create(orderId, cmd.customerId);
600
+
601
+ // Add items to the order
602
+ for (const item of cmd.items) {
603
+ order.addItem(item.productId, item.quantity, item.price);
604
+ }
605
+
588
606
  await repository.save(order);
589
607
 
590
608
  return {
@@ -622,7 +640,7 @@ import {
622
640
  type CreateOrderCommand = Command & {
623
641
  type: "CreateOrder";
624
642
  customerId: string;
625
- items: OrderItem[];
643
+ items: Array<{ productId: string; quantity: number; price: number }>;
626
644
  };
627
645
 
628
646
  type GetOrderQuery = Query & {
@@ -634,7 +652,14 @@ type GetOrderQuery = Query & {
634
652
  const createOrderHandler: CommandHandler<CreateOrderCommand, OrderId> = async (
635
653
  cmd
636
654
  ) => {
637
- const order = Order.create(cmd.customerId, cmd.items);
655
+ const orderId = `order-${Date.now()}` as OrderId;
656
+ const order = Order.create(orderId, cmd.customerId);
657
+
658
+ // Add items to the order
659
+ for (const item of cmd.items) {
660
+ order.addItem(item.productId, item.quantity, item.price);
661
+ }
662
+
638
663
  await repository.save(order);
639
664
  return ok(order.id);
640
665
  };