more changes
This commit is contained in:
@@ -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.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user