TML-2185 port retail store v2 e commerce app to prisma next mongodb#327
Draft
wmadden wants to merge 29 commits intotml-2231-m2-full-index-vocabulary-validators-collection-optionsfrom
Conversation
Add _prisma_migrations collection support for MongoDB: - readMarker, initMarker, updateMarker (CAS), writeLedgerEntry - MongoControlDriverInstance extending ControlDriverInstance with db access - Wire readMarker() on MongoControlFamilyInstance - Integration tests using mongodb-memory-server
Reset branch to tml-2220-m1-family-migration-spi-vertical-slice which provides the full Mongo framework stack (embedded value objects, ORM CRUD, pipeline builder, migrations). Carry forward the project spec and retail-store plan (revised for the new capabilities) and predictive-maintenance plan.
Add workspace package with Next.js, PN Mongo deps, and config files mirroring mongo-demo. No contract or source files yet.
Define 8 value object types (Price, Image, Address, CartItem, OrderLineItem, StatusEntry, InvoiceLineItem, EventMetadata) and 7 models (Product, User, Cart, Order, Location, Invoice, Event) with nested value objects and reference relations. Extend scalar type descriptors with Float -> mongo/double@1 since the default Mongo PSL interpreter does not include Float.
db.ts exposes orm, runtime, pipeline, raw, and contract. seed.ts populates all 7 collections with realistic e-commerce data. scripts/seed.ts provides a standalone entry point with .env support.
Implement typed data access functions for all 7 collections: products, users, carts, orders, locations, invoices, events. Add objectIdEq helper to handle BSON ObjectId filtering via MongoParamRef, since MongoFieldFilter.eq resolveValue corrupts raw ObjectId instances by treating them as plain objects. Integration tests cover: CRUD lifecycle, embedded value objects (Price, Image, Address, CartItem, OrderLineItem, StatusEntry, InvoiceLineItem, EventMetadata), upsert, clear cart, relation loading via $lookup (cart->user, order->user, invoice->order), and seed data population across all 7 collections.
Implement addToCart ($push), removeFromCart ($pull), and updateOrderStatus ($push to statusHistory) using raw MongoDB commands through mongoRaw. These bypass the ORM to use native array operators not yet supported in the typed ORM surface. Tests verify push/pull on cart items and status history append.
aggregateEventsByType uses $match -> $group -> $sort to count event types per user. getRandomProducts uses $sample to return a random subset from the products collection. Tests verify group counts and sample cardinality.
RESTful API routes backed by the data access layer: - GET/POST/DELETE /api/cart (add/remove items, clear) - GET /api/products, GET /api/products/[id], GET /api/products/random - GET/POST /api/orders, GET/DELETE/PATCH /api/orders/[id] - GET /api/locations db-singleton provides lazy-initialized shared db client.
Server-rendered pages using the data access layer directly: - Product catalog grid (/) with brand, category, and pricing - Product detail (/products/[id]) with full metadata - Cart view (/cart) with line items and total - Order history (/orders) with status badges - Order detail (/orders/[id]) with items and status timeline Uses inline styles for simplicity (no Tailwind dependency).
Add findSimilarProducts via $vectorSearch (requires Atlas). Fix instanceof checks on string params for typecheck. Document demonstrated features and known framework gaps in README.
Document .env configuration, seed workflow, DEMO_USER_ID requirement for cart/orders pages, and optional Atlas vector search setup.
seed() now returns the demo user ID. The seed script writes it into .env automatically, removing the manual mongosh step from the setup workflow.
- F01: fix objectIdEq param type from string|unknown to string|ObjectId - F02: replace as-string casts in seed.ts with String() calls - F03: guard cart/orders API routes against empty DEMO_USER_ID - F04: document why raw commands skip MongoParamRef wrapping - F06: document why findSimilarProducts uses raw aggregate - F07: document migration gap in README - F08: explain standalone biome config in biome.jsonc - F09: type pipeline return values (Product[], EventTypeCount[]) - F10: extract executeRaw/collectResults helpers
Install tailwindcss, @tailwindcss/postcss, class-variance-authority, clsx, tailwind-merge, lucide-react, and Radix UI primitives. Create postcss.config.mjs, Tailwind v4 globals.css with @theme, cn() utility, and 8 UI components (Button, Card, Input, Badge, Select, RadioGroup, Separator, DropdownMenu).
Next.js middleware redirects unauthenticated visitors to /login. Sign Up creates a user doc via ORM and sets a userId cookie. getAuthUser() server helper reads the cookie and fetches the user.
…write Products now span Apparel/Accessories/Footwear in Heritage, UrbanEdge, Craftsman, TrailMark brands. Added 4 store locations. Seed script no longer writes DEMO_USER_ID to .env since auth uses cookies.
Replace inline styles with Tailwind + shadcn Card components. Add findProductsPaginated (ORM skip/take) and searchProducts ($regex via MongoOrExpr) to data layer. Add Navbar server+client components with auth display. Include integration tests for search and pagination.
API routes read userId from auth cookie instead of env var. Cart and order pages redirect unauthenticated users. Add CartActions client component for remove/clear, OrderStatusButtons for status progression.
…r badge CartProvider wraps the app with cart count state, fetched from GET /api/cart/count. AddToCartButton on product pages posts to the cart API and triggers context refresh. Cart badge in navbar shows item count. CartActions invalidate context after mutations.
Server component loads cart, user address, and store locations. CheckoutForm client component lets user choose between home delivery (with address input) and Buy Online Pick Up In Store (location select). Places order via POST /api/orders, clears cart, redirects to order.
Document the full user flow (signup → browse → cart → checkout → orders), expanded feature table, updated project structure listing. Include middleware.ts in tsconfig include paths.
The useState initializer must be pure — side effects like fetch are not allowed there. Use useEffect for initial count fetch and inline the fetch in invalidateCart to avoid the exhaustive-deps lint.
addToCart uses raw updateOne/$push which silently matches zero docs when no cart exists yet. Now check for an existing cart first and fall back to upsertCart to create the document with the first item.
The adapter resolveValue and resolveDocument now apply codec.encode() when a MongoParamRef carries a codecId. createMongoAdapter() registers all standard codecs (ObjectId, String, Int32, etc.) by default so existing call sites gain encoding without changes.
#toDocument and #toSetFields now look up each field type in the contract and set codecId on the MongoParamRef. This enables the adapter to encode values correctly (e.g. string -> ObjectId for ObjectId-typed fields). Value object sub-fields are processed recursively.
Cover the exact scenario that was broken (addToCart on non-existent cart) and the full happy paths for cart (add, append, remove, clear) and order (create from cart, status progression, user relation, deletion).
addToCart now uses findOneAndUpdate with upsert:true so adding to a non-existent cart atomically creates it instead of silently doing nothing. updateOrderStatus now returns the document (or null), letting callers detect missing orders. The cart POST handler drops the check-then-branch workaround in favor of the single atomic operation.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
@prisma-next/vite-plugin-contract-emit
@prisma-next/runtime-executor
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-pipeline-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
c6c3885 to
b13db34
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.