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

docs: migrate guides to TSDoc references #6100

Merged
merged 14 commits into from
Jan 22, 2024
Merged

Conversation

shahednasser
Copy link
Member

@shahednasser shahednasser commented Jan 16, 2024

Edit: Turning this into a PR holding all left migration of guides to references.

Important

This PR includes changes to some plugins and abstract classes constructors. Check the changesets for more details.


This PR includes changes from the PRs #6121 , #6116 , #6115 + the following changes:

Tax Provider

  • Move documentation closer to code for tax-provider guide.
  • Add typedoc configuration to generate the reference
  • Generate the references

Notification Provider

  • Move documentation closer to code for notification-provider guide.
  • Add typedoc configuration to generate the reference
  • Fix issue in some return types not having description
  • Changed typedoc sort order to be source-file based.
  • Generate the references

File Service

  • Move documentation closer to code for file-service guide.
  • Add typedoc configuration to generate the reference.
  • Fix issue in return field duplicating the same field.
  • Generate the references.

Search Service

  • Move documentation closer to code for search-service guide.
  • Add typedoc configuration to generate the reference.
  • Generate the references.

Medusa Configurations

  • Move documentation closer to code
  • Add typedoc configuration to generate the reference
  • Added support in the typedoc theme to expand properties within the pag
  • Generate the references

@shahednasser shahednasser requested review from a team as code owners January 16, 2024 16:11
Copy link

changeset-bot bot commented Jan 16, 2024

🦋 Changeset detected

Latest commit: 5dc2813

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

This PR includes changesets to release 4 packages
Name Type
@medusajs/file-local Patch
medusa-file-minio Patch
medusa-file-s3 Patch
@medusajs/medusa 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 Jan 16, 2024

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

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 19, 2024 4:30pm
docs-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 19, 2024 4:30pm
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 19, 2024 4:30pm
medusa-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 19, 2024 4:30pm

Comment on lines 12 to 13
constructor() {
super({})
constructor(_) {
super(_)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrien2p can you confirm if it's ok to make this change? I needed to add the constructor to the AbstractTaxService for documentation purposes but the original constructor implementation caused a TypeScript error related to {} not matching type MedusaContainer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I usually do is the following

class SystemTaxService extends AbstractTaxService {
  static identifier = "system"

  constructor(...args: any[]) {
    super(...arguments)
  }

Why? Because here what we are saying is that the SystemTaxService has a defined public constructor that can take any arguments and we pass all the given arguments to super (the base class). Now, maybe we would like to define specifically what arguments this class can take if someone wanted to extend it or just to specify what it is expected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be this right?

constructor(...args: any[]) {
    super(args)
  }

args instead of arguments.

I still get an error for incompatible types. For reference, this is how I've written the constructor:

protected constructor(
protected readonly container: MedusaContainer,
protected readonly config?: Record<string, unknown> // eslint-disable-next-line @typescript-eslint/no-empty-function
) {
super(container, config)
}

I based this implementation of both the constructor in the abstract class and in the system tax service on the implementation for the system payment provider.

Copy link
Member

@adrien2p adrien2p Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to spread the args. arguments is a special js keywords that hold all the arguments passed to a function. args here are the same as arguments. The difference is that if you always want to pass all the args provided by to the constructor arguments will always works.

In your changes above you are passing an array to the parent constructor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but I get this TS error when I use your codeblock:

A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556)

Copy link
Member

@adrien2p adrien2p Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add ts-ignore. If you look in the code base we are already doing that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I've added that. Thanks! 🙏

@shahednasser
Copy link
Member Author

@adrien2p can I get your approval on this one?

@olivermrbl
Copy link
Contributor

Holy smokes, this diff is something. But let's get it in 😄

@shahednasser
Copy link
Member Author

@olivermrbl most of the big file changes are in the generated references in the docs, which you don't need to review. You can just review files under the packages directory 😇

@olivermrbl olivermrbl merged commit 4792c55 into develop Jan 22, 2024
23 checks passed
@olivermrbl olivermrbl deleted the docs/tax-provider branch January 22, 2024 17:38
Comment on lines +231 to +262
* @example
* // ...
* import {
* AbstractPriceSelectionStrategy,
* CustomerService,
* } from "@medusajs/medusa"
* type InjectedDependencies = {
* customerService: CustomerService
* }
*
* class MyStrategy extends
* AbstractPriceSelectionStrategy {
*
* protected customerService_: CustomerService
*
* constructor(container: InjectedDependencies) {
* super(container)
* this.customerService_ = container.customerService
* }
*
* // ...
* }
*
* export default MyStrategy
*/
protected constructor(
protected readonly container: MedusaContainer,
protected readonly config?: Record<string, unknown> // eslint-disable-next-line @typescript-eslint/no-empty-function
) {
super(container, config)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the introduction of the constructor (before this PR it was auto extended from TransactionBaseService which had container: any) broke the example written here above (and the one from the documentation). I don't know now how to inject dependencies as passing InjectedDependencies Object is not allowed by the type MedusaContainer now anymore.

Related issue: https://discord.com/channels/876835651130097704/1201534153896763472/1201534153896763472

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out @tobiaskraus , I'll open another PR to fix it. In the meantime, you can instead use super(arguments[0]) instead of super(container)

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