more changes
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -2,88 +2,141 @@ syntax = "proto3";
|
||||
|
||||
package messages;
|
||||
|
||||
option go_package = ".;messages";
|
||||
option go_package = "git.tornberg.me/go-cart-actor/proto;messages";
|
||||
import "messages.proto";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Cart Actor gRPC API (Envelope Variant)
|
||||
// Cart Actor gRPC API (oneof Envelope Variant)
|
||||
// -----------------------------------------------------------------------------
|
||||
// This service replaces the legacy custom TCP frame protocol used on port 1337.
|
||||
// It keeps the existing per-mutation proto messages (defined in messages.proto)
|
||||
// serialized into an opaque `bytes payload` field for minimal refactor cost.
|
||||
// The numeric values in MutationType MUST match the legacy message type
|
||||
// constants (see message-types.go) so persisted event logs replay correctly.
|
||||
// This version removes the legacy numeric MutationType enum + raw bytes payload
|
||||
// approach and replaces it with a strongly typed oneof envelope. Each concrete
|
||||
// mutation proto is embedded directly, enabling:
|
||||
// * Type-safe routing server-side (simple type switch on the oneof).
|
||||
// * Direct persistence of MutationEnvelope messages (no custom binary header).
|
||||
// * Elimination of the legacy message handler registry.
|
||||
//
|
||||
// NOTE: Regenerate Go code after editing:
|
||||
// protoc --go_out=. --go_opt=paths=source_relative \
|
||||
// --go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||
// proto/cart_actor.proto proto/messages.proto
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// MutationType corresponds 1:1 with the legacy uint16 message type constants.
|
||||
enum MutationType {
|
||||
MUTATION_TYPE_UNSPECIFIED = 0;
|
||||
MUTATION_ADD_REQUEST = 1;
|
||||
MUTATION_ADD_ITEM = 2;
|
||||
// (3 was unused / reserved in legacy framing)
|
||||
MUTATION_REMOVE_ITEM = 4;
|
||||
MUTATION_REMOVE_DELIVERY = 5;
|
||||
MUTATION_CHANGE_QUANTITY = 6;
|
||||
MUTATION_SET_DELIVERY = 7;
|
||||
MUTATION_SET_PICKUP_POINT = 8;
|
||||
MUTATION_CREATE_CHECKOUT_ORDER = 9;
|
||||
MUTATION_SET_CART_ITEMS = 10;
|
||||
MUTATION_ORDER_COMPLETED = 11;
|
||||
// MutationEnvelope carries exactly one mutation plus metadata.
|
||||
// client_timestamp:
|
||||
// - Optional Unix timestamp provided by the client.
|
||||
// - If zero the server MAY overwrite with its local time.
|
||||
message MutationEnvelope {
|
||||
string cart_id = 1;
|
||||
int64 client_timestamp = 2;
|
||||
|
||||
oneof mutation {
|
||||
AddRequest add_request = 10;
|
||||
AddItem add_item = 11;
|
||||
RemoveItem remove_item = 12;
|
||||
RemoveDelivery remove_delivery = 13;
|
||||
ChangeQuantity change_quantity = 14;
|
||||
SetDelivery set_delivery = 15;
|
||||
SetPickupPoint set_pickup_point = 16;
|
||||
CreateCheckoutOrder create_checkout_order = 17;
|
||||
SetCartRequest set_cart_items = 18;
|
||||
OrderCreated order_completed = 19;
|
||||
}
|
||||
}
|
||||
|
||||
// MutationRequest is an envelope:
|
||||
// - cart_id: string form of CartId (legacy 16-byte array truncated/padded).
|
||||
// - type: mutation kind (see enum).
|
||||
// - payload: serialized underlying proto message (AddRequest, AddItem, etc.).
|
||||
// - client_timestamp: optional unix timestamp; server sets if zero.
|
||||
message MutationRequest {
|
||||
string cart_id = 1;
|
||||
MutationType type = 2;
|
||||
bytes payload = 3;
|
||||
int64 client_timestamp = 4;
|
||||
}
|
||||
|
||||
// MutationReply returns a status code (legacy semantics) plus a JSON payload
|
||||
// representing the full cart state (or an error message if non-200).
|
||||
// MutationReply returns a legacy-style status code plus a JSON payload
|
||||
// holding either the updated cart state (on success) or an error string.
|
||||
message MutationReply {
|
||||
int32 status_code = 1;
|
||||
bytes payload = 2; // JSON cart state or error string
|
||||
|
||||
// Exactly one of state or error will be set.
|
||||
oneof result {
|
||||
CartState state = 2;
|
||||
string error = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// StateRequest fetches current cart state without mutation.
|
||||
// StateRequest fetches current cart state without mutating.
|
||||
message StateRequest {
|
||||
string cart_id = 1;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// CartState represents the full cart snapshot returned by state/mutation replies.
|
||||
// Replaces the previous raw JSON payload.
|
||||
// -----------------------------------------------------------------------------
|
||||
message CartState {
|
||||
string cart_id = 1;
|
||||
repeated CartItemState items = 2;
|
||||
int64 total_price = 3;
|
||||
int64 total_tax = 4;
|
||||
int64 total_discount = 5;
|
||||
repeated DeliveryState deliveries = 6;
|
||||
bool payment_in_progress = 7;
|
||||
string order_reference = 8;
|
||||
string payment_status = 9;
|
||||
}
|
||||
|
||||
// Lightweight representation of an item in the cart
|
||||
message CartItemState {
|
||||
int64 id = 1;
|
||||
int64 source_item_id = 2;
|
||||
string sku = 3;
|
||||
string name = 4;
|
||||
int64 unit_price = 5;
|
||||
int32 quantity = 6;
|
||||
int64 total_price = 7;
|
||||
int64 total_tax = 8;
|
||||
int64 org_price = 9;
|
||||
int32 tax_rate = 10;
|
||||
int64 total_discount = 11;
|
||||
string brand = 12;
|
||||
string category = 13;
|
||||
string category2 = 14;
|
||||
string category3 = 15;
|
||||
string category4 = 16;
|
||||
string category5 = 17;
|
||||
string image = 18;
|
||||
string article_type = 19;
|
||||
string seller_id = 20;
|
||||
string seller_name = 21;
|
||||
string disclaimer = 22;
|
||||
string outlet = 23;
|
||||
string store_id = 24;
|
||||
int32 stock = 25;
|
||||
}
|
||||
|
||||
// Delivery / shipping entry
|
||||
message DeliveryState {
|
||||
int64 id = 1;
|
||||
string provider = 2;
|
||||
int64 price = 3;
|
||||
repeated int64 item_ids = 4;
|
||||
PickupPoint pickup_point = 5;
|
||||
}
|
||||
|
||||
// StateReply mirrors MutationReply for consistency.
|
||||
message StateReply {
|
||||
int32 status_code = 1;
|
||||
bytes payload = 2; // JSON cart state or error string
|
||||
|
||||
oneof result {
|
||||
CartState state = 2;
|
||||
string error = 3;
|
||||
}
|
||||
}
|
||||
|
||||
// CartActor exposes mutation and state retrieval for remote grains.
|
||||
service CartActor {
|
||||
// Mutate applies a single mutation to a cart, creating the cart lazily if needed.
|
||||
rpc Mutate(MutationRequest) returns (MutationReply);
|
||||
rpc Mutate(MutationEnvelope) returns (MutationReply);
|
||||
|
||||
// GetState retrieves the cart's current state (JSON).
|
||||
rpc GetState(StateRequest) returns (StateReply);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Notes:
|
||||
//
|
||||
// 1. Generation:
|
||||
// protoc --go_out=. --go_opt=paths=source_relative \
|
||||
// --go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||
// cart_actor.proto
|
||||
//
|
||||
// 2. Underlying mutation payloads originate from messages.proto definitions.
|
||||
// The server side will route based on MutationType and decode payload bytes
|
||||
// using existing handler registry logic.
|
||||
//
|
||||
// 3. Future Enhancements:
|
||||
// - Replace JSON state payload with a strongly typed CartState proto.
|
||||
// - Add streaming RPC (e.g. WatchState) for live updates.
|
||||
// - Migrate control plane (negotiate/ownership) into a separate proto
|
||||
// (control_plane.proto) as per the migration plan.
|
||||
// Future Enhancements:
|
||||
// * Replace JSON state payload with a strongly typed CartState proto.
|
||||
// * Add streaming RPC (e.g., WatchState) for live updates.
|
||||
// * Add batch mutations (repeated MutationEnvelope) if performance requires.
|
||||
// * Introduce optimistic concurrency via version fields if external writers appear.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -30,7 +30,7 @@ const (
|
||||
// CartActor exposes mutation and state retrieval for remote grains.
|
||||
type CartActorClient interface {
|
||||
// Mutate applies a single mutation to a cart, creating the cart lazily if needed.
|
||||
Mutate(ctx context.Context, in *MutationRequest, opts ...grpc.CallOption) (*MutationReply, error)
|
||||
Mutate(ctx context.Context, in *MutationEnvelope, opts ...grpc.CallOption) (*MutationReply, error)
|
||||
// GetState retrieves the cart's current state (JSON).
|
||||
GetState(ctx context.Context, in *StateRequest, opts ...grpc.CallOption) (*StateReply, error)
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func NewCartActorClient(cc grpc.ClientConnInterface) CartActorClient {
|
||||
return &cartActorClient{cc}
|
||||
}
|
||||
|
||||
func (c *cartActorClient) Mutate(ctx context.Context, in *MutationRequest, opts ...grpc.CallOption) (*MutationReply, error) {
|
||||
func (c *cartActorClient) Mutate(ctx context.Context, in *MutationEnvelope, opts ...grpc.CallOption) (*MutationReply, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(MutationReply)
|
||||
err := c.cc.Invoke(ctx, CartActor_Mutate_FullMethodName, in, out, cOpts...)
|
||||
@@ -70,7 +70,7 @@ func (c *cartActorClient) GetState(ctx context.Context, in *StateRequest, opts .
|
||||
// CartActor exposes mutation and state retrieval for remote grains.
|
||||
type CartActorServer interface {
|
||||
// Mutate applies a single mutation to a cart, creating the cart lazily if needed.
|
||||
Mutate(context.Context, *MutationRequest) (*MutationReply, error)
|
||||
Mutate(context.Context, *MutationEnvelope) (*MutationReply, error)
|
||||
// GetState retrieves the cart's current state (JSON).
|
||||
GetState(context.Context, *StateRequest) (*StateReply, error)
|
||||
mustEmbedUnimplementedCartActorServer()
|
||||
@@ -83,7 +83,7 @@ type CartActorServer interface {
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedCartActorServer struct{}
|
||||
|
||||
func (UnimplementedCartActorServer) Mutate(context.Context, *MutationRequest) (*MutationReply, error) {
|
||||
func (UnimplementedCartActorServer) Mutate(context.Context, *MutationEnvelope) (*MutationReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Mutate not implemented")
|
||||
}
|
||||
func (UnimplementedCartActorServer) GetState(context.Context, *StateRequest) (*StateReply, error) {
|
||||
@@ -111,7 +111,7 @@ func RegisterCartActorServer(s grpc.ServiceRegistrar, srv CartActorServer) {
|
||||
}
|
||||
|
||||
func _CartActor_Mutate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(MutationRequest)
|
||||
in := new(MutationEnvelope)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func _CartActor_Mutate_Handler(srv interface{}, ctx context.Context, dec func(in
|
||||
FullMethod: CartActor_Mutate_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CartActorServer).Mutate(ctx, req.(*MutationRequest))
|
||||
return srv.(CartActorServer).Mutate(ctx, req.(*MutationEnvelope))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
@@ -427,8 +427,7 @@ const file_control_plane_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"GetCartIds\x12\x0f.messages.Empty\x1a\x16.messages.CartIdsReply\x12F\n" +
|
||||
"\fConfirmOwner\x12\x1c.messages.OwnerChangeRequest\x1a\x18.messages.OwnerChangeAck\x12<\n" +
|
||||
"\aClosing\x12\x17.messages.ClosingNotice\x1a\x18.messages.OwnerChangeAckB\fZ\n" +
|
||||
".;messagesb\x06proto3"
|
||||
"\aClosing\x12\x17.messages.ClosingNotice\x1a\x18.messages.OwnerChangeAckB.Z,git.tornberg.me/go-cart-actor/proto;messagesb\x06proto3"
|
||||
|
||||
var (
|
||||
file_control_plane_proto_rawDescOnce sync.Once
|
||||
|
||||
@@ -2,7 +2,7 @@ syntax = "proto3";
|
||||
|
||||
package messages;
|
||||
|
||||
option go_package = ".;messages";
|
||||
option go_package = "git.tornberg.me/go-cart-actor/proto;messages";
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Control Plane gRPC API
|
||||
|
||||
1066
proto/messages.pb.go
1066
proto/messages.pb.go
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
package messages;
|
||||
option go_package = ".;messages";
|
||||
option go_package = "git.tornberg.me/go-cart-actor/proto;messages";
|
||||
|
||||
message AddRequest {
|
||||
int32 quantity = 1;
|
||||
|
||||
Reference in New Issue
Block a user