Skip to content

Commit

Permalink
docs: Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Jan 3, 2023
1 parent 71ceaa3 commit beaf389
Show file tree
Hide file tree
Showing 63 changed files with 722 additions and 503 deletions.
49 changes: 13 additions & 36 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ decorators approach to increase the DX and full typings support for easier devel
* [@OnMedusaEntityEvent](#onmedusaentityevent)
* [Utilities :wrench:](#utilities-wrench)
* [attachOrReplaceEntitySubscriber](#attachorreplaceentitysubscriber)
* [repositoryMixin](#repositorymixin)
* [Omit](#omit)
* [repositoryMixin (@deprecated)](#repositorymixin-deprecated)
* [Omit (@deprecated)](#omit-deprecated)
* [Starters](#starters)
* [Internal modules (Optional)](#internal-modules-optional)
* [Monitoring ](#monitoring-)
Expand Down Expand Up @@ -403,12 +403,12 @@ export class Product extends MedusaProduct {
> The `override` parameter of the `@MedusaEntity` decorator allow to specify which entity
> from the core must be overridden.
In the case of an overriding extension, you have to augment medusa types in order for your project and the external lib to
be able to know about the new typings. To do so you can create an `index.d.ts` file in the same directory as your module
In the case of an overriding extension, you have to augment medusa types in order for typescript to be aware of the changes
and not throw you an error. To do so you can create an `index.d.ts` file in the same directory as your module
and add the following content.

```typescript
declare module '@medusajs/medusa/dist/models/product' {
export declare module '@medusajs/medusa/dist/models/product' {
declare interface Product {
customField: string;
}
Expand Down Expand Up @@ -460,35 +460,18 @@ Let see an example

```typescript
import { ProductRepository as MedusaProductRepository } from "@medusajs/medusa/dist/repositories/product";
import { Repository as MedusaRepository, Utils } from "medusa-extender";
import { Repository as MedusaRepository } from "medusa-extender";
import { EntityRepository } from "typeorm";
import { Product } from "./product.entity";

@MedusaRepository({ override: MedusaProductRepository })
@EntityRepository(Product)
export default class UserRepository extends Utils.repositoryMixin<Product, MedusaProductRepository>(MedusaProductRepository) {}
export default class UserRepository extends MedusaProductRepository {}
```

> The `override` parameter of the `@MedusaRepository` decorator allow to specify which custom repository
> from the core must be overridden. You can also access the container to resolve
> a dependency in your routes handler through `req.scope.resolve('key')`.
> The `Utils.repositoryMixin` is a special utility exported by the extender that
> allow multiple class inheritance. This is mandatory to be able to extend an existing
> custom repository.
In the case of an overriding extension, you have to augment medusa types in order for your project and the external lib to
be able to know about the new typings. To do so you can create an `index.d.ts` file in the same directory as your module
and add the following content.

```typescript
declare module '@medusajs/medusa/dist/repositories/product' {
declare class UserRepository extends ExtendedProductRepository {}
}
```

you can learn more about that by looking how it is done in the starters [here](https://github.com/adrien2p/medusa-extender/blob/main/starters/server/src/modules/user/index.d.ts)
or in the troubleshooting section of the documentation.
> a dependency in your route handlers through `req.scope.resolve('key')`.
### @Migration

Expand Down Expand Up @@ -662,10 +645,6 @@ export default class ProductService extends MedusaProductService {
> be re created for each new request in order for you to access the `loggedInUser` as we've seen
> in the previous section.
> :warning: You should have the less possible resources using the `scoped` lifetime
> to avoid lower performance, it must be used in special cases such as being able to access
> specific values that does exists only during the request processing. :warning:
### @Middleware

The middleware decorator allow you to create new middleware on specific routes
Expand Down Expand Up @@ -708,7 +687,7 @@ In this scenario, the middleware is applied after the medusa authentication stra
We need to be after the authentication to be able to be sure that the user is already
authenticated and that we have access to the `userId`.

This middleware is applied to all routes and will retrieve the authenticated user
This middleware is applied to all admin routes and will retrieve the authenticated user
to store it in the underlying container. You will be then be able to get access to it
into your servives as we've seen in the previous sections.

Expand Down Expand Up @@ -927,7 +906,7 @@ export default class ProductSubscriber implements EntitySubscriberInterface<Prod

public async beforeInsert(event: InsertEvent<Product>): Promise<InsertEvent<Product>> {
const eventName = OnMedusaEntityEvent.Before.InsertEvent(Product);
await eventEmitter.emitAsync<InsertEvent<User>>(eventName, {
await eventEmitter.emitAsync<InsertEvent<Product>>(eventName, {
event,
transactionalEntityManager: event.manager,
});
Expand Down Expand Up @@ -1006,13 +985,13 @@ this utility is used mainly by the subscriber in order to help you attach a new
It will take the `connection` as an argument and manage to remove the previous subscriber and attach the new one if needed.
[See how to use it here](#onmedusaentityevent).

### repositoryMixin
### repositoryMixin (@deprecated)

This utility is mandatory when you extend an existing repository.
Since that to be able to work the repository must extend multiple classes in order to reflect the original repository
and the custom extension that you've made. [See how to use it here](#repository).

### Omit
### Omit (@deprecated)

The `Omit` utility allows you to omit a set of properties from a class.
In some cases, extending a class to change the type of a property makes
Expand Down Expand Up @@ -1234,9 +1213,7 @@ In that case, we have to let typescript know that `Foo` has been extended and th
this is what the following code will do with a user extension example:

```ts
import { default as ExtendedUserRepository } from './user.repository';

declare module '@medusajs/medusa/dist/models/user' {
export declare module '@medusajs/medusa/dist/models/user' {
declare interface User {
store_id: string;
}
Expand Down
20 changes: 11 additions & 9 deletions docs/classes/Medusa.Medusa-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[Medusa](../modules/Medusa.md).Medusa

Load medusa and apply all components

## Table of contents

### Constructors
Expand All @@ -29,12 +31,12 @@

| Name | Type | Description |
| :------ | :------ | :------ |
| `rootDir` | `string` | |
| `express` | `Express` | |
| `rootDir` | `string` | Directory where the `medusa-config` is located |
| `express` | `Express` | Express instance |

#### Defined in

[Medusa.ts:38](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/Medusa.ts#L38)
[Medusa.ts:38](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/Medusa.ts#L38)

## Properties

Expand All @@ -44,7 +46,7 @@

#### Defined in

[Medusa.ts:31](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/Medusa.ts#L31)
[Medusa.ts:31](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/Medusa.ts#L31)

___

Expand All @@ -54,24 +56,24 @@ ___

#### Defined in

[Medusa.ts:32](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/Medusa.ts#L32)
[Medusa.ts:32](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/Medusa.ts#L32)

## Methods

### load

**load**(`modules`): `Promise`<[`MedusaContainer`](../modules/core_types.md#medusacontainer)\>
**load**(`modules`): `Promise`<`MedusaContainer`\>

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `modules` | [`Type`](../interfaces/core_types.Type.md)<`unknown`\>[] | |
| `modules` | [`Type`](../interfaces/core_types.Type.md)<`unknown`\>[] | The modules to load into medusa |

#### Returns

`Promise`<[`MedusaContainer`](../modules/core_types.md#medusacontainer)\>
`Promise`<`MedusaContainer`\>

#### Defined in

[Medusa.ts:46](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/Medusa.ts#L46)
[Medusa.ts:46](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/Medusa.ts#L46)
4 changes: 2 additions & 2 deletions docs/classes/core_componentMap.ComponentMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Map&lt;InjectableComponentTypes, GetInjectableOptions\&gt;.constructor

#### Defined in

[core/componentMap.ts:4](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/core/componentMap.ts#L4)
[core/componentMap.ts:4](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/core/componentMap.ts#L4)

## Methods

Expand Down Expand Up @@ -68,4 +68,4 @@ Map.get

#### Defined in

[core/componentMap.ts:16](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/core/componentMap.ts#L16)
[core/componentMap.ts:16](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/core/componentMap.ts#L16)
32 changes: 21 additions & 11 deletions docs/classes/core_event_emmiter.Internals.CustomEventEmitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[core/event-emmiter](../modules/core_event_emmiter.md).[Internals](../modules/core_event_emmiter.Internals.md).CustomEventEmitter

Extended event emitter to register methods that must be call when certain events are triggered and relay the handling to the API package

## Hierarchy

- `EventEmitter`
Expand Down Expand Up @@ -38,7 +40,7 @@ EventEmitter.constructor

#### Defined in

[core/event-emmiter.ts:24](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/core/event-emmiter.ts#L24)
[core/event-emmiter.ts:24](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/core/event-emmiter.ts#L24)

## Properties

Expand All @@ -48,14 +50,16 @@ EventEmitter.constructor

#### Defined in

[core/event-emmiter.ts:22](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/core/event-emmiter.ts#L22)
[core/event-emmiter.ts:22](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/core/event-emmiter.ts#L22)

## Methods

### emitAsync

**emitAsync**<`T`\>(`eventName`, `values`): `Promise`<`T`\>

Emit an asynchrone event entity based and wait for the result.

#### Type parameters

| Name |
Expand All @@ -66,23 +70,25 @@ EventEmitter.constructor

| Name | Type | Description |
| :------ | :------ | :------ |
| `eventName` | `string` \| `symbol` | |
| `values` | `Record`<`string`, `unknown`\> | |
| `eventName` | `string` \| `symbol` | The event that must be triggered |
| `values` | `Record`<`string`, `unknown`\> | The data that are passed to the event handler |

#### Returns

`Promise`<`T`\>

#### Defined in

[core/event-emmiter.ts:94](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/core/event-emmiter.ts#L94)
[core/event-emmiter.ts:94](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/core/event-emmiter.ts#L94)

___

### register

**register**<`T`\>(`eventName`, `propertyName`, `metatype`): `void`

Register a new event handler.

#### Type parameters

| Name |
Expand All @@ -93,34 +99,38 @@ ___

| Name | Type | Description |
| :------ | :------ | :------ |
| `eventName` | `string` \| `symbol` | |
| `propertyName` | `string` | |
| `metatype` | [`Type`](../interfaces/core_types.Type.md)<`T`\> | |
| `eventName` | `string` \| `symbol` | The name of the event that has to be triggered |
| `propertyName` | `string` | The name of the class property that will handle the event |
| `metatype` | [`Type`](../interfaces/core_types.Type.md)<`T`\> | The object that contains the property above |

#### Returns

`void`

#### Defined in

[core/event-emmiter.ts:34](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/core/event-emmiter.ts#L34)
[core/event-emmiter.ts:34](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/core/event-emmiter.ts#L34)

___

### registerListeners

**registerListeners**(`container`): `void`

Apply all event handlers hold by the `listenerDescriptors`.
Only unregister and register again non singleton based event listeners.
No duplicate listener can exist on one handler.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `container` | `AwilixContainer`<`any`\> | |
| `container` | `AwilixContainer`<`any`\> | The IoC container that allow to resolve instance |

#### Returns

`void`

#### Defined in

[core/event-emmiter.ts:47](https://github.com/adrien2p/medusa-extender/blob/12c4270/src/core/event-emmiter.ts#L47)
[core/event-emmiter.ts:47](https://github.com/adrien2p/medusa-extender/blob/71ceaa3/src/core/event-emmiter.ts#L47)
Loading

0 comments on commit beaf389

Please sign in to comment.