medusa icon indicating copy to clipboard operation
medusa copied to clipboard

Feat(modules-sdk): define link

Open carlos-r-l-rodrigues opened this issue 10 months ago • 6 comments

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",
    },
  }
)

carlos-r-l-rodrigues avatar Apr 09 '24 06:04 carlos-r-l-rodrigues

🦋 Changeset detected

Latest commit: 1bd087e12bf988c2dae4aec104b92cbd5252aad3

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

changeset-bot[bot] avatar Apr 09 '24 06:04 changeset-bot[bot]

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

vercel[bot] avatar Apr 09 '24 06:04 vercel[bot]

/snapshot-this

carlos-r-l-rodrigues avatar Apr 09 '24 11:04 carlos-r-l-rodrigues

:rocket: 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/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add [email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add [email protected]
yarn add [email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]
yarn add @medusajs/[email protected]

Latest commit: 3882cac622c7d14421fb56dfb88c3929ac73092c

github-actions[bot] avatar Apr 09 '24 11:04 github-actions[bot]

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

olivermrbl avatar May 07 '24 15:05 olivermrbl

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.

carlos-r-l-rodrigues avatar May 07 '24 16:05 carlos-r-l-rodrigues

@carlos-r-l-rodrigues, should we reopen this and get it merged?

I think regardless of where we will load links created by external devs, we will need the utility to perform it.

olivermrbl avatar Jun 17 '24 09:06 olivermrbl

I haven't applied this last format proposed. I will fix conflicts and open another PR..

carlos-r-l-rodrigues avatar Jun 17 '24 10:06 carlos-r-l-rodrigues