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

Feat(modules-sdk): define link #7022

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft

Conversation

carlos-r-l-rodrigues
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues commented Apr 9, 2024

defineLink(
  `${Modules.CART}.cart_id`,
  `${Modules.PAYMENT}.payment_collection_id`
)

defineLink(
  `${Modules.CART}.cart_id`,
  `${Modules.PAYMENT}.payment_collection_id[]` // isList: true
)

defineLink(
  {
     module: Modules.CART,
     key: "cart_id",
     alias: "cart_alias"
  },
  Modules.PAYMENT + ".payment_collection_id"
)

defineLink(
  `${Modules.CART}.cart_id`,
  `${Modules.PAYMENT}.payment_collection_id`,
  {
    database: {
      table: "cart_payment_collection",
      idPrefix: "capaycol",
    },
  }
)

Copy link

changeset-bot bot commented Apr 9, 2024

🦋 Changeset detected

Latest commit: 1bd087e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@medusajs/modules-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 2, 2024 3:44pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) May 2, 2024 3:44pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview May 2, 2024 3:44pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview May 2, 2024 3:44pm

@carlos-r-l-rodrigues
Copy link
Contributor Author

/snapshot-this

Copy link
Contributor

github-actions bot commented Apr 9, 2024

🚀 A snapshot release has been made for this PR

Test the snapshots by updating your package.json with the newly published versions:

yarn add @medusajs/admin@7.1.13-snapshot-20240409114424
yarn add @medusajs/admin-ui@2.1.14-snapshot-20240409114424
yarn add @medusajs/api-key@0.1.2-snapshot-20240409114424
yarn add @medusajs/cache-redis@1.9.1-snapshot-20240409114424
yarn add @medusajs/core-flows@0.0.9-snapshot-20240409114424
yarn add create-medusa-app@1.2.8-snapshot-20240409114424
yarn add @medusajs/currency@0.1.2-snapshot-20240409114424
yarn add @medusajs/customer@0.0.3-snapshot-20240409114424
yarn add @medusajs/event-bus-redis@1.8.13-snapshot-20240409114424
yarn add @medusajs/link-modules@0.2.11-snapshot-20240409114424
yarn add @medusajs/medusa@1.21.0-snapshot-20240409114424
yarn add medusa-react@9.0.17-snapshot-20240409114424
yarn add medusa-test-utils@1.1.44-snapshot-20240409114424
yarn add @medusajs/modules-sdk@1.12.11-snapshot-20240409114424
yarn add @medusajs/orchestration@0.5.7-snapshot-20240409114424
yarn add @medusajs/payment@0.0.3-snapshot-20240409114424
yarn add @medusajs/pricing@0.2.0-snapshot-20240409114424
yarn add @medusajs/product@0.4.0-snapshot-20240409114424
yarn add @medusajs/promotion@0.0.4-snapshot-20240409114424
yarn add @medusajs/stock-location-next@0.0.3-snapshot-20240409114424
yarn add @medusajs/types@1.12.0-snapshot-20240409114424
yarn add @medusajs/utils@1.12.0-snapshot-20240409114424
yarn add @medusajs/workflow-engine-inmemory@0.0.4-snapshot-20240409114424
yarn add @medusajs/workflow-engine-redis@0.0.4-snapshot-20240409114424
yarn add @medusajs/workflows-sdk@0.1.6-snapshot-20240409114424

Latest commit: 3882cac

@olivermrbl
Copy link
Contributor

olivermrbl commented May 7, 2024

Would it make sense to simplify the API of defineLink to only support one way? My idea is to try to reduce the amount of decisions developers need to make in the context of link definitions. We make it easy for them and they don't have to worry about what is most appropriate.

What I have in mind was something like this:

// /src/links/index.ts

const someLink = {
  modules: [
    {
      name: Modules.CART,
      key: "cart_id",
    },
    {
      name: Modules.PAYMENT,
      key: "payment_collection_id",
      isList: true,
    },
  ],
  options: { idPrefix: "capaycol" }
}

const someOtherLink = {
  modules: [
    {
      name: Modules.CART,
      key: "cart_id",
    },
    {
      name: Modules.SALES_CHANNEL,
      key: "sales_channel_id",
    },
  ],
}

defineLink([ someLink, someOtherLink ])

Curious to hear what you think about this

cc @srindom

@carlos-r-l-rodrigues
Copy link
Contributor Author

I like this approach too because at the end we have multiple extra properties that we'll need.
So having a proper object with all the available options, like the fieldAlias, is good.

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.

None yet

2 participants