Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] develop from medusajs:develop #8

Merged
merged 7 commits into from
Dec 19, 2024
Merged

Conversation

pull[bot]
Copy link

@pull pull bot commented Dec 19, 2024

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Refactor models to use DML.

New Features:

  • Allow defining foreign key name for belongsTo and hasOne relations.

Tests:

  • Updated tests to reflect changes.

riqwan and others added 7 commits December 19, 2024 16:31
…10673)

* fix(core-flows): refresh payment collections upon shipping changes

* chore: fix spec
* docs: support generating sidebar items with tags

* small fix

* fix dependencies

* test

* test fix

* test fix

* test fix

* test fix

* another fix

* revert change

* fix for resources
**What**
- Allow to provide `foreignKeyName` option for hasOne and belongsTo relationships
  - `model.hasOne(() => OtherEntity, { foreignKey: true, foreignKeyName: 'other_entity_something_id' })`
  - The above will also output a generated type that takes into consideration the custom fk name 🔽 
- Update types to account for defined custom foreign key name
- Fix joiner config linkable generation to account for custom linkable keys that provide a public API for their model but are not part of the list of the models included in the MedusaService
  - This was supposed to be handled correctly but the implementation was not considering that custom linkable keys could reference models not part of the one provided to medusa service
- Migrate fulfillment module to DML
- Fix has one with fk behaviour and hooks (the relation should be assigned but not the fk)
- Fix has one belongsTo hooks (the relation should be assigned but not the fk)
- Fix hasOneWithFk and belongsTo non persisted fk to be selectable
- Allow to define `belongsTo` without other side definition for `ManyToOne` with no counter part defined
  - Meaning that if a user defined `belongsTo` on one side andnot mapped by and no counter part on the other entity it will be considered as a `ManyToOne`
- `orphanRemoval` on `OneToOne` have been removed, this means that when assigning a new object relation to an entity, the previous one gets deconected but not deleted automatically. This prevent removing data un volountarely

**NOTE**
As per our convention here are some information to keep in mind

**HasOne <> BelongsTo**
Define `OneToOne`, The foreign key is owned by the belongs to and the relation needs to be provided to cascade if wanted

**HasMany <> BelongsTo**
Define `OneToMane` <> `ManyToOne`, the foreign key is owned by the many to one and for those relation no cascade will be performed, the foreign key must be provided. For the `HasMany` the cascade is available

**HasOne (with FK)**
Will act similarly to belongs to with **HasOne <> BelongsTo**

Co-authored-by: Carlos R. L. Rodrigues <[email protected]>
@pull pull bot added the ⤵️ pull label Dec 19, 2024
@pull pull bot merged commit 8650e61 into Stars1233:develop Dec 19, 2024
Copy link

sourcery-ai bot commented Dec 19, 2024

Reviewer's Guide by Sourcery

This pull request refactors the Fulfillment module to use the DML (Data Modeling Language) for defining entities and relationships. It also introduces a number of improvements to the existing functionality, including support for custom foreign keys in relationships, improved handling of foreign key assignments, and a more robust implementation of cascading deletes. Additionally, it includes updates to the cart workflows to refresh payment collections when shipping methods are changed, and fixes an issue with updating collections with products.

Sequence diagram for adding shipping method to cart

sequenceDiagram
    participant Client
    participant Cart
    participant ShippingOption
    participant PaymentCollection

    Client->>Cart: addShippingMethod
    Cart->>ShippingOption: validateShippingOption
    Cart->>Cart: removeExistingShippingMethod
    Cart->>Cart: addNewShippingMethod
    Cart->>Cart: refreshCartItems
    Note over Cart: Updated to use refreshCartItems workflow
    Cart->>PaymentCollection: refresh
    Note over PaymentCollection: Payment collection refreshed after shipping change
Loading

Entity relationship diagram for the Fulfillment module

erDiagram
    FULFILLMENT ||--o{ FULFILLMENT_ITEM : contains
    FULFILLMENT ||--o| FULFILLMENT_ADDRESS : has
    FULFILLMENT ||--o{ FULFILLMENT_LABEL : has
    FULFILLMENT }|--|| FULFILLMENT_PROVIDER : provided_by
    FULFILLMENT }o--|| SHIPPING_OPTION : uses

    SERVICE_ZONE ||--o{ GEO_ZONE : contains
    SERVICE_ZONE }|--|| FULFILLMENT_SET : belongs_to
    SERVICE_ZONE ||--o{ SHIPPING_OPTION : offers

    SHIPPING_OPTION ||--o{ SHIPPING_OPTION_RULE : has
    SHIPPING_OPTION ||--|| SHIPPING_OPTION_TYPE : has
    SHIPPING_OPTION }o--|| SHIPPING_PROFILE : belongs_to
Loading

Class diagram showing the updated Fulfillment module entities

classDiagram
    class Fulfillment {
      +id: string
      +location_id: string
      +packed_at: Date
      +shipped_at: Date
      +delivered_at: Date
      +canceled_at: Date
      +data: Record
      +requires_shipping: boolean
    }
    class FulfillmentItem {
      +id: string
      +title: string
      +sku: string
      +barcode: string
      +quantity: BigNumber
      +line_item_id: string
      +inventory_item_id: string
    }
    class ServiceZone {
      +id: string
      +name: string
      +metadata: Record
    }
    class GeoZone {
      +id: string
      +type: GeoZoneType
      +country_code: string
      +province_code: string
      +city: string
      +postal_expression: Record
    }
    class ShippingOption {
      +id: string
      +name: string
      +price_type: ShippingOptionPriceType
      +data: Record
      +metadata: Record
    }

    Fulfillment "1" -- "*" FulfillmentItem
    ServiceZone "1" -- "*" GeoZone
    ServiceZone "1" -- "*" ShippingOption
Loading

File-Level Changes

Change Details Files
Refactored entities to use DML.
  • Replaced MikroORM decorators with DML functions.
  • Removed entity class definitions and replaced them with DML model definitions.
  • Removed explicit index and cascade definitions and replaced them with DML index and cascade definitions.
packages/modules/fulfillment/src/models/address.ts
packages/modules/fulfillment/src/models/fulfillment-item.ts
packages/modules/fulfillment/src/models/fulfillment-label.ts
packages/modules/fulfillment/src/models/fulfillment-provider.ts
packages/modules/fulfillment/src/models/fulfillment.ts
packages/modules/fulfillment/src/models/fulfillment-set.ts
packages/modules/fulfillment/src/models/geo-zone.ts
packages/modules/fulfillment/src/models/index.ts
packages/modules/fulfillment/src/models/service-zone.ts
packages/modules/fulfillment/src/models/shipping-option-rule.ts
packages/modules/fulfillment/src/models/shipping-option-type.ts
packages/modules/fulfillment/src/models/shipping-option.ts
packages/modules/fulfillment/src/models/shipping-profile.ts
Added support for custom foreign keys in relationships.
  • Added foreignKeyName option to BelongsTo and HasOneWithForeignKey relationships.
  • Used foreignKeyName option to define custom foreign key names.
packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts
Improved handling of foreign key assignments.
  • Added hooks to automatically assign foreign key values based on relationships.
  • Added hooks to automatically assign relationship values based on foreign keys.
packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts
Improved implementation of cascading deletes.
  • Used orphanRemoval option to ensure that related entities are deleted when the parent entity is deleted.
packages/core/utils/src/dml/helpers/entity-builder/define-relationship.ts
Updated cart workflows to refresh payment collections when shipping methods are changed.
  • Added refreshCartItemsWorkflow step to addShippingMethodToCartWorkflow.
packages/core/core-flows/src/cart/workflows/add-shipping-method-to-cart.ts
Fixed issue with updating collections with products.
  • Fixed an issue where products were not being added to collections when updating a collection.
packages/modules/product/src/services/product-module-service.ts
Added support for autogenerating sidebar items from tags.
  • Added autogenerate_tags option to sidebar items.
  • Added getAutogeneratedTagSidebarItems function to generate sidebar items from tags.
www/packages/build-scripts/src/generate-sidebar.ts
www/packages/types/src/sidebar.ts
Added tags to MDX files.
  • Added tags frontmatter to MDX files.
www/apps/resources/app/commerce-modules/product/guides/price-with-taxes/page.mdx
www/apps/resources/app/commerce-modules/product/guides/price/page.mdx
www/apps/resources/app/storefront-development/cart/context/page.mdx
www/apps/resources/app/storefront-development/cart/create/page.mdx
www/apps/resources/app/storefront-development/cart/manage-items/page.mdx
www/apps/resources/app/storefront-development/cart/retrieve/page.mdx
www/apps/resources/app/storefront-development/cart/update/page.mdx
www/apps/resources/app/storefront-development/checkout/address/page.mdx
www/apps/resources/app/storefront-development/checkout/complete-cart/page.mdx
www/apps/resources/app/storefront-development/checkout/email/page.mdx
www/apps/resources/app/storefront-development/checkout/payment/page.mdx
www/apps/resources/app/storefront-development/checkout/payment/stripe/page.mdx
www/apps/resources/app/storefront-development/checkout/shipping/page.mdx
www/apps/resources/app/storefront-development/customers/addresses/page.mdx
www/apps/resources/app/storefront-development/customers/context/page.mdx
www/apps/resources/app/storefront-development/customers/log-out/page.mdx
www/apps/resources/app/storefront-development/customers/login/page.mdx
www/apps/resources/app/storefront-development/customers/profile/page.mdx
www/apps/resources/app/storefront-development/customers/register/page.mdx
www/apps/resources/app/storefront-development/customers/reset-password/page.mdx
www/apps/resources/app/storefront-development/customers/retrieve/page.mdx
www/apps/resources/app/storefront-development/customers/third-party-login/page.mdx
www/apps/resources/app/storefront-development/products/categories/list/page.mdx
www/apps/resources/app/storefront-development/products/categories/nested-categories/page.mdx
www/apps/resources/app/storefront-development/products/categories/products/page.mdx
www/apps/resources/app/storefront-development/products/categories/retrieve/page.mdx
www/apps/resources/app/storefront-development/products/collections/list/page.mdx
www/apps/resources/app/storefront-development/products/collections/products/page.mdx
www/apps/resources/app/storefront-development/products/collections/retrieve/page.mdx
www/apps/resources/app/storefront-development/products/inventory/page.mdx
www/apps/resources/app/storefront-development/products/list/page.mdx
www/apps/resources/app/storefront-development/products/price/examples/sale-price/page.mdx
www/apps/resources/app/storefront-development/products/price/examples/show-price/page.mdx
www/apps/resources/app/storefront-development/products/price/examples/tax-price/page.mdx
www/apps/resources/app/storefront-development/products/price/page.mdx
www/apps/resources/app/storefront-development/products/retrieve/page.mdx
www/apps/resources/app/storefront-development/products/variants/page.mdx
www/apps/resources/app/storefront-development/publishable-api-keys/page.mdx
www/apps/resources/app/storefront-development/regions/context/page.mdx
www/apps/resources/app/storefront-development/regions/list/page.mdx
www/apps/resources/app/storefront-development/regions/store-retrieve-region/page.mdx
www/apps/resources/app/storefront-development/tips/page.mdx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

coderabbitai bot commented Dec 19, 2024

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants